Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

(There are about 3-5 answers regarding this question that I can find and none give a solid answer - I want to do this without external plugins because this is for my own plugin)

I am looking to add a new capability to my custom Role I have added. My role is added on plugin activation, and it will be removed on deactivation, so that side of things is not an issue. I just want a CPT, and a custom user role, and the new user role can manage the CPT.

I have read on some answers I found that the below code is something to do with it. When I have added a CPT in the past, I assumed capability_type should be set to the (already existing) post type that I want to mimic the capabilities of, so I usually just wrote post/page in there.

register_post_type( ... array(
    'capability_type' => 'artists',
    'map_meta_cap' => true
));

Now I understand it is something to do with that, it's just getting my head around it. I have read the Roles and Capabilities page, and every question/answer I can find on the subject, I am just struggling to understand it still. If what I think is true is true, and I add my custom capabilities through the register_post_type somehow, then do I need to do that before registering my new roles? I wish there was just clear documentation on creating a new cap.

Just so I don't miss anything, I will also include my add_role code below, which is all I currently have at the minute, I haven't added my CPT yet.

public static function activate($network_wide) {
    if(get_role('devil')) {

    } else {
        $caps = array(
            'read' => true,
            'delete_posts' => true,
            'edit_posts' => true,
            'delete_published_posts' => true,
            'publish_posts' => true,
            'create_product' => true,
            'upload_files' => true,
            'edit_published_posts' => true,
            'read_private_pages' => true,
            'edit_private_pages' => true,
            'delete_private_pages' => true,
            'read_private_posts' => true,
            'edit_private_posts' => true,
            'delete_private_posts' => true,
            'delete_others_posts' => true,
            'delete_published_pages' => true,
            'delete_others_pages' => true,
            'delete_pages' => true,
            'publish_pages' => true,
            'edit_published_pages' => true,
            'edit_others_pages' => true,
            'edit_pages' => true,
            'edit_others_posts' => true,
            'manage_links' => true,
            'manage_categories' => true,
            'moderate_comments' => true
        );
        $result = add_role('devil', 'Devil', $caps);

        if(null !== $result) {
            echo 'Role created';
        } else {
            echo 'Role creation failed. Does it already exist?';
        }
    }
}
share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.