admin管理员组

文章数量:1133915

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?

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?

Share Improve this question edited Sep 23, 2023 at 14:36 Ali Kiani asked Sep 22, 2023 at 19:06 Ali KianiAli Kiani 335 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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);

本文标签: user rolesdisable adding new tags on the edit and add post