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.

I'm trying to add a specific role to manage my custom post types and I'm stuck at the very beginning.

I've added add_role() to the functions.php file as following:

add_role('resourcerer', 'Resourcerer', array('read_internal_jobs'));

and created a user with that role. However, when I try to login with a new user I would get an error You do not have sufficient permissions to access this page. I can't figure out what I'm doing wrong here :S

When registering my Custom Post Type I've got the following settings:

'capability_type' => array('internal_job', 'internal_jobs'),
'map_meta_cap' => true,

which, if I understand the register_post_type() Codex correctly, by specifying capability_type the capabilities strings will be constructed respectively using the strings specified in the capability_type, for example: edit_internal_jobs, publish_internal_jobs and so on.

I would really appreciate any help!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

That's because the "normal" capabilites that are needed to login are missing. You should simply load the capabilites of some default role and attach them to your custom role before using it on a user.


EDIT: Solution from @dashalune (OP):

add_role('resourcerer', 'Resourcerer'); 
$role =& get_role('resourcerer'); 
$role->add_cap('read');
share|improve this answer
    
thanks. I've added the 'read' capability, so at least I could login and see admin side. Here is my code if anyone will find it useful: add_role('resourcerer', 'Resourcerer'); $role =& get_role('resourcerer'); $role->add_cap('read'); –  dashaluna Sep 13 '11 at 11:21

This is a full working example of custom roles for a custom made role (via add_role) for a specific theme:

function add_theme_caps() {
    $role = get_role( 'roletypename' );
    // create if neccesary
    if (!$role) $role = add_role('roletypename', 'Role Name'); 
    // add theme specific roles
    $role->add_cap('delete_posts');
    $role->add_cap('delete_published_posts');
    $role->add_cap('edit_posts');
    $role->add_cap('edit_published_posts');
    $role->add_cap('publish_posts');
    $role->add_cap('read');
    $role->add_cap('upload_files');
}
add_action( 'admin_init', 'add_theme_caps');
share|improve this answer

Your Answer

 
discard

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

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