2

I've created a custom post type 'openproject', where i set capabilities.

function custom_post_openproject() {
    $labels = array(
        'name' => 'openproject',
        'add_new' => 'Add new openproject',
        'add_new_item' => 'Add new openproject',
        'edit_item' => 'Edit openproject',
        'menu_name' => 'Openproject'
    );
    $map_meta_cap = true;
    $capability_type = 'openproject';
    $capabilities = array(
        'edit_files' => 'edit_files',
        'upload_files' => 'upload_files',
        'edit_post' => 'openproject_edit',
        'read_post' => 'openproject_read',
        'delete_post' => 'openproject_delete',
        'edit_posts' => 'openprojects_edit',
        'edit_others_posts' => 'openprojects_edit_others',
        'publish_posts' => 'openprojects_publish',
        'delete_posts' => 'openprojects_delete',
        'delete_published_posts' => 'openprojects_delete_published',
        'delete_others_posts' => 'openprojects_delete_others',
        'edit_publish_posts' => 'openprojects_edit_publish',
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_in_menu' => true, 
        'capability_type' => $capability_type,
        'capabilities' => $capabilities,
        'map_meta_cap' => $map_meta_cap,
        'hierarchical' => false,
        'with_front' => false,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comment'),
        'has_archive' => false,
        'rewrite' => array('slug'=>'openproject'),
    );
    register_post_type( 'openproject', $args );
}

I assigned this custom post type to a custom role 'openproject_access'

function openproject_user_can(){
    $newrole = add_role( 
        'openproject_access', 
        'Membre OpenProject', 
        array(
            'read'=> true,

            'openprojects_publish' => true,
            'openproject_read' => true,
            'openproject_edit' => true,
            'openprojects_edit_others' => false,
            'openprojects_edit' => true,
            'openproject_delete' => true,
            'openprojects_delete' => true,
            'openprojects_delete_others' => false,

            'edit_comment' => false,
            'moderate_comments' => false,
            'edit_files' => true,
            'upload_files' => true,
        )
    ); 
}

I've created a user with this role, but when i'm logged in as this user, the problem is when i create a new 'openproject', i have only "Submit for review" button and not "Publish" !

I think i have set the publish capability properly in my setting ('publish_posts' => 'openprojects_publish', in CPT and 'openprojects_publish' => true, in the role) What i have missed ?

EDIT To be complete, i've tried this on a fresh install of WP 4.0. In my wp_usermeta i've got a:1:{s:18:"openproject_access";b:1;} for the capability of that user

1 Answer 1

1

You have map_meta_cap as true, and yet you are defining the capabilities using 'capabilities' yourself, and with backwards syntax.

When the capabilities are mapped, the verb goes at the beginning and the noun at the end, so the 'edit_post' capability would be 'edit_openproject'.

Your Answer

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

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