WordPress theme custom capabilities not works

I have created custom post type listings and defined some capabilities to it.But when adding capabilities it does not works.

Custom post

register_post_type('listings', array(
    'labels' => array(
        'name' => __('Restaurant listing', 'thefoody') ,
        'singular_name' => __('Restaurant listing', 'thefoody') ,
        'add_new' => __('Add New', 'thefoody') ,
        'add_new_item' => __('Add New Restaurant listing', 'thefoody') ,
        'edit' => __('Edit', 'thefoody') ,
        'edit_item' => __('Edit Restaurant listing', 'thefoody') ,
        'new_item' => __('New Restaurant listing', 'thefoody') ,
        'view' => __('View Restaurant listing', 'thefoody') ,
        'view_item' => __('View Restaurant listing', 'thefoody') ,
        'search_items' => __('Search Restaurant listings', 'thefoody') ,
        'not_found' => __('No Restaurant listings found', 'thefoody') ,
        'not_found_in_trash' => __('No Restaurant listings found in Trash', 'thefoody') ,
        'parent' => __('Parent Restaurant listing', 'thefoody') ,
    ) ,
    'public' => true,
    'show_ui' => true,
    'exclude_from_search' => true,
    'hierarchical' => true,
    'supports' => array(
        'title',
        'editor',
        'thumbnail'
    ) ,
    'query_var' => true,
    'menu_icon' => 'dashicons-megaphone',
    'capability_type'   => 'listings',
    'capabilities' => array(
        'edit_post'             => 'edit_restaurant',
        'edit_others_posts'     => 'edit_others_restaurants',
        'publish_posts'         => 'publish_restaurants',
        'read_post'             => 'read_restaurant',
        'read_private_posts'    => 'read_private_restaurants',
        'delete_posts'          => 'delete_restaurants',
        'delete_others_posts'   => 'delete_others_restaurants',
    ),
));

And my codes to add capabilities:

function add_theme_caps() {
    $role_shop_manager = get_role( 'shop_manager' );
    $role_shop_manager->add_cap( 
                            'edit_restaurants', 
                            'publish_restaurants', 
                            'view_posts', 
                            'delete_post', 
                            'delete_published_posts', 
                            'delete_restaurant' 
                        ); 
    $role_shop_manager->remove_cap( 'edit_others_restaurants', 'edit_others_posts' ); 
}
add_action( 'admin_init', 'add_theme_caps');

Read more here: WordPress theme custom capabilities not works

Leave a Reply

Your email address will not be published. Required fields are marked *