3

I have registered several custom taxonomies for a custom post type. Code for one of them is the following:

$labels = array(
    'name'              => __( 'Genre', 'textdomain' ),
    'singular_name'     => __( 'Genre', 'textdomain' ),
    'search_items'      => __( 'Search Genres', 'textdomain' ),
    'all_items'         => __( 'All Genres', 'textdomain' ),
    'parent_item'       => __( 'Parent Genre', 'textdomain' ),
    'parent_item_colon' => __( 'Perent Genre:', 'textdomain' ),
    'edit_item'         => __( 'Edit Genre', 'textdomain' ), 
    'update_item'       => __( 'Update Genre', 'textdomain' ),
    'add_new_item'      => __( 'Add New Genre', 'textdomain' ),
    'new_item_name'     => __( 'New Genre', 'textdomain' ),
    'menu_name'         => __( 'Genres', 'textdomain' ),
);
$args = array(
    'labels'            => $labels,
    'public'            => true,
    'show_admin_column' => true,
    'show_ui'           => true,
    'hierarchical'      => true,
    'capabilities'      => array(
        'manage_terms'  => 'edit_posts',
        'edit_terms'    => 'edit_posts',
        'delete_terms'  => 'edit_posts',
        'assign_terms'  => 'edit_posts'
    )
);
register_taxonomy( 'genres', 'book', $args );

I'm having issues with capabilities, as far as I want that one of the custom tax could be managed by authors.

If I define capabilities as the code above like 'manage_terms' => 'edit_posts', authors are not allowed to add new terms to the custom taxonomy even when authors have edit_posts capabilities.

I have also tried to add custom capabilities to author role and assign this capabilities when registering the custom taxonomy, but no success.

What does work is add 'manage_categories' to authors role, but this solution is not satisfactory as far as all the taxonomies are then editable by authors.

Thanks in advance.

1

Just like CPT capabilities those of taxonomy are also customizable, in register_taxonomy():

capabilities

  • 'manage_terms' - 'manage_categories'
  • 'edit_terms' - 'manage_categories'
  • 'delete_terms' - 'manage_categories'
  • 'assign_terms' - 'edit_posts'

Since your authors only have edit_posts it works as you observe — they can assign existing terms, but not create them. You can customize capabilities for taxonomy in question and give respective capability to authors, so that they can create terms in it (but not in other taxonomies).

  • @vguerrero no, you need to adjust capabilities for taxonomies. Taxonomy and CPT are distinctly different things with their own sets of capabilities, you cannot manipulate both by CPT definition alone. – Rarst Jul 24 '14 at 9:50
  • If I am getting it right, you are suggesting to define capabilites for the custom post type as 'capabilites' => array( 'manage_terms' => 'manage_custom_tax', 'edit_terms' => 'manage_custom_tax', 'delete_terms' => 'manage_custom_tax', 'assign_terms' => 'edit_posts')and then adding 'manage_custom_tax' to author role. I did try this prior opening this post, and I have tried this solution again, with no success. I guess I'm not understanding you. I would appreciate more detail or an example. Thanks. – vguerrero Jul 24 '14 at 9:53
  • Sorry, I wrote custom post type but I meant custom taxonomy. – vguerrero Jul 24 '14 at 10:01
  • @vguerrero yes, that what I was suggesting and I am not sure why wouldn't it work in your case. You could try to elaborate on what have you tried in your question. – Rarst Jul 24 '14 at 10:08
  • Ok. This is somehow embarrassing. I'm so sorry about this. It was all because a misspell in the word capabilites, and I couldn't see it even I had been two days struggling with this. I think I could delete this post because it has no interest at all. Sorry for the inconvenience. – vguerrero Jul 24 '14 at 15:49
2

When you are defining capabilities while registering a taxonomy you are defining new capabilities that are equal to the existing capabilities of manage_terms edit_terms delete_terms and assign_terms.

So you should do something like this since your taxonomy is Genre:

'capabilities' => array(
    'manage_terms' => 'manage_genre',
    'edit_terms' => 'edit_genre',
    'delete_terms' => 'delete_genre',
    'assign_terms' => 'assign_genre',
)

After this is done, you will be able to map these capabilities to a user role. The easiest way to do this and my preferred method is to use a plugin such as Capability Manager Enhanced, although there are many plugins that will do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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