Custom Post Types – Capability Type

I agree with you that the codex isn’t a huge help on this subject. Check out the stuff about capabilities under register_post_type – it needs a serious rewrite.

As I understand it, only page and post can be used in the way you suggest (and in fact post is used by default in the absence of a defined capability type).

Of course, by creating your book version of all the usual caps, you allow yourself to assign capabilities specific to your custom post type, either in your own code or via a plugin such as members.

You can create any capability you like, but I’m not sure you can do it at that stage. What I tend to do, is assign a custom cap to a role:

$role = get_role( 'administrator' );
$role->add_cap( 'access_awesomeness' );

I would probably do this on plugin activation, as caps are written to the DB, so why do it more than once.

Your plugin can then check if the current user has permission to do whatever with it:

if (current_user_can( 'access_awesomeness' )) { ...

You can also use it where you’d add any other permission – for example:

add_menu_page( $page_title, $menu_title, 'access_awesomeness', $menu_slug, $function, $icon_url, $position );

I’m not sure that answers your question entirely, but that’s my 2 cents worth.

Leave a Comment