1

I am making a new role called "sales" where I add capabilities to, so the sales people only can read, edit and delete leads in the admin panel.

Everything works fine, except that I cannot select multiple leads (posts) and delete them in one time. I have added the capabilities "delete_lead" and "delete_leads" so in my opinion this should work.

// Create sales role
add_role( 'sales', __( 'Sales', 'gtp_translate' ) );

// Add sales capabilities to sales
$roles = array( 'sales', 'editor', 'administrator' );
foreach( $roles as $the_role ) {
    // Get role object by role name
    $role = get_role( $the_role );
    // Add capabilities to this role
    $role->add_cap( 'edit_lead' );
    $role->add_cap( 'read_lead' );  
    $role->add_cap( 'delete_lead' );
    $role->add_cap( 'edit_others_leads' );
    $role->add_cap( 'publish_leads' );
    $role->add_cap( 'edit_leads' );
    $role->add_cap( 'read_private_leads' );
    $role->add_cap( 'delete_leads' );
    $role->add_cap( 'delete_private_leads' );
    $role->add_cap( 'delete_published_leads' );
    $role->add_cap( 'delete_others_leads' );
    $role->add_cap( 'edit_private_leads' );
    $role->add_cap( 'edit_published_leads' );
}  

Normally your post type action drop down should look like the image, but "Move to trash" is not there now.

enter image description here

My Leads custom post type

// Leads
$labels = array(
    'name'                => _x( 'Leads', 'Post Type General Name', 'gtp_translate' ),
    'singular_name'       => _x( 'Lead', 'Post Type Singular Name', 'gtp_translate' ),
    'menu_name'           => __( 'Leads', 'gtp_translate' ),
    'parent_item_colon'   => __( 'Parent Lead:', 'gtp_translate' ),
    'all_items'           => __( 'All Leads', 'gtp_translate' ),
    'view_item'           => __( 'View Lead', 'gtp_translate' ),
    'add_new_item'        => __( 'Add New Lead', 'gtp_translate' ),
    'add_new'             => __( 'Add New', 'gtp_translate' ),
    'edit_item'           => __( 'Edit Lead', 'gtp_translate' ),
    'update_item'         => __( 'Update Lead', 'gtp_translate' ),
    'search_items'        => __( 'Search Leads', 'gtp_translate' ),
    'not_found'           => __( 'Not found', 'gtp_translate' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'gtp_translate' ),
);
$args = array(
    'label'               => 'leads',
    'description'         => 'Leads',
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'author', 'revisions', 'custom-fields', ),
    'hierarchical'        => false,
    'public'              => false,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => false,
    'show_in_admin_bar'   => true,
    'menu_position'       => 3,
    'menu_icon'           => '',
    'can_export'          => true,
    'has_archive'         => false,
    'exclude_from_search' => true,
    'publicly_queryable'  => false,
    'capability_type'     => array( 'lead', 'leads' ),
);
register_post_type( 'leads', $args );
4
  • Are you sure this is the code responsible?
    – s_ha_dum
    Commented May 4, 2015 at 14:18
  • @s_ha_dum Yes I am sure. The only thing which maybe is relevant is that I use 'capability_type' => array( 'lead', 'leads' ) as argument for my leads post type.
    – Robbert
    Commented May 4, 2015 at 14:22
  • hmm... at least post the code for your "Leads" CPT so the whole thing can be replicated.
    – s_ha_dum
    Commented May 4, 2015 at 14:28
  • @s_ha_dum Watch my edit
    – Robbert
    Commented May 4, 2015 at 14:32

1 Answer 1

1

you need to add

map_meta_cap => true,

in the args of register_post_type

    'publicly_queryable'  => false,
    'map_meta_cap'  => true,
    'capability_type'     => array( 'lead', 'leads' ),
);
register_post_type( 'leads', $args );

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.