Apply custom role capabilities to administrator (without plugin)

First off, @Wyck is right, it would be helpful to see your register_post_type code. If it were me, I’d make sure I had something like this in the $args array:

register_post_type( ... array(
    'capability_type' => 'artists',
    'map_meta_cap' => true
) );

Next, you don’t want to reset capabilities on every admin page load, that’s unnecessary work for your server. A simple trick I employ is to add ?reload_caps=1 after /wp-admin/ and check for that in my theme’s functions.php file. Here’s some code I used successfully on a site, modified to use the role artists_relations and capability type artists:

if ( is_admin() && '1' == $_GET['reload_caps'] ) {
    $administrator     = get_role('administrator');
    $artists_relations = get_role('artists_relations');

    $administrator->add_cap( 'assign_custom_taxes' );
    $artists_relations->add_cap( 'assign_custom_taxes' );

    foreach ( array('publish','delete','delete_others','delete_private','delete_published','edit','edit_others','edit_private','edit_published','read_private') as $cap ) {
        $administrator->add_cap( "{$cap}_artists" );
        $artists_relations->add_cap( "{$cap}_artists" );
    }
}

Leave a Comment