1

When adding a custom post type using the "capability_type" argument, custom capabilities are automatically generated for the post type.

https://developer.wordpress.org/reference/functions/register_post_type/#capability_type

Ie registering a post type named "cars"

'capability_type' => array('cars', 'car')   

Automatically generates 'edit_cars', 'delete_car' etc.

Afterwards, these capabilities can be added to a custom user role to control their access and permissions. So far so good.

But.. Isn't the administrator role supposed to have all capabilities including custom ones per default?

When using the above approach, my admin users loses their permission to edit the post type in question.

What is the correct approach here? Should all custom caps be added to admin role manually like they are added to other roles?

TIA

1 Answer 1

0

What is the correct approach here? Should all custom caps be added to admin role manually like they are added to other roles?

Yes, because register_post_type() will not automatically assign the capabilities to any users or user roles, including administrators, but if Multisite is enabled, then those who are super admins would always be able to manage (e.g. edit or delete) the posts in the post type, unless if do_not_allow is present in their capabilities (as returned by map_meta_cap()) — see WP_User::has_cap().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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