Make WordPress Core


Ignore:
Timestamp:
10/20/2015 10:15:11 PM (9 years ago)
Author:
westonruter
Message:

Customizer: Introduce customize_loaded_components filter to allow core components to be disabled.

Also move style rule from customize-nav-menus.css to customize-controls.css so that widgets button is properly styled when nav_menus component is excluded from loading. See [35304]. See #33327.

Props westonruter, DrewAPicture.
Fixes #33552.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r34921 r35307  
    192192        require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
    193193        require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    194         require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
    195         require_once( ABSPATH . WPINC . '/class-wp-customize-nav-menus.php' );
    196 
    197         $this->widgets = new WP_Customize_Widgets( $this );
    198         $this->nav_menus = new WP_Customize_Nav_Menus( $this );
     194
     195        /**
     196         * Filter the core Customizer components to load.
     197         *
     198         * This allows Core components to be excluded from being instantiated by
     199         * filtering them out of the array. Note that this filter generally runs
     200         * during the <code>plugins_loaded</code> action, so it cannot be added
     201         * in a theme.
     202         *
     203         * @since 4.4.0
     204         *
     205         * @see WP_Customize_Manager::__construct()
     206         *
     207         * @param array                $components List of core components to load.
     208         * @param WP_Customize_Manager $this       WP_Customize_Manager instance.
     209         */
     210        $components = apply_filters( 'customize_loaded_components', array( 'widgets', 'nav_menus' ), $this );
     211
     212        if ( in_array( 'widgets', $components ) ) {
     213            require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
     214            $this->widgets = new WP_Customize_Widgets( $this );
     215        }
     216        if ( in_array( 'nav_menus', $components ) ) {
     217            require_once( ABSPATH . WPINC . '/class-wp-customize-nav-menus.php' );
     218            $this->nav_menus = new WP_Customize_Nav_Menus( $this );
     219        }
    199220
    200221        add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
Note: See TracChangeset for help on using the changeset viewer.