最简单的方法是创建两个自定义功能,并将它们分配给管理员,一个分配给角色教练,另一个分配给角色球员。
创建角色时,您可以执行以下操作:
$coach_caps = array(
\'read\' => true,
\'something_else\' => true,
\'can_open_coach_menu\' => TRUE // this is important for your scope
);
add_role( \'coach\', \'Coach\', $coach_caps );
$player_caps = array(
\'read\' => true,
\'something\' => true,
\'can_open_player_menu\' => TRUE // this is important for your scope
);
add_role( \'player\', \'Player\', $player_caps );
然后将这两种功能分配给管理员角色:
$roles = new WP_Roles();
$roles->add_cap( \'administrator\', \'can_open_coach_menu\', TRUE);
$roles->add_cap( \'administrator\', \'can_open_player_menu\', TRUE);
现在,添加子菜单页时:
// this is for administrator and coach roles
add_submenu_page( $parent, $p_title, $m_title, \'can_open_coach_menu\', \'submenu1\');
// this is for administrator and player roles
add_submenu_page( $parent, $p_title, $m_title, \'can_open_player_menu\', \'submenu2\');