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.
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 );
'capability_type' => array( 'lead', 'leads' )
as argument for my leads post type.