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. Built from https://develop.svn.wordpress.org/trunk@30329 git-svn-id: http://core.svn.wordpress.org/trunk@30328 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
92e3890daa
commit
41197a7c31
|
@ -1348,23 +1348,22 @@
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk over all panels, sections, and controls and set their
|
||||
* respective active states to true if the preview explicitly
|
||||
* indicates as such.
|
||||
*/
|
||||
var constructs = {
|
||||
panel: data.activePanels,
|
||||
section: data.activeSections,
|
||||
control: data.activeControls
|
||||
};
|
||||
|
||||
$.each( constructs, function ( type, activeConstructs ) {
|
||||
if ( activeConstructs ) {
|
||||
$.each( activeConstructs, function ( id, active ) {
|
||||
var construct = api[ type ]( id );
|
||||
if ( construct ) {
|
||||
_( constructs ).each( function ( activeConstructs, type ) {
|
||||
api[ type ].each( function ( construct, id ) {
|
||||
var active = !! ( activeConstructs && activeConstructs[ id ] );
|
||||
construct.active( active );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
||||
|
||||
this.request = $.ajax( this.previewUrl(), {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1367,12 +1367,55 @@
|
|||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* wp.customize.Widgets.SidebarSection
|
||||
*
|
||||
* Customizer section representing a widget area widget
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
api.Widgets.SidebarSection = api.Section.extend({
|
||||
|
||||
/**
|
||||
* Sync the section's active state back to the Backbone model's is_rendered attribute
|
||||
*/
|
||||
ready: function () {
|
||||
var section = this, registeredSidebar;
|
||||
api.Section.prototype.ready.call( this );
|
||||
registeredSidebar = api.Widgets.registeredSidebars.get( section.params.sidebarId );
|
||||
section.active.bind( function ( active ) {
|
||||
registeredSidebar.set( 'is_rendered', active );
|
||||
});
|
||||
registeredSidebar.set( 'is_rendered', section.active() );
|
||||
},
|
||||
|
||||
/**
|
||||
* Override Section.isContextuallyActive() to skip considering
|
||||
* SidebarControl as opposed to a WidgetControl.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isContextuallyActive: function () {
|
||||
var section, activeCount;
|
||||
section = this;
|
||||
activeCount = 0;
|
||||
_( section.controls() ).each( function ( control ) {
|
||||
if ( control.active() && ! control.extended( api.Widgets.SidebarControl ) ) {
|
||||
activeCount += 1;
|
||||
}
|
||||
});
|
||||
return ( activeCount !== 0 );
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* wp.customize.Widgets.SidebarControl
|
||||
*
|
||||
* Customizer control for widgets.
|
||||
* Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @constructor
|
||||
* @augments wp.customize.Control
|
||||
*/
|
||||
|
@ -1395,8 +1438,7 @@
|
|||
* Update ordering of widget control forms when the setting is updated
|
||||
*/
|
||||
_setupModel: function() {
|
||||
var self = this,
|
||||
registeredSidebar = api.Widgets.registeredSidebars.get( this.params.sidebar_id );
|
||||
var self = this;
|
||||
|
||||
this.setting.bind( function( newWidgetIds, oldWidgetIds ) {
|
||||
var widgetFormControls, removedWidgetIds, priority;
|
||||
|
@ -1499,13 +1541,6 @@
|
|||
|
||||
} );
|
||||
} );
|
||||
|
||||
// Update the model with whether or not the sidebar is rendered
|
||||
self.active.bind( function ( active ) {
|
||||
registeredSidebar.set( 'is_rendered', active );
|
||||
api.section( self.section.get() ).active( active );
|
||||
} );
|
||||
api.section( self.section.get() ).active( self.active() );
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1816,10 +1851,10 @@
|
|||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* Extends wp.customizer.controlConstructor with control constructor for
|
||||
* widget_form and sidebar_widgets.
|
||||
*/
|
||||
// Register models for custom section and control types
|
||||
$.extend( api.sectionConstructor, {
|
||||
sidebar: api.Widgets.SidebarSection
|
||||
});
|
||||
$.extend( api.controlConstructor, {
|
||||
widget_form: api.Widgets.WidgetControl,
|
||||
sidebar_widgets: api.Widgets.SidebarControl
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.1-alpha-30328';
|
||||
$wp_version = '4.1-alpha-30329';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue