1

Can I stop my client from adding terms to a certain taxonomy? So that I set up a fixed amount of terms, and that´s what they get to choose from.

Can I remove the menu item for certain taxonomies in the backend? Let´s say I have created two taxonomies, and I want the user to be able to access one of them and the other should be hidden and only show up as options in the editing of posts/pages.

1 Answer 1

5

When you registered the taxonomy with register_taxonomy there is a capabilities argument. This takes, an array of the capabilities for this taxonomy. In particular:

  • 'manage_terms'
  • 'edit_terms'
  • 'delete_terms'
  • 'assign_terms'

Associated with each of them should be a capability that it is required to be able to perform that action. For instance to assign_terms usually requires the user to have the capabiliy of edit_posts. You can give the first three some capability (custom or otherwise, manage_options might do) that your clients do not have, but you do. The last can be just edit_posts.

As an example:

 register_taxonomy('mytax',array('post'), array(
   'hierarchical' => false,
   //Other properties...
   'capabilities'=>array(
        'manage_terms' => 'manage_options',//or some other capability your clients don't have
        'edit_terms' => 'manage_options',
        'delete_terms' => 'manage_options',
        'assign_terms' =>'edit_posts'),
   //Other properties...
    ));
6
  • I've been struggling with getting my custom roles to accept my taxonomy capabilities. I've scoured the web these past couple days and your explanation was the first that really made sense. Thanks for explaining it so clearly! It feels good to finally fix those pesky bugs :) +1 to you, sir Commented Dec 5, 2012 at 23:31
  • I may need verification, but being able to 'assign_terms' means that you can create terms. It's too bad you can't limit the assign_terms cap to already existing terms (?)
    – AlxVallejo
    Commented Jul 24, 2013 at 18:33
  • @AlxVallejo That's correct. But there's a plug-in which lets you do that: wordpress.org/plugins/manage-tags-capability (I've never used it though) Commented Jul 24, 2013 at 21:31
  • Sadly that plugin is "closed": This plugin has been closed as of March 10, 2020 and is not available for download. Reason: Guideline Violation.
    – jerclarke
    Commented Aug 28, 2020 at 21:35
  • Also note that the example code from Stephen Harris won't work due to a bug in WordPress core, where the capabilities argument (which should be the answer) is ignored for hierarchical=>false taxonomies. I've written it up in detail on the core bug tracker: core.trac.wordpress.org/ticket/51181#ticket
    – jerclarke
    Commented Aug 28, 2020 at 21:36

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.