Delete the submenu page "customize.php" in WordPress 4.0

When I started WP 3.9.2, I was able to use the following code to remove the "Configure" menu item from the "Appearance" in the admin menu.

function remove_customize() { remove_submenu_page('themes.php', 'customize.php'); } add_action('admin_init', 'remove_customize', 999); 

As soon as I upgraded to version 4.0, this no longer works.

+8
source share
12 answers

Edit: Updated for WordPress 4.9+ and increased compatibility with PHP = 5.4

The WordPress core does not offer a binding for disabling theme customization , but there is a smart and elegant way to remove "Customize" from the "Appearance" menu by changing the global variable $submenu :

 /** * Remove Admin Menu Link to Theme Customizer */ add_action( 'admin_menu', function () { global $submenu; if ( isset( $submenu[ 'themes.php' ] ) ) { foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) { if ( in_array( array( 'Customize', 'Customizer', 'customize' ), $menu_item ) ) { unset( $submenu[ 'themes.php' ][ $index ] ); } } } }); 

While other code examples here and elsewhere rely irresponsibly on the specific numeric indices of the global variable $ submenu (for example, $submenu['themes.php'][6][0] , ...), this method intelligently passes through the hierarchy, so it should be compatible with older (3.x) and newer versions of WordPress (4.x).

+3
source

This works with WordPress 4.1 and 4.0 and 3.x here:

Edit: adjusted for compatibility with WordPress 4.1:

 function remove_customize() { $customize_url_arr = array(); $customize_url_arr[] = 'customize.php'; // 3.x $customize_url = add_query_arg( 'return', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'customize.php' ); $customize_url_arr[] = $customize_url; // 4.0 & 4.1 if ( current_theme_supports( 'custom-header' ) && current_user_can( 'customize') ) { $customize_url_arr[] = add_query_arg( 'autofocus[control]', 'header_image', $customize_url ); // 4.1 $customize_url_arr[] = 'custom-header'; // 4.0 } if ( current_theme_supports( 'custom-background' ) && current_user_can( 'customize') ) { $customize_url_arr[] = add_query_arg( 'autofocus[control]', 'background_image', $customize_url ); // 4.1 $customize_url_arr[] = 'custom-background'; // 4.0 } foreach ( $customize_url_arr as $customize_url ) { remove_submenu_page( 'themes.php', $customize_url ); } } add_action( 'admin_menu', 'remove_customize', 999 ); 
+17
source

The answer should be:

 add_action( 'admin_menu', function () { global $submenu; if ( isset( $submenu[ 'themes.php' ] ) ) { foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) { foreach ($menu_item as $value) { if (strpos($value,'customize') !== false) { unset( $submenu[ 'themes.php' ][ $index ] ); } } } } }); 

The way rjb used the array as an arrow in in_array () in the accepted answer does not work. Check why in the docs . I replaced in_array with another foreach, which iterates over the arrays of $ menu_item and looks for "customize" as part of the value.

It works for me with WordPress 4.9.6

+9
source

You can directly change the global $submenus like this:

 global $submenu; unset($submenu['themes.php'][6]); // Customize link 

I use this in the same function connected to admin_menu as I use to disable other controls and it seems to work fine

 function as_remove_menus () { remove_menu_page('upload.php'); //hide Media remove_menu_page('link-manager.php'); //hide links remove_submenu_page( 'edit.php', 'edit-tags.php' ); //hide tags global $submenu; // Appearance Menu unset($submenu['themes.php'][6]); // Customize } add_action('admin_menu', 'as_remove_menus'); 
+8
source

In fact, you can use remove_submenu_page to remove the theme submenu option on the admin screen. The trick is that the URL must match what exactly is associated with the administrator for this feature to work.

 function remove_admin_menus() { remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode( str_replace( get_bloginfo('url'), "", get_admin_url() ) ) . 'themes.php' ); } add_action( 'admin_init', 'remove_admin_menus' ); 

I programmatically determined the admin URL in case you are not just using '/ wp-admin'. @isabisa This will also prevent future hacking if the index of a menu item ever changes.

I use this in WP 4.0 and it works great!

+6
source

WordPress> = 4.9.8

 add_action('admin_menu', function () { $request = urlencode($_SERVER['REQUEST_URI']); remove_submenu_page('themes.php', 'customize.php?return='. $request); }, 999); 
+2
source

@ Rjb's accepted answer didn't work for my spanish wordpress, but just changing Customize to Customize did the trick.

 /** * Remove Admin Menu Link to Theme Customizer */ add_action( 'admin_menu', function () { global $submenu; if ( isset( $submenu[ 'themes.php' ] ) ) { foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) { if ( in_array( 'customize', $menu_item ) ) { unset( $submenu[ 'themes.php' ][ $index ] ); } } } }); 
+1
source

Removing the menu is only an interim solution, since it does not completely disable the tuner. In order to completely and safely disable the customizer (as well as delete the menu), you must remove the customizer permission from all users. Something like this would do this:

 add_filter('map_meta_cap', function($caps, $cap, $user_id, $args) { if ('customize' == $cap) return ['do_not_allow']; return $caps; }, 10, 4); 
+1
source

Try changing 'admin_init' to 'admin_menu'

0
source

@ bash88 answer and @Emanuel A. answer work, but if you want to also remove buttons (blue settings buttons) from the themes page, the answer should be as follows:

Tested WordPress 5.0.3

 /** * Remove customize links from admin panel. */ function admin_remove_customize_links() { echo '<style>.hide-if-no-customize { display: none !important; }</style>'; } add_action( 'admin_head', 'admin_remove_customize_links' ); 
0
source

Works in WordPres 5. *

Removing Customize from Wordpress Admin needs to be removed from the sidebar as well as from the top panel in front

From the sidebar menu

 add_action( 'admin_menu', 'remove_customize' ); function remove_customize() { global $submenu; if ( isset( $submenu[ 'themes.php' ] ) ) { foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) { if(in_array('Customize', $menu_item) || in_array('Customizer', $menu_item) || in_array('customize', $menu_item)) { unset( $submenu[ 'themes.php' ][ $index ] ); } } } } 

From the admin bar at the top (in front)

 add_action( 'admin_bar_menu', 'remove_customize_menu_bar', 999 ); function remove_customize_menu_bar( $wp_admin_bar ) { $wp_admin_bar->remove_node( 'customize' ); } 

This will completely disable the configuration option :)

0
source

For WordPress 5

 add_action( 'admin_menu', function() { remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME'])); }, 999 ) 
0
source

Source: https://habr.com/ru/post/1202342/


All Articles