所以我得到了这个代码,它的作用与我想要的相反。
add_action(\'admin_menu\', \'remove_admin_menu_links\');
function remove_admin_menu_links(){
$user = wp_get_current_user();
//if( $user && isset($user->user_email) && \'[email protected]\' == $user->user_email ) {
if( !$user && isset($user->user_login) && \'USERNAMEHERE\' == $user->user_login ) {
remove_menu_page(\'tools.php\');
remove_menu_page(\'tools.php\');
remove_menu_page(\'themes.php\');
remove_menu_page(\'options-general.php\');
remove_menu_page(\'plugins.php\');
remove_menu_page(\'users.php\');
remove_menu_page(\'edit-comments.php\');
remove_menu_page(\'page.php\');
remove_menu_page(\'upload.php\');
remove_menu_page( \'edit.php?post_type=page\' );
remove_menu_page( \'edit.php?post_type=videos\' );
remove_menu_page( \'edit.php\' );
}
}
remove_theme_support( \'user-admin-menu\' );
因此,如果用户名为“USERNAMEHERE”,则上面的代码会隐藏管理菜单,但是我希望它做完全相反的事情,所以我希望所有菜单都对除某个用户名之外的所有管理员隐藏。
我想添加!if语句内部可能已经完成了,但它似乎不起作用?
最合适的回答,由SO网友:vikrant zilpe 整理而成
function hide_menu() {
global $current_user;
$current_user = wp_get_current_user();
$user_name = $current_user->user_login;
//check condition for the user means show menu for this user
if(is_admin() && $user_name != \'USERNAME\') {
//your code here
}
}
add_action(\'admin_head\', \'hide_menu\');