$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - Show menus to one admin username|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - Show menus to one admin username

matteradmin6PV0评论

So I've got this code which does the reverse of what I want it to do.

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' );

So the above code hides admin menu's if the username is "USERNAMEHERE", however id like it to do the complete opposite, so id like all menu's to be hidden to all admins apart from a certain username.

I thought adding ! inside the if statement might have done it but it doesnt seem to work ?

So I've got this code which does the reverse of what I want it to do.

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' );

So the above code hides admin menu's if the username is "USERNAMEHERE", however id like it to do the complete opposite, so id like all menu's to be hidden to all admins apart from a certain username.

I thought adding ! inside the if statement might have done it but it doesnt seem to work ?

Share Improve this question asked Nov 15, 2018 at 10:56 Randomer11Randomer11 41611 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1
    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');

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far