customize_loaded_componentsfilter-hookWP 4.4.0

Allows you to remove core WordPress Customizer components, such as the menus and widgets sections.

Section names removed from the array will not be initialized in the Customizer.

IMPORTANT. This filter fires during the 'plugins_loaded' event, so it must be used in a plugin and cannot be used later than this event, for example, somewhere in the theme's functions.php file.

Usage

add_filter( 'customize_loaded_components', 'wp_kama_customize_loaded_components_filter', 10, 2 );

/**
 * Function for `customize_loaded_components` filter-hook.
 * 
 * @param string[]             $components Array of core components to load.
 * @param WP_Customize_Manager $manager    WP_Customize_Manager instance.
 *
 * @return string[]
 */
function wp_kama_customize_loaded_components_filter( $components, $manager ){
	// filter...
	return $components;
}
$components(array)

An array of core components to load in the Customizer.

Array (
	[0] => widgets
	[1] => nav_menus
)
$that(WP_Customize_Manager)
An instance of WP_Customize_Manager.

Examples

#1 Remove the “widgets” and “menus” sections from the Customizer.

## Removes the “widgets” and “menus” sections from the Customizer.
add_filter( 'customize_loaded_components', 'remove_core_customizer_components' );
function remove_core_customizer_components( $components ){

	foreach( [ 'nav_menus', 'widgets' ] as $key ){

		$i = array_search( $key, $components );

		if ( false !== $i )
			unset( $components[ $i ] );

	}

	return $components;
}
The following items will be removed

Changelog

Since 4.4.0 Introduced.

Where the hook is called

WP_Customize_Manager::__construct()
customize_loaded_components
wp-includes/class-wp-customize-manager.php 359
$components = apply_filters( 'customize_loaded_components', $this->components, $this );

Where the hook is used in WordPress

Usage not found.