mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-05 15:16:59 +00:00
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:
@@ -2254,59 +2254,80 @@ 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.' ),
|
||||
) );
|
||||
$this->add_section( 'static_front_page', array(
|
||||
'title' => __( '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_setting( 'show_on_front', array(
|
||||
'default' => get_option( 'show_on_front' ),
|
||||
'capability' => 'manage_options',
|
||||
'type' => 'option',
|
||||
) );
|
||||
|
||||
$this->add_control( 'show_on_front', array(
|
||||
'label' => __( 'Front page displays' ),
|
||||
'section' => 'static_front_page',
|
||||
'type' => 'radio',
|
||||
'choices' => array(
|
||||
'posts' => __( 'Your latest posts' ),
|
||||
'page' => __( 'A static page' ),
|
||||
),
|
||||
) );
|
||||
$this->add_control( 'show_on_front', array(
|
||||
'label' => __( 'Front page displays' ),
|
||||
'section' => 'static_front_page',
|
||||
'type' => 'radio',
|
||||
'choices' => array(
|
||||
'posts' => __( 'Your latest posts' ),
|
||||
'page' => __( 'A static page' ),
|
||||
),
|
||||
) );
|
||||
|
||||
$this->add_setting( 'page_on_front', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
) );
|
||||
$this->add_setting( 'page_on_front', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
) );
|
||||
|
||||
$this->add_control( 'page_on_front', array(
|
||||
'label' => __( 'Front page' ),
|
||||
'section' => 'static_front_page',
|
||||
'type' => 'dropdown-pages',
|
||||
) );
|
||||
$this->add_control( 'page_on_front', array(
|
||||
'label' => __( 'Front page' ),
|
||||
'section' => 'static_front_page',
|
||||
'type' => 'dropdown-pages',
|
||||
) );
|
||||
|
||||
$this->add_setting( 'page_for_posts', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
// 'theme_supports' => 'static-front-page',
|
||||
) );
|
||||
$this->add_setting( 'page_for_posts', array(
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_options',
|
||||
) );
|
||||
|
||||
$this->add_control( 'page_for_posts', array(
|
||||
'label' => __( 'Posts page' ),
|
||||
'section' => 'static_front_page',
|
||||
'type' => 'dropdown-pages',
|
||||
) );
|
||||
$this->add_control( 'page_for_posts', array(
|
||||
'label' => __( 'Posts page' ),
|
||||
'section' => 'static_front_page',
|
||||
'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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user