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. Built from https://develop.svn.wordpress.org/trunk@38624 git-svn-id: http://core.svn.wordpress.org/trunk@38567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
94ff5710ce
commit
d84c343cc6
|
@ -104,6 +104,23 @@
|
|||
deferred.resolve( response );
|
||||
api.Menus.insertedAutoDrafts.push( response.post_id );
|
||||
api( 'nav_menus_created_posts' ).set( _.clone( api.Menus.insertedAutoDrafts ) );
|
||||
|
||||
if ( 'page' === params.post_type ) {
|
||||
|
||||
// Activate static front page controls as this could be the first page created.
|
||||
if ( api.section.has( 'static_front_page' ) ) {
|
||||
api.section( 'static_front_page' ).activate();
|
||||
}
|
||||
|
||||
// Add new page to dropdown-pages controls.
|
||||
api.control.each( function( control ) {
|
||||
var select;
|
||||
if ( 'dropdown-pages' === control.params.type ) {
|
||||
select = control.container.find( 'select[name^="_customize-dropdown-pages-"]' );
|
||||
select.append( new Option( params.post_title, response.post_id ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -533,15 +533,24 @@ class WP_Customize_Control {
|
|||
<span class="description customize-control-description"><?php echo $this->description; ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $dropdown = wp_dropdown_pages(
|
||||
<?php
|
||||
$dropdown_name = '_customize-dropdown-pages-' . $this->id;
|
||||
$show_option_none = __( '— Select —' );
|
||||
$option_none_value = '0';
|
||||
$dropdown = wp_dropdown_pages(
|
||||
array(
|
||||
'name' => '_customize-dropdown-pages-' . $this->id,
|
||||
'name' => $dropdown_name,
|
||||
'echo' => 0,
|
||||
'show_option_none' => __( '— Select —' ),
|
||||
'option_none_value' => '0',
|
||||
'show_option_none' => $show_option_none,
|
||||
'option_none_value' => $option_none_value,
|
||||
'selected' => $this->value(),
|
||||
)
|
||||
);
|
||||
if ( empty( $dropdown ) ) {
|
||||
$dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) );
|
||||
$dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
|
||||
$dropdown .= '</select>';
|
||||
}
|
||||
|
||||
// Hackily add in the data link parameter.
|
||||
$dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
|
||||
|
|
|
@ -2254,23 +2254,23 @@ final class WP_Customize_Manager {
|
|||
}
|
||||
}
|
||||
|
||||
/* Static Front Page */
|
||||
// #WP19627
|
||||
/*
|
||||
* Static Front Page
|
||||
* See also https://core.trac.wordpress.org/ticket/19627 which introduces the the static-front-page theme_support.
|
||||
* The following replicates behavior from options-reading.php.
|
||||
*/
|
||||
|
||||
// Replicate behavior from options-reading.php and hide front page options if there are no pages
|
||||
if ( get_pages() ) {
|
||||
$this->add_section( 'static_front_page', array(
|
||||
'title' => __( 'Static Front Page' ),
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
'priority' => 120,
|
||||
'description' => __( 'Your theme supports a static front page.' ),
|
||||
'active_callback' => array( $this, 'has_published_pages' ),
|
||||
) );
|
||||
|
||||
$this->add_setting( 'show_on_front', array(
|
||||
'default' => get_option( 'show_on_front' ),
|
||||
'capability' => 'manage_options',
|
||||
'type' => 'option',
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
) );
|
||||
|
||||
$this->add_control( 'show_on_front', array(
|
||||
|
@ -2286,7 +2286,6 @@ final class WP_Customize_Manager {
|
|||
$this->add_setting( 'page_on_front', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
) );
|
||||
|
||||
$this->add_control( 'page_on_front', array(
|
||||
|
@ -2298,7 +2297,6 @@ final class WP_Customize_Manager {
|
|||
$this->add_setting( 'page_for_posts', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
) );
|
||||
|
||||
$this->add_control( 'page_for_posts', array(
|
||||
|
@ -2307,6 +2305,29 @@ final class WP_Customize_Manager {
|
|||
'type' => 'dropdown-pages',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether there are published pages.
|
||||
*
|
||||
* Used as active callback for static front page section and controls.
|
||||
*
|
||||
* @access private
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @returns bool Whether there are published (or to be published) pages.
|
||||
*/
|
||||
public function has_published_pages() {
|
||||
|
||||
$setting = $this->get_setting( 'nav_menus_created_posts' );
|
||||
if ( $setting ) {
|
||||
foreach ( $setting->value() as $post_id ) {
|
||||
if ( 'page' === get_post_type( $post_id ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0 !== count( get_pages() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-alpha-38623';
|
||||
$wp_version = '4.7-alpha-38624';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue