Custom taxonomies capabilities

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.

2 s
2

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).

Leave a Comment