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.


git-svn-id: https://develop.svn.wordpress.org/trunk@38624 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2016-09-20 00:46:54 +00:00
parent 849c5de6d5
commit 7079459b77
4 changed files with 138 additions and 49 deletions
+42
View File
@@ -398,6 +398,48 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertEquals( 'dynamic_bar_default', $manager->get_setting( 'bar' )->default, 'Expected dynamic setting bar to have default providd by filter.' );
}
/**
* Test WP_Customize_Manager::has_published_pages().
*
* @ticket 38013
* @covers WP_Customize_Manager::has_published_pages()
*/
function test_has_published_pages() {
foreach ( get_pages() as $page ) {
wp_delete_post( $page->ID, true );
}
$this->assertFalse( $this->manager->has_published_pages() );
$this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'private' ) );
$this->assertFalse( $this->manager->has_published_pages() );
$this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'publish' ) );
$this->assertTrue( $this->manager->has_published_pages() );
}
/**
* Ensure that page stubs created via nav menus will cause has_published_pages to return true.
*
* @ticket 38013
* @covers WP_Customize_Manager::has_published_pages()
*/
function test_has_published_pages_when_nav_menus_created_posts() {
foreach ( get_pages() as $page ) {
wp_delete_post( $page->ID, true );
}
$this->assertFalse( $this->manager->has_published_pages() );
wp_set_current_user( $this->factory()->user->create( array( 'role' => 'editor' ) ) );
$this->manager->nav_menus->customize_register();
$setting_id = 'nav_menus_created_posts';
$setting = $this->manager->get_setting( $setting_id );
$this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting );
$auto_draft_page = $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'auto-draft' ) );
$this->manager->set_post_value( $setting_id, array( $auto_draft_page ) );
$setting->preview();
$this->assertTrue( $this->manager->has_published_pages() );
}
/**
* Test the WP_Customize_Manager::register_dynamic_settings() method.
*