Question

I am trying to hide almost every single admin menu from wordpress dashboard for a specific user id who has administrator role. I want to give that user only option to edit a certain custom post type named lessons and other custom post type Events.

I am using LMS wordpress theme from themeforest by designthemes. I am not sure why this theme just don't give access to the WP-admin for other role except administrator, like Editor, Contributor etc. So I decided to give that specific user administrator role so that he can get in to wordpress dashboard. Then my plan is just to hide other admin menu for this user.

I have used the plugin called User role editor pro and other free plugins. but nothing seems to be working with this. Then I tried with the below code. But this code is removing these admin menus from other administrator dashboard as well where I want these menus to be removed for this user id only who's user id is 279 here. Any help is appreciated. This is the site link https://impactmarketingsystems.com/

<?php
function hide_menu(){
 global $current_user;
 $user_id = get_current_user_id();
 // echo "user:".$user_id;   // Use this to find your user id quickly

    if($user_id != '279'){

        // To remove the whole Appearance admin menu you would use;

        remove_menu_page( 'themes.php' );

        // To remove the theme editor and theme options submenus from
        // the Appearance admin menu, as well as the main 'Themes'
        // submenu you would use 

        remove_menu_page( 'index.php' );
        remove_submenu_page( 'index.php', 'update-core.php' );

        remove_submenu_page( 'themes.php', 'themes.php' );
        remove_submenu_page( 'themes.php', 'theme-editor.php' );
        remove_submenu_page( 'themes.php', 'theme_options' );

        remove_menu_page( 'users.php' );
        remove_submenu_page( 'users.php', 'user-new.php' );
        remove_submenu_page( 'users.php', 'profile.php' );

        remove_menu_page( 'upload.php' );
        remove_submenu_page( 'upload.php', 'media-new.php' );
        remove_submenu_page( 'upload.php', 'upload.php?page=wp-smush-bulk' );

        remove_menu_page( 'admin.php?page=Wordfence' );
        remove_submenu_page( 'admin.php?page=Wordfence', 'media-new.php' );


        remove_menu_page( 'edit.php?post_type=dt_teachers' );
        remove_submenu_page( 'edit.php?post_type=dt_teachers', 'post-new.php?post_type=dt_teachers' );

        remove_menu_page( 'edit.php?post_type=dt_portfolios' );
        remove_submenu_page( 'edit.php?post_type=dt_portfolios', 'post-new.php?post_type=dt_portfolios' );
        remove_submenu_page( 'edit-tags.php?taxonomy=portfolio_entries', 'edit-tags.php?taxonomy=portfolio_entries&post_type=dt_portfolios' );

        remove_menu_page( 'edit.php' );
        remove_submenu_page( 'edit.php', 'post-new.php' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );


        // Remove Page menu Items
        remove_menu_page( 'edit.php?post_type=page' );
        remove_submenu_page( 'edit.php?post_type=page', 'post-new.php?post_type=page' );


        // Remove Comments Menu

        remove_menu_page( 'edit-comments.php' );

        //// Remove LMS Menu
        remove_menu_page( 'admin.php?page=parent' );

         remove_menu_page( 'tools.php' );                  //Tools
         remove_menu_page( 'options-general.php' );        //Settings

          remove_menu_page( 'plugins.php' );        //Plugins

          remove_menu_page( 'edit.php?post_type=product' );





// Not working
// Remove WP Contacts Items  
        remove_menu_page( 'admin.php?page=shwcp_options' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_options&db=1' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_add_db' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_delete_db' );    


        remove_menu_page( 'admin.php?page=upme-settings' ); 

        remove_menu_page( 'admin.php?page=ultimate_affiliates_pro' );     


    }
}




add_action('admin_head', 'hide_menu');

?>
Was it helpful?

Solution

problem is with your logical statement. now you are trying to remove dashboard staff where user id is not '279', which means only user id 279 can see dashboard. you can try this in if statement

if(is_admin() && $user_id == '279'){ //your codes }
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top