我通过一点“补丁”解决了这个问题,这要感谢对这两个线程的解释:Remove ability to access certain admin menus &;Hide Admin menus per role in Wordpress
我在restrict\\u菜单功能中添加了我需要禁止访问的项目,并在remove\\u菜单中隐藏了我能够访问的列表项目。我还将此角色处于活动状态时启动的管理样式表排入队列,并隐藏显示的插件项。
这是我现在的最终代码:
//remove_role( \'Supervisor\'); // developing purposes only
$result = add_role( \'Supervisor\',
__(\'Supervisor\' ),
array(
\'read\' => true,
\'create_posts\' => false,
\'create_pages\' => false,
\'moderate_comments\' => false,
\'edit_pages\' => true,
\'publish_pages\' => true,
\'edit_published_pages\' => true,
)
);
function restrict_menus(){
$author = wp_get_current_user();
if(isset($author->roles[0])){
$current_role = $author->roles[0];
}else{
$current_role = \'no_role\';
}
if($current_role == \'Supervisor\'){
$screen = get_current_screen();
$base = $screen->id;
if($base == \'edit-post\' || $base == \'tools\' || $base == \'edit-comments\' ||
$base == \'page\' && $action == \'add\' || $base == \'te_announcements\' && $action == \'add\')
{
wp_die(\'Não tem permissões para aceder a esta área\');
}
}
}
add_action( \'current_screen\', \'restrict_menus\' );
function remove_menus()
{
global $menu;
$author = wp_get_current_user();
if(isset($author->roles[0])){
$current_role = $author->roles[0];
}else{
$current_role = \'no_role\';
}
if($current_role == \'Supervisor\')
{
$restricted = array(__(\'Comments\'),
__(\'Appearance\'),
__(\'Plugins\'),
__(\'Tools\'),
__(\'Settings\'),
__(\'Posts\'),
);
end ($menu);
while (prev($menu)){
$value = explode(\' \',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while
}// end if
}
add_action(\'admin_menu\', \'remove_menus\');
如果有人有更好的办法,请告诉我。