Customizer: Improve ability to filter active state for widget area Customizer sections.

* Mark panels, sections, controls as active if preview explicitly indicates.
* Introduce `WP_Customize_Sidebar_Section` PHP class, and `SidebarSection` JS class.
* Move logic for determining whether a sidebar section is active from the `SidebarControl` to `SidebarSection`.

props westonruter.
fixes #30235.

git-svn-id: https://develop.svn.wordpress.org/trunk@30329 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2014-11-13 12:18:01 +00:00
parent 2a941720be
commit 8d476eee4f
6 changed files with 115 additions and 36 deletions
@@ -1115,17 +1115,6 @@ class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
<?php
}
/**
* Whether the current sidebar is rendered on the page.
*
* @since 4.0.0
* @access public
*
* @return bool Whether sidebar is rendered.
*/
public function active_callback() {
return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
}
}
/**
@@ -515,6 +515,9 @@ final class WP_Customize_Manager {
}
foreach ( $this->panels as $id => $panel ) {
$settings['activePanels'][ $id ] = $panel->active();
foreach ( $panel->sections as $id => $section ) {
$settings['activeSections'][ $id ] = $section->active();
}
}
foreach ( $this->sections as $id => $section ) {
$settings['activeSections'][ $id ] = $section->active();
@@ -310,3 +310,54 @@ class WP_Customize_Section {
<?php
}
}
/**
* Customizer section representing widget area (sidebar).
*
* @package WordPress
* @subpackage Customize
* @since 4.1.0
*/
class WP_Customize_Sidebar_Section extends WP_Customize_Section {
/**
* @since 4.1.0
* @access public
* @var string
*/
public $type = 'sidebar';
/**
* Unique identifier.
*
* @since 4.1.0
* @access public
* @var string
*/
public $sidebar_id;
/**
* Gather the parameters passed to client JavaScript via JSON.
*
* @since 4.1.0
*
* @return array The array to be exported to the client as JSON
*/
public function json() {
$json = parent::json();
$json['sidebarId'] = $this->sidebar_id;
return $json;
}
/**
* Whether the current sidebar is rendered on the page.
*
* @since 4.1.0
* @access public
*
* @return bool Whether sidebar is rendered.
*/
public function active_callback() {
return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
}
}
@@ -468,6 +468,7 @@ final class WP_Customize_Widgets {
'description' => $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['description'],
'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
'panel' => 'widgets',
'sidebar_id' => $sidebar_id,
);
/**
@@ -481,7 +482,8 @@ final class WP_Customize_Widgets {
*/
$section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id );
$this->manager->add_section( $section_id, $section_args );
$section = new WP_Customize_Sidebar_Section( $this->manager, $section_id, $section_args );
$this->manager->add_section( $section );
$control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array(
'section' => $section_id,