Members-Core Create Caps – also for custompost types

1 Reply ·

  1. Hi,

    I just bought this add-on for Members,and I was hoping that this add-on would also apply to the custom post types which I created. Unfortunately, it only works for Posts and Pages.
    Would the next release also work for custom post types?
    Or guide me how to amend your code to achieve this.

    Kind regards,

  2. Justin Tadlock

    This plugin shouldn’t touch custom post types (CPTs) because it would most certainly break a great many of them by doing so. Each CPT should handle its own permissions. The only reason this isn’t the case for post and page is because WP has to handle legacy support.

    How to make this same change with CPTs is going to depend on the CPT itself.

    Since you’re creating these yourself, I assume you’re familiar with the capabilities argument of register_post_type(). In particular, you’ll want to set the create_posts cap to something different from the edit_posts cap in your plugin’s code.

    Here’s an example from my Custom Content Portfolio plugin:

    'capabilities' => array(
        // meta caps (don't assign these to roles)
        'edit_post'              => 'edit_portfolio_project',
        'read_post'              => 'read_portfolio_project',
        'delete_post'            => 'delete_portfolio_project',
        // primitive/meta caps
        'create_posts'           => 'create_portfolio_projects',
        // primitive caps used outside of map_meta_cap()
        'edit_posts'             => 'edit_portfolio_projects',
        'edit_others_posts'      => 'edit_others_portfolio_projects',
        'publish_posts'          => 'publish_portfolio_projects',
        'read_private_posts'     => 'read_private_portfolio_projects',
        // primitive caps used inside of map_meta_cap()
        'read'                   => 'read',
        'delete_posts'           => 'delete_portfolio_projects',
        'delete_private_posts'   => 'delete_private_portfolio_projects',
        'delete_published_posts' => 'delete_published_portfolio_projects',
        'delete_others_posts'    => 'delete_others_portfolio_projects',
        'edit_private_posts'     => 'edit_private_portfolio_projects',
        'edit_published_posts'   => 'edit_published_portfolio_projects'

    As you can see, I set the create_posts cap to create_portfolio_projects and the edit_posts cap to edit_portfolio_projects. You’d only need to do the same thing for your CPTs.