我不知道这是否是最好的方法,但我最近刚刚做的一件事(从这里的答案中挑选出来)是,如果不满足某些条件,就删除菜单页,并更新所有删除的页面上的大写字母,这样就不会被足够聪明的人访问,从而记住URL。
add_action(\'admin_menu\', \'wpa_44698\',999);
function wpa_44698(){
global $submenu;
//only show w3tc_general options to network admins in multisite
if ( is_multisite() && !current_user_can( \'manage_network\' ) ) {
remove_menu_page(\'w3tc_general\');
// Still need to update cap requirements even when hidden
if(isset($submenu[\'w3tc_general\'])) foreach( $submenu[\'w3tc_general\'] as $position => $data ) {
$submenu[\'w3tc_general\'][$position][1] = \'manage_network\';
}
}
}
编辑:我不知道这是否“更好”,但它似乎也有效。
add_action(\'admin_menu\', \'wpa_44698\',999);
function wpa_44698(){
global $submenu;
//only show w3tc_general options to network admins in multisite
if ( is_multisite() && !current_user_can( \'manage_network\' ) && isset($submenu[\'w3tc_general\']) ) {
foreach( $submenu[\'w3tc_general\'] as $position => $data ) {
remove_menu_page($data[2]);
$submenu[\'w3tc_general\'][$position][1] = \'manage_network\';
}
}
}