jhon jhon - 4 months ago 13
PHP Question

show custom plugin menu for custom user role user in wordpress

i am creating new user role "test_client" and it's working but my problem is i want to show only my custom plugin page menu in dashboard but in this code "manage_options" is 'true' then all plugin menu showing and if "manage_options" is 'false' not showing any plugin menu..

$result = add_role('test_client', 'Test_client',
array(
// Dashboard
'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => false, // Allows user to edit others posts not just their own
'create_posts' => false, // Allows user to create new posts
'manage_categories' => false, // Allows user to manage post categories
'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
'manage_options' => true,
)
);


so how to showing only custom plugin menu in wordpress dashboard

Answer

add custom capabilities to your plugin menu

$result = add_role('test_client', 'Test_client', 
    array(
    // Dashboard
    'read' => true, // true allows this capability
    'edit_posts' => true, // Allows user to edit their own posts
    'edit_pages' => true, // Allows user to edit pages
    'edit_others_posts' => false, // Allows user to edit others posts not just their own
    'create_posts' => false, // Allows user to create new posts
    'manage_categories' => false, // Allows user to manage post categories
    'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
    'manage_options' => fasle,
'cusotom_capability_name'=>true,
    )
    );

after that add

$role= get_role('test_client');
$role->add_cap('cusotom_capability_name');

finally change in your admin menu 'manage_option' to your 'cusotom_capability_name'