Skip to main content
3 of 3
edited tags
Randomer11
  • 416
  • 11
  • 31

Hide Theme options and Customize Admin menu

Under the appearance admin menu, I have customizer added by the theme, and theme options added by a plugin. I'm using this code to hide both menus ( submenu's of Appearance )for ALL admins apart from a certain USERNAME.

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

         remove_submenu_page( 'themes.php', 'customize' );
         remove_submenu_page( 'themes.php', 'core-settings' );
   }
}
add_action('admin_head', 'hide-menu');

The code its self works fine, I can hide parent menu's. But I can't seem to hide the two sub menu's that I want to hide.

The two menu's point to URLs :

domainname.com/wp-admin/customize.php

domainname.com/wp-admin/themes.php?page=core-settings

Submenu Debug :

[6] => Array
                (
                    [0] => Customise
                    [1] => customize
                    [2] => customize.php?return=%2Fwp-admin%2Findex.php
                    [3] => 
                    [4] => hide-if-no-customize
                )
               [21] => Array
                (
                    [0] => Theme Settings
                    [1] => manage_options
                    [2] => core-settings
                    [3] => Theme Settings
                )

I've looked at dubug mode but im not sure what im looking at, could someone please give a solution and an explanation as to why it works.

Randomer11
  • 416
  • 11
  • 31