当我需要为不同的用户提供不同的菜单时,我会为每个用户类型创建一个角色(在您的情况下Merchant
和Owner
) 我为每个角色提供了不同的视图菜单功能,例如:
add_role(\'merchant\', \'Merchant\', array(
\'merchant_menu\' => true // would allow the merchant to view merchant menu
));
add_role(\'owner\', \'Owner\', array(
\'owner_menu\' => true // would allow the owner to view owner menu
));
然后我只需创建3个菜单,而不是按位置调用wp\\u nav\\u menu(),而是按名称调用它:
if ( current_user_can(\'merchant_menu\') ) { //current user is a merchant
wp_nav_menu(array(\'menu\' => \'Merchant Menu Name\' ));
}elseif(current_user_can(\'owner_menu\') ){ //current user is an owner
wp_nav_menu(array(\'menu\' => \'Owner Menu Name\' ));
}else{//any one else get the default menu
wp_nav_menu(array(\'menu\' => \'Default Menu\' ));
}