Make WordPress Core


Ignore:
Timestamp:
09/20/2016 12:46:54 AM (10 years ago)
Author:
westonruter
Message:

Customize: Let static_front_page section be contextually active based on whether there are any published pages.

If there are no pages when the customizer is opened, the static_front_page section will be hidden. As soon as a page is created in the customizer session, the static_front_page section will be revealed. Previously the section would not be registered if there were no pages. Page stubs created via nav menus will appear in the dropdown-pages controls for page_for_posts and page_on_front, and such page stubs will thus cause the static_front_page section to appear. Plugins that facilitate page creation in the customizer by filtering get_pages will also cause the section to appear.

See #34923.
Fixes #38013.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r38513 r38624  
    400400
    401401        /**
     402         * Test WP_Customize_Manager::has_published_pages().
     403         *
     404         * @ticket 38013
     405         * @covers WP_Customize_Manager::has_published_pages()
     406         */
     407        function test_has_published_pages() {
     408                foreach ( get_pages() as $page ) {
     409                        wp_delete_post( $page->ID, true );
     410                }
     411                $this->assertFalse( $this->manager->has_published_pages() );
     412
     413                $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'private' ) );
     414                $this->assertFalse( $this->manager->has_published_pages() );
     415
     416                $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'publish' ) );
     417                $this->assertTrue( $this->manager->has_published_pages() );
     418        }
     419
     420        /**
     421         * Ensure that page stubs created via nav menus will cause has_published_pages to return true.
     422         *
     423         * @ticket 38013
     424         * @covers WP_Customize_Manager::has_published_pages()
     425         */
     426        function test_has_published_pages_when_nav_menus_created_posts() {
     427                foreach ( get_pages() as $page ) {
     428                        wp_delete_post( $page->ID, true );
     429                }
     430                $this->assertFalse( $this->manager->has_published_pages() );
     431
     432                wp_set_current_user( $this->factory()->user->create( array( 'role' => 'editor' ) ) );
     433                $this->manager->nav_menus->customize_register();
     434                $setting_id = 'nav_menus_created_posts';
     435                $setting = $this->manager->get_setting( $setting_id );
     436                $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting );
     437                $auto_draft_page = $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'auto-draft' ) );
     438                $this->manager->set_post_value( $setting_id, array( $auto_draft_page ) );
     439                $setting->preview();
     440                $this->assertTrue( $this->manager->has_published_pages() );
     441        }
     442
     443        /**
    402444         * Test the WP_Customize_Manager::register_dynamic_settings() method.
    403445         *
Note: See TracChangeset for help on using the changeset viewer.