WordPress.org

Make WordPress Core

Changeset 35307


Ignore:
Timestamp:
10/20/2015 10:15:11 PM (4 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.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/customize-controls.css

    r35304 r35307  
    22    overflow: hidden;
    33    -webkit-text-size-adjust: 100%;
     4}
     5
     6button.not-a-button {
     7    background: transparent;
     8    border: none;
     9    -webkit-box-shadow: none;
     10    box-shadow: none;
     11    -webkit-border-radius: 0;
     12    border-radius: 0;
     13    outline: 0;
     14    padding: 0;
     15    margin: 0;
    416}
    517
  • trunk/src/wp-admin/css/customize-nav-menus.css

    r35304 r35307  
    613613}
    614614
    615 button.not-a-button {
    616     background: transparent;
    617     border: none;
    618     -webkit-box-shadow: none;
    619     box-shadow: none;
    620     -webkit-border-radius: 0;
    621     border-radius: 0;
    622     outline: 0;
    623     padding: 0;
    624     margin: 0;
    625 }
    626 
    627615#available-menu-items .accordion-section-title button {
    628616    display: block;
  • 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' ) );
  • trunk/tests/phpunit/tests/customize/manager.php

    r35242 r35307  
    328328        $this->assertArrayHasKey( 'preview', $data['nonce'] );
    329329    }
     330
     331    /**
     332     * @ticket 33552
     333     */
     334    function test_customize_loaded_components_filter() {
     335        $manager = new WP_Customize_Manager();
     336        $this->assertInstanceOf( 'WP_Customize_Widgets', $manager->widgets );
     337        $this->assertInstanceOf( 'WP_Customize_Nav_Menus', $manager->nav_menus );
     338
     339        add_filter( 'customize_loaded_components', array( $this, 'return_array_containing_widgets' ), 10, 2 );
     340        $manager = new WP_Customize_Manager();
     341        $this->assertInstanceOf( 'WP_Customize_Widgets', $manager->widgets );
     342        $this->assertEmpty( $manager->nav_menus );
     343        remove_all_filters( 'customize_loaded_components' );
     344
     345        add_filter( 'customize_loaded_components', array( $this, 'return_array_containing_nav_menus' ), 10, 2 );
     346        $manager = new WP_Customize_Manager();
     347        $this->assertInstanceOf( 'WP_Customize_Nav_Menus', $manager->nav_menus );
     348        $this->assertEmpty( $manager->widgets );
     349        remove_all_filters( 'customize_loaded_components' );
     350
     351        add_filter( 'customize_loaded_components', '__return_empty_array' );
     352        $manager = new WP_Customize_Manager();
     353        $this->assertEmpty( $manager->widgets );
     354        $this->assertEmpty( $manager->nav_menus );
     355        remove_all_filters( 'customize_loaded_components' );
     356    }
     357
     358    /**
     359     * @see Tests_WP_Customize_Manager::test_customize_loaded_components_filter()
     360     *
     361     * @param array                $components         Components.
     362     * @param WP_Customize_Manager $customize_manager  Manager.
     363     *
     364     * @return array Components.
     365     */
     366    function return_array_containing_widgets( $components, $customize_manager ) {
     367        $this->assertInternalType( 'array', $components );
     368        $this->assertContains( 'widgets', $components );
     369        $this->assertContains( 'nav_menus', $components );
     370        $this->assertInternalType( 'array', $components );
     371        $this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
     372        return array( 'widgets' );
     373    }
     374
     375    /**
     376     * @see Tests_WP_Customize_Manager::test_customize_loaded_components_filter()
     377     *
     378     * @param array                $components         Components.
     379     * @param WP_Customize_Manager $customize_manager  Manager.
     380     *
     381     * @return array Components.
     382     */
     383    function return_array_containing_nav_menus( $components, $customize_manager ) {
     384        $this->assertInternalType( 'array', $components );
     385        $this->assertContains( 'widgets', $components );
     386        $this->assertContains( 'nav_menus', $components );
     387        $this->assertInternalType( 'array', $components );
     388        $this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
     389        return array( 'nav_menus' );
     390    }
    330391}
Note: See TracChangeset for help on using the changeset viewer.