1

I use the admin menu editor plugin. I have not allowed editors and authors to access the tags section

But they can add a new tag in the post edit section This is not good for our site

We want them to only use tags that have already been created

Is there a way to disable adding new tags on the edit and add post, by editors and authors?

enter image description here

1 Answer 1

1

A CSS rule would be the simple action.

You can just create a single global admin area foot script set of instructions and disable a whole series of elements by user capability and simply add instructions as needed, and affect all areas of the admin area.

functions.php or create a plugin that would give flexibility to be used on any WP site without dependence on specific theme.

add_action('admin_print_footer_scripts', function() {
  ## block fields from non admins

// set default empty vars
  $non_admin_css_blocks= $non_admin_js_blocks='';

// user condition check
  if( !current_user_can('manage_options') ) {
    $non_admin_blocks = '
    #post_tag .jaxtag, 
    .other-field, 
    .another-field {display: none !important;}
    ';

    // javascript instructions
    $non_admin_js_blocks = '
      $("#post-body #title,#edit-slug-box button.edit-slug").attr("disabled","disabled");
    ';
  }

  $css = '
  <style>
  '.$non_admin_blocks.'
  </style>
  ';
  $js = '
  <script>
  jQuery(function($) {
    '.$non_admin_js_blocks.'
  });
  </script>
  ';

  echo $css . $js;
});

Note

You can always scan the files in wp-admin to find all the hooks that will deliver any alteration desired. Just search for do_action or apply_filters and read the commented tip to determine firing time and behavior. If a hook has a variable, that will be used in the callback argument. If there are multiple vars you will need to define the count. EG

priority 10,args count 2

add_action('do_something_different', function($alt,$target) {

}10,2);
2
  • I want this box to still be displayed and authors to be able to use previous tags with search But they cannot create a new label And use other tags Our labels are currently around 6000 pieces
    – Ali Kiani
    Commented Sep 27, 2023 at 13:13
  • that's what the javascript line does. Do not use the CSS rule, just add the tag class to the comma separated array of the jQuery line. In fact just create an array of input field classes or ID which you just want to disable. var field_disable = [ "#post-body #title", "#edit-slug-box button.edit-slug", "input#new-tag-post_tag", "input.tagadd" ]; $.each(field_disable, function(i,v) { $(v).attr("disabled","disabled"); });
    – Nadal
    Commented Sep 27, 2023 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.