I have removed admin specific capabilities for the custom role however they can still delete admin published listings.
I only want people with the custom role of submit_listing to be able to submit and edit own listings, not delete or edit listings from admin, author or editor.
add_action( 'admin_init', 'add_custom_role_capabilities', 999 );
function add_custom_role_capabilities() {
// Don't lock admins out
$admins = get_role( 'administrator' );
$admins->add_cap( 'publish_listings' );
$admins->add_cap( 'edit_listings' );
$admins->add_cap( 'edit_others_listings' );
$admins->add_cap( 'delete_listings' );
$admins->add_cap( 'delete_others_listings' );
$admins->add_cap( 'read_private_listings' );
$admins->add_cap( 'edit_listing' );
$admins->add_cap( 'delete_listing' );
$admins->add_cap( 'read_listing' );
// Does our custom role exist?
$submit_listing = get_role( 'submit_listing' );
// Nope? Let's create it
if ( ! $submit_listing )
$submit_listing = add_role( 'submit_listing', __( 'Submit Listings' ) );
// Add core capabilities
$submit_listing->add_cap( 'read' ); // admin access
$submit_listing->add_cap( 'upload_files' ); // featured images
// Add listings capabilities
$submit_listing->add_cap( 'edit_listings' );
$submit_listing->add_cap( 'delete_listings' );
$submit_listing->add_cap( 'read_private_listings' );
$submit_listing->add_cap( 'edit_listing' );
$submit_listing->add_cap( 'delete_listing' );
$submit_listing->add_cap( 'read_listing' );
}
Also note the following post type args :
'capability_type' => array( 'listing', 'listings' );
'map_meta_cap' => false;
'capabilities' => array(
'publish_posts' => 'publish_listings',
'edit_posts' => 'edit_listings',
'edit_others_posts' => 'edit_others_listings',
'delete_posts' => 'delete_listings',
'delete_others_posts' => 'delete_others_listings',
'read_private_posts' => 'read_private_listings',
'edit_post' => 'edit_listing',
'delete_post' => 'delete_listing',
'read_post' => 'read_listing',
);
return $args;