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/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.