Customizer: Re-use list of components to eliminate code duplication.

Introduces protected `WP_Customize_Manager::$components` to store list of loaded core components filtered by `customize_loaded_components`.

Props DrewAPicture.
See #35242
See #33552.
Fixes #35354.

Built from https://develop.svn.wordpress.org/trunk@36262


git-svn-id: http://core.svn.wordpress.org/trunk@36229 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-01-11 20:28:28 +00:00
parent 3e35a7157f
commit dd123ab2c0
2 changed files with 13 additions and 8 deletions

View File

@ -93,6 +93,15 @@ final class WP_Customize_Manager {
*/
protected $panels = array();
/**
* List of core components.
*
* @since 4.5.0
* @access protected
* @var array
*/
protected $components = array( 'widgets', 'nav_menus' );
/**
* Registered instances of WP_Customize_Section.
*
@ -238,7 +247,7 @@ final class WP_Customize_Manager {
* @param array $components List of core components to load.
* @param WP_Customize_Manager $this WP_Customize_Manager instance.
*/
$components = apply_filters( 'customize_loaded_components', array( 'widgets', 'nav_menus' ), $this );
$components = apply_filters( 'customize_loaded_components', $this->components, $this );
if ( in_array( 'widgets', $components ) ) {
require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
@ -1198,12 +1207,8 @@ final class WP_Customize_Manager {
* @param string $id Panel ID to remove.
*/
public function remove_panel( $id ) {
$core_panels = array(
'widgets',
'nav_menus',
);
if ( in_array( $id, $core_panels, true ) ) {
// Removing core components this way is _doing_it_wrong().
if ( in_array( $id, $this->components, true ) ) {
/* translators: 1: panel id, 2: filter reference URL, 3: filter name */
$message = sprintf( __( 'Removing %1$s manually will cause PHP warnings. Use the <a href="%2$s">%3$s</a> filter instead.' ),
$id,

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36261';
$wp_version = '4.5-alpha-36262';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.