我正在创建新的用户角色"test_client"并且它正在工作,但我的问题是我只想在仪表板中显示我的自定义插件页面菜单,但在此代码中"manage_options"是"true",然后显示所有插件菜单,如果"manage_options"为"false",则不显示任何插件菜单。
$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,
)
);
那么如何在WordPress仪表板中仅显示自定义插件菜单
将
自定义功能添加到插件菜单
$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' => false,
'custom_capability_name'=>true,
)
);
之后添加
$role= get_role('test_client');
$role->add_cap('custom_capability_name');
最后将管理菜单中的"manage_option"更改为"cusotom_capability_name"