Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Let static_front_page section be contextual instead of controls #275

Merged
merged 2 commits into from
Sep 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@
return;
}

// 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( api.Posts.data.l10n.noTitle, data.postId ) );
}
} );
if ( api.section.has( 'static_front_page' ) ) {
api.section( 'static_front_page' ).activate();
}

deferred.resolve( {
postId: data.postId,
section: section,
Expand Down
24 changes: 6 additions & 18 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ public function ensure_static_front_page_constructs_registered( WP_Customize_Man
'type' => 'option',
) );
}
$control = $wp_customize->get_control( 'show_on_front' );
if ( ! $control ) {
$control = $wp_customize->add_control( 'show_on_front', array(
if ( ! $wp_customize->get_control( 'show_on_front' ) ) {
$wp_customize->add_control( 'show_on_front', array(
'label' => __( 'Front page displays', 'default' ),
'section' => 'static_front_page',
'type' => 'radio',
Expand All @@ -324,9 +323,6 @@ public function ensure_static_front_page_constructs_registered( WP_Customize_Man
),
) );
}
if ( array( $control, 'active_callback' ) === $control->active_callback ) {
$control->active_callback = array( $this, 'has_published_pages' );
}

// Page on Front.
if ( ! $wp_customize->get_setting( 'page_on_front' ) ) {
Expand All @@ -335,17 +331,13 @@ public function ensure_static_front_page_constructs_registered( WP_Customize_Man
'capability' => 'manage_options',
) );
}
$control = $wp_customize->get_control( 'page_on_front' );
if ( ! $control ) {
$control = $wp_customize->add_control( 'page_on_front', array(
if ( ! $wp_customize->get_control( 'page_on_front' ) ) {
$wp_customize->add_control( 'page_on_front', array(
'label' => __( 'Front page', 'default' ),
'section' => 'static_front_page',
'type' => 'dropdown-pages',
) );
}
if ( array( $control, 'active_callback' ) === $control->active_callback ) {
$control->active_callback = array( $this, 'has_published_pages' );
}

// Page for Posts.
if ( ! $wp_customize->get_setting( 'page_for_posts' ) ) {
Expand All @@ -354,17 +346,13 @@ public function ensure_static_front_page_constructs_registered( WP_Customize_Man
'capability' => 'manage_options',
) );
}
$control = $wp_customize->get_control( 'page_for_posts' );
if ( ! $control ) {
$control = $wp_customize->add_control( 'page_for_posts', array(
if ( ! $wp_customize->get_control( 'page_for_posts' ) ) {
$wp_customize->add_control( 'page_for_posts', array(
'label' => __( 'Posts page', 'default' ),
'section' => 'static_front_page',
'type' => 'dropdown-pages',
) );
}
if ( array( $control, 'active_callback' ) === $control->active_callback ) {
$control->active_callback = array( $this, 'has_published_pages' );
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/php/test-class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ public function test_ensure_static_front_page_constructs_registered() {
$this->do_customize_boot_actions();
$section = $this->wp_customize->get_section( 'static_front_page' );
$this->assertInstanceOf( 'WP_Customize_Section', $section );
$this->assertEquals( array( $this->posts, 'has_published_pages' ), $section->active_callback );
if ( $section->active_callback !== array( $this->wp_customize, 'has_published_pages' ) ) { // Forward-compat, see WP Core Trac #38013.
$this->assertEquals( array( $this->posts, 'has_published_pages' ), $section->active_callback );
}

$section->active_callback = array( $section, 'active_callback' ); // Reset to default.
$this->posts->ensure_static_front_page_constructs_registered( $this->wp_customize );
Expand Down