How to assign multiple roles for capabilities array withini register_taxonomy function?

I am not sure how to add multiple capabilities to ‘assign_terms’ capability.

My code is below, notice the capabilities array within the register_taxonomy function

/* Registers taxonomies. */

function cflnk_wod_score_register_taxonomies() {
/* Set up the artist taxonomy arguments. */
$wod_name_args = array(
    'hierarchical' => false,
    'query_var' => 'wod_name', 
    'show_tagcloud' => true,
        'rewrite' => array(
            'slug' => 'wod/name',
            'with_front' => false 
            ),
    here --->>> 'capabilities' => array (
            'manage_terms' => 'administrator',
            'edit_terms' => 'administrator',
            'delete_terms' => 'administrator',
            'assign_terms' => 'administrator', 'editor', 'author', 'contributor'
            ),
    'labels' => array(
        'name' => 'WOD Names',
        'singular_name' => 'WOD Name',
        'edit_item' => 'Edit WOD Name',
        'update_item' => 'Update WOD Name',
        'add_new_item' => 'Add New WOD Name',
        'new_item_name' => 'New WOD Name Name',
        'all_items' => 'All WOD Names',
        'search_items' => 'Search WOD Names',
        'popular_items' => 'Popular WOD Names',
        'separate_items_with_commas' => 'Separate wod names with commas',
        'add_or_remove_items' => 'Add or remove wod names',
        'choose_from_most_used' => 'Choose from the most popular wod names',
    ),
);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

When assigning capabilities to ‘capabilities’ argument of register_taxonomy() you need to assign the capability and not the role! so use capabilities that only a specific role has eg:

'capabilities' => array (
            'manage_terms' => 'manage_options', //by default only admin
            'edit_terms' => 'manage_options',
            'delete_terms' => 'manage_options',
            'assign_terms' => 'edit_posts'  // means administrator', 'editor', 'author', 'contributor'
            )


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x