I have a custom post type registered and when registering I am using...

if( !post_type_exists( 'email_template' ) ) {
            register_post_type( 'email_template',
                    'labels'    => array(
                        'name'               => _x( 'Email Templates', 'post type general name', 'mobile-dj-manager' ),
                        'singular_name'      => _x( 'Email Template', 'post type singular name', 'mobile-dj-manager' ),
                        'menu_name'          => _x( 'Email Templates', 'admin menu', 'mobile-dj-manager' ),
                        'name_admin_bar'     => _x( 'Email Template', 'add new on admin bar', 'mobile-dj-manager' ),
                        'add_new'            => __( 'Add Template', 'mobile-dj-manager' ),
                        'add_new_item'       => __( 'Add New Template', 'mobile-dj-manager' ),
                        'new_item'           => __( 'New Template', 'mobile-dj-manager' ),
                        'edit_item'          => __( 'Edit Template', 'mobile-dj-manager' ),
                        'view_item'          => __( 'View Template', 'mobile-dj-manager' ),
                        'all_items'          => __( 'All Templates', 'mobile-dj-manager' ),
                        'search_items'       => __( 'Search Templates', 'mobile-dj-manager' ),
                        'not_found'          => __( 'No templates found.', 'mobile-dj-manager' ),
                        'not_found_in_trash' => __( 'No templates found in Trash.', 'mobile-dj-manager' ) ),
                    'description'           => __( 'Email Templates for the Mobile DJ Manager plugin', 'mobile-dj-manager' ),
                    'public'                 => false,
                    'exclude_from_search'   => true,
                    'publicly_queryable'     => true,
                    'show_ui'               => true,
                    'show_in_menu'         => 'edit.php?post_type=email_template',
                    'show_in_admin_bar'   => true,
                    'query_var'           => true,
                    'rewrite'               => array( 'slug' => 'email-template' ),
                    'capability_type'       => 'mdjm_template',
                    'capabilities'           => array(
                        'edit_post'             => 'edit_mdjm_template',
                        'read_post'             => 'read_mdjm_template',
                        'delete_post'           => 'delete_mdjm_template',
                        'edit_posts'            => 'edit_mdjm_templates',
                        'edit_others_posts'     => 'edit_others_mdjm_templates',
                        'publish_posts'         => 'publish_mdjm_templates',
                        'read_private_posts'    => 'read_private_mdjm_templates'
                    'map_meta_cap'         => true,
                    'has_archive'           => true,
                    'hierarchical'             => false,
                    'menu_position'           => 5,
                    'supports'             => array( 'title', 'editor', 'revisions' ) ) );

to register the post type.

I have confirmed using User Role Editor that my user has all of the *_mdjm_template caps and yet the user cannot create a new post. The only other cap this role has is 'read'. The New post button is displayed but clicking it renders the "You do not have sufficient permissions to access this page." message.

All other functionality within this post type works fine. i.e. The user can see all posts and edit them. Just not create new ones.

What have I missed?


I am adding the caps to a user role that was created during plugin activation using the below...

$role = get_role( 'my_role' );
$caps = array( 
    'mdjm_template_edit' => true, 'edit_mdjm_template' => true,
    'read_mdjm_template' => true, 'delete_mdjm_template' => true, 'edit_mdjm_templates' => true,
    'edit_others_mdjm_templates' => true, 'publish_mdjm_templates' => true, 'read_private_mdjm_templates' => true,
    'edit_published_mdjm_templates' => true, 'edit_private_mdjm_templates' => true, 'delete_mdjm_templates' => true,
    'delete_others_mdjm_templates' => true, 'delete_private_mdjm_templates' => true,
    'delete_published_mdjm_templates' => true

foreach( $caps as $cap => $val )    {
    if( empty( $val ) )
        $role->remove_cap( $cap );
        $role->add_cap( $cap );

Output of user caps to error log whilst trying to create new post*

Signed in as user with the appropriate role and using current_user_can( '$cap' )

mdjm_template_edit: Has Cap
edit_mdjm_template: Does not have Cap
read_mdjm_template: Does not have Cap
delete_mdjm_template: Does not have Cap
edit_mdjm_templates: Has Cap
edit_others_mdjm_templates: Has Cap
publish_mdjm_templates: Has Cap
read_private_mdjm_templates: Has Cap
edit_published_mdjm_templates: Has Cap
edit_private_mdjm_templates: Has Cap
delete_mdjm_templates: Has Cap
delete_others_mdjm_templates: Has Cap
delete_private_mdjm_templates: Has Cap
delete_published_mdjm_templates: Has Cap
  • Can an admin user create a post? Is the user who can't create a post a standard user or one with customized role/privileges? Commented Dec 11, 2015 at 20:00
  • Its a custom role with only read caps from the default WP caps but all the custom caps for the post type. Admin is fine and can create new custom posts without issue
    – Mike
    Commented Dec 11, 2015 at 21:34
  • You may know this already, but -- the array code in your example is just what provides post-type-specific names to each of the capabilities. Toggling those capabilities is done in your User Role Editor. I suspect you will need to provide more information on the User Role Editor settings. Commented Dec 12, 2015 at 0:22
  • Also -- can the user in question Create New regular posts? Commented Dec 12, 2015 at 0:22
  • 1
    The user cannot create other post types. The only caps this role has are the *_mdjm_template(s) caps and the built in 'read' cap. I updated the original post to include the full register_post_type function
    – Mike
    Commented Dec 12, 2015 at 11:41


Your Answer

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

Browse other questions tagged or ask your own question.