diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 0ea60ce..7e42595 100644
|
|
|
1338 | 1338 | return; |
1339 | 1339 | } |
1340 | 1340 | |
| 1341 | /* |
| 1342 | * Walk over all panels, sections, and controls and set their |
| 1343 | * respective active states to true if the preview explicitly |
| 1344 | * indicates as such. |
| 1345 | */ |
1341 | 1346 | var constructs = { |
1342 | 1347 | panel: data.activePanels, |
1343 | 1348 | section: data.activeSections, |
1344 | 1349 | control: data.activeControls |
1345 | 1350 | }; |
1346 | | |
1347 | | $.each( constructs, function ( type, activeConstructs ) { |
1348 | | if ( activeConstructs ) { |
1349 | | $.each( activeConstructs, function ( id, active ) { |
1350 | | var construct = api[ type ]( id ); |
1351 | | if ( construct ) { |
1352 | | construct.active( active ); |
1353 | | } |
1354 | | } ); |
1355 | | } |
| 1351 | _( constructs ).each( function ( activeConstructs, type ) { |
| 1352 | api[ type ].each( function ( construct, id ) { |
| 1353 | var active = !! ( activeConstructs && activeConstructs[ id ] ); |
| 1354 | construct.active( active ); |
| 1355 | } ); |
1356 | 1356 | } ); |
1357 | | |
1358 | 1357 | } ); |
1359 | 1358 | |
1360 | 1359 | this.request = $.ajax( this.previewUrl(), { |
diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
index 3338f7b..a383c06 100644
|
|
|
1361 | 1361 | } ); |
1362 | 1362 | |
1363 | 1363 | /** |
| 1364 | * wp.customize.Widgets.SidebarSection |
| 1365 | * |
| 1366 | * Customizer section representing a widget area widget |
| 1367 | * |
| 1368 | * @since 4.1.0 |
| 1369 | */ |
| 1370 | api.Widgets.SidebarSection = api.Section.extend({ |
| 1371 | |
| 1372 | /** |
| 1373 | * Sync the section's active state back to the Backbone model's is_rendered attribute |
| 1374 | */ |
| 1375 | ready: function () { |
| 1376 | var section = this, registeredSidebar; |
| 1377 | api.Section.prototype.ready.call( this ); |
| 1378 | registeredSidebar = api.Widgets.registeredSidebars.get( section.params.sidebarId ); |
| 1379 | section.active.bind( function ( active ) { |
| 1380 | registeredSidebar.set( 'is_rendered', active ); |
| 1381 | }); |
| 1382 | registeredSidebar.set( 'is_rendered', section.active() ); |
| 1383 | }, |
| 1384 | |
| 1385 | /** |
| 1386 | * Override Section.isContextuallyActive() to skip considering |
| 1387 | * SidebarControl as opposed to a WidgetControl. |
| 1388 | * |
| 1389 | * @returns {boolean} |
| 1390 | */ |
| 1391 | isContextuallyActive: function () { |
| 1392 | var section, activeCount; |
| 1393 | section = this; |
| 1394 | activeCount = 0; |
| 1395 | _( section.controls() ).each( function ( control ) { |
| 1396 | if ( control.active() && ! control.extended( api.Widgets.SidebarControl ) ) { |
| 1397 | activeCount += 1; |
| 1398 | } |
| 1399 | }); |
| 1400 | return ( activeCount !== 0 ); |
| 1401 | } |
| 1402 | }); |
| 1403 | |
| 1404 | /** |
1364 | 1405 | * wp.customize.Widgets.SidebarControl |
1365 | 1406 | * |
1366 | 1407 | * Customizer control for widgets. |
1367 | 1408 | * Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type |
1368 | 1409 | * |
| 1410 | * @since 3.9.0 |
| 1411 | * |
1369 | 1412 | * @constructor |
1370 | 1413 | * @augments wp.customize.Control |
1371 | 1414 | */ |
… |
… |
|
1388 | 1431 | * Update ordering of widget control forms when the setting is updated |
1389 | 1432 | */ |
1390 | 1433 | _setupModel: function() { |
1391 | | var self = this, |
1392 | | registeredSidebar = api.Widgets.registeredSidebars.get( this.params.sidebar_id ); |
| 1434 | var self = this; |
1393 | 1435 | |
1394 | 1436 | this.setting.bind( function( newWidgetIds, oldWidgetIds ) { |
1395 | 1437 | var widgetFormControls, removedWidgetIds, priority; |
… |
… |
|
1492 | 1534 | |
1493 | 1535 | } ); |
1494 | 1536 | } ); |
1495 | | |
1496 | | // Update the model with whether or not the sidebar is rendered |
1497 | | self.active.bind( function ( active ) { |
1498 | | registeredSidebar.set( 'is_rendered', active ); |
1499 | | api.section( self.section.get() ).active( active ); |
1500 | | } ); |
1501 | | api.section( self.section.get() ).active( self.active() ); |
1502 | 1537 | }, |
1503 | 1538 | |
1504 | 1539 | /** |
… |
… |
|
1811 | 1846 | } |
1812 | 1847 | } ); |
1813 | 1848 | |
1814 | | /** |
1815 | | * Extends wp.customizer.controlConstructor with control constructor for |
1816 | | * widget_form and sidebar_widgets. |
1817 | | */ |
| 1849 | // Register models for custom section and control types |
| 1850 | $.extend( api.sectionConstructor, { |
| 1851 | sidebar: api.Widgets.SidebarSection |
| 1852 | }); |
1818 | 1853 | $.extend( api.controlConstructor, { |
1819 | 1854 | widget_form: api.Widgets.WidgetControl, |
1820 | 1855 | sidebar_widgets: api.Widgets.SidebarControl |
diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php
index 2130f0c..7bd8a6e 100644
|
|
class WP_Widget_Area_Customize_Control extends WP_Customize_Control { |
1133 | 1133 | <?php |
1134 | 1134 | } |
1135 | 1135 | |
1136 | | /** |
1137 | | * Whether the current sidebar is rendered on the page. |
1138 | | * |
1139 | | * @since 4.0.0 |
1140 | | * @access public |
1141 | | * |
1142 | | * @return bool Whether sidebar is rendered. |
1143 | | */ |
1144 | | public function active_callback() { |
1145 | | return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); |
1146 | | } |
1147 | 1136 | } |
1148 | 1137 | |
1149 | 1138 | /** |
diff --git src/wp-includes/class-wp-customize-section.php src/wp-includes/class-wp-customize-section.php
index 3553285..120eeaa 100644
|
|
class WP_Customize_Section { |
287 | 287 | <?php |
288 | 288 | } |
289 | 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Customizer section representing widget area (sidebar). |
| 293 | * |
| 294 | * @package WordPress |
| 295 | * @subpackage Customize |
| 296 | * @since 4.1.0 |
| 297 | */ |
| 298 | class WP_Customize_Sidebar_Section extends WP_Customize_Section { |
| 299 | |
| 300 | /** |
| 301 | * @var string |
| 302 | */ |
| 303 | public $type = 'sidebar'; |
| 304 | |
| 305 | /** |
| 306 | * @var string |
| 307 | */ |
| 308 | public $sidebar_id; |
| 309 | |
| 310 | /** |
| 311 | * @return array |
| 312 | */ |
| 313 | public function json() { |
| 314 | $json = parent::json(); |
| 315 | $json['sidebarId'] = $this->sidebar_id; |
| 316 | return $json; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Whether the current sidebar is rendered on the page. |
| 321 | * |
| 322 | * @since 4.0.0 |
| 323 | * @access public |
| 324 | * |
| 325 | * @return bool Whether sidebar is rendered. |
| 326 | */ |
| 327 | public function active_callback() { |
| 328 | return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); |
| 329 | } |
| 330 | } |
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php
index fe5afd9..04bcce6 100644
|
|
final class WP_Customize_Widgets { |
468 | 468 | 'description' => $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['description'], |
469 | 469 | 'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ), |
470 | 470 | 'panel' => 'widgets', |
| 471 | 'sidebar_id' => $sidebar_id, |
471 | 472 | ); |
472 | 473 | |
473 | 474 | /** |
… |
… |
final class WP_Customize_Widgets { |
481 | 482 | */ |
482 | 483 | $section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id ); |
483 | 484 | |
484 | | $this->manager->add_section( $section_id, $section_args ); |
| 485 | $section = new WP_Customize_Sidebar_Section( $this->manager, $section_id, $section_args ); |
| 486 | $this->manager->add_section( $section ); |
485 | 487 | |
486 | 488 | $control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array( |
487 | 489 | 'section' => $section_id, |