Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter

Have you tried defining the capabilities inside the external_roles_post_type_init() function?

After the

'capability_type' => array('external_role', 'external_roles'),

try add this

'capabilities' => array(
    'publish_posts' => 'publish_external_roles',
    'edit_posts' => 'edit_external_roles',
    'edit_others_posts' => 'edit_others_external_roles',
    'delete_posts' => 'delete_external_roles',
    'delete_others_posts' => 'delete_others_external_roles',
    'read_private_posts' => 'read_private_external_roles',
    'edit_post' => 'edit_external_role',
    'delete_post' => 'delete_external_role',
    'read_post' => 'read_external_role',
        ),

as another argument of the $args array

Then, before applying the capability to this or that role
you can try to install User Role Editor Plugin an look if the capabilities a really existent
If you see them you can even think about using just that plugin to give or revoke caps to roles.
I know it’s not like coding, but acually the ability to give and revoke with a click in admin panel it’s really handy.

I tell you this, because sometimes (quite often actually), I register custom post types with the very same method you use (plus the capabilities array that I’ve pasted above) but for some reason the capabilities are not really created.
Sometimes I solve just by moving registration function in upper position in functions.php file.
It seems like wichcraft to me also, but sometimes it works.

When I find myself in dead path like that the only solution I can find is using both User Role Editor and Map Cap plugins.
I do not like that, but it’s better than loosing mind.

I hope it helps you, even if it does not solve the “confusion” state that I’m sharing with you.

Leave a Comment