First you have to passed two additional arguments into the register_post_type() function.
- capability_type
- map_meta_cap
Then, You can add capability using add_cap(); function.
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
'capability_type' => array('acme_product','acme_products'),
'map_meta_cap' => true,
)
);
add_action('admin_init','vendor_role_caps');
function vendor_role_caps() {
$role = get_role('vendor_user');
$role->add_cap( 'read' );
$role->add_cap( 'read_acme_product');
$role->add_cap( 'read_private_acme_products' );
$role->add_cap( 'edit_acme_product' );
$role->add_cap( 'edit_acme_products' );
$role->add_cap( 'edit_others_acme_products' );
$role->add_cap( 'edit_published_acme_products' );
$role->add_cap( 'publish_acme_products' );
$role->add_cap( 'delete_others_acme_products' );
$role->add_cap( 'delete_private_acme_products' );
$role->add_cap( 'delete_published_acme_products' );
}