• Hi, i want to hide one menuitem for all users exept me.

    i use the plugin White Label CMS, and I want to be the only admin who can make adjustments, other admins should also be excluded, therefore no plugin with user roles can be used.

    can someone help me with the correct code?

Viewing 3 replies - 1 through 3 (of 3 total)
  • function admin_WLCMS_82js7( $hook ) {
    	$current_user = wp_get_current_user();
    	$cu_id = $current_user->ID;
    	if ($cu_id != 1) { 
    		echo "<style>#adminmenu li#menu-settings li a[href*="page=wlcms-plugin.php"] { display: none; }</style>";
    	}
    }
    add_action( 'admin_enqueue_scripts', 'admin_WLCMS_82js7', 2000 );

    You can add that to your theme functions.php. That will take the current user and find their ID. If the ID is not your ID ) this is that “1”, then it applies CSS to remove the link to White Label CMS in the admin menu. Now it’s only hiding by CSS so someone could use dev tools to unhide it so it might now be the best solution if your other admins know how to do it.

    • This reply was modified 2 years, 2 months ago by tugbucket.

    Hello @winock
    You can user ‘remvoe_menu_page’ function to hide any specific menu item from any user. Example:

    function hide_menu() {
        $user = wp_get_current_user();
        if (!$user->ID == 1) { // replace 1 with the ID of the user you want to allow the menu for
            remove_menu_page('index.php'); // Dashboard
            remove_menu_page('edit.php'); // Posts
            remove_menu_page('upload.php'); // Media
            remove_menu_page('link-manager.php'); // Links
            remove_menu_page('edit.php?post_type=page'); // Pages
            remove_menu_page('edit-comments.php'); // Comments
            remove_menu_page('themes.php'); // Appearance
            remove_menu_page('plugins.php'); // Plugins
            remove_menu_page('users.php'); // Users
            remove_menu_page('tools.php'); // Tools
            remove_menu_page('options-general.php'); // Settings
        }
    }
    add_action('admin_menu', 'hide_menu');
    

    Hope this will help you.
    Thanks

    @wpfy remove_menu_page('options-general.php'); will remove the entire Settings menu and the OP only want’s to remove 1 specific link under the Settings menu.

    • This reply was modified 2 years, 2 months ago by tugbucket.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show admin menu item for user ID’ is closed to new replies.