Skip to main content
Notice removed Canonical answer required by Randomer11
Bounty Ended with coolpasta's answer chosen by Randomer11
Notice added Canonical answer required by Randomer11
Bounty Started worth 50 reputation by Randomer11
edited tags
Link
Randomer11
  • 416
  • 11
  • 31
added 56 characters in body
Source Link
Randomer11
  • 416
  • 11
  • 31

I'm trying to hideUnder 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 it forboth menus ( submenu's of Appearance )for ALL admins apart from a certain usernameUSERNAME.

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-menus'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.

I'm trying to hide customizer added by the theme and theme options added by a plugin. I'm using this code to hide it 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-menus');

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.

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.

Source Link
Randomer11
  • 416
  • 11
  • 31

Hide Theme options and Customize Admin menu

I'm trying to hide customizer added by the theme and theme options added by a plugin. I'm using this code to hide it 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-menus');

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.