diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index ae38187..7b9f7b1 100644
|
|
|
|
| 1348 | 1348 | return; |
| 1349 | 1349 | } |
| 1350 | 1350 | |
| | 1351 | /* |
| | 1352 | * Walk over all panels, sections, and controls and set their |
| | 1353 | * respective active states to true if the preview explicitly |
| | 1354 | * indicates as such. |
| | 1355 | */ |
| 1351 | 1356 | var constructs = { |
| 1352 | 1357 | panel: data.activePanels, |
| 1353 | 1358 | section: data.activeSections, |
| 1354 | 1359 | control: data.activeControls |
| 1355 | 1360 | }; |
| 1356 | | |
| 1357 | | $.each( constructs, function ( type, activeConstructs ) { |
| 1358 | | if ( activeConstructs ) { |
| 1359 | | $.each( activeConstructs, function ( id, active ) { |
| 1360 | | var construct = api[ type ]( id ); |
| 1361 | | if ( construct ) { |
| 1362 | | construct.active( active ); |
| 1363 | | } |
| 1364 | | } ); |
| 1365 | | } |
| | 1361 | _( constructs ).each( function ( activeConstructs, type ) { |
| | 1362 | api[ type ].each( function ( construct, id ) { |
| | 1363 | var active = !! ( activeConstructs && activeConstructs[ id ] ); |
| | 1364 | construct.active( active ); |
| | 1365 | } ); |
| 1366 | 1366 | } ); |
| 1367 | | |
| 1368 | 1367 | } ); |
| 1369 | 1368 | |
| 1370 | 1369 | this.request = $.ajax( this.previewUrl(), { |
diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
index 0c7c0fe..fb28d30 100644
|
|
|
|
| 1368 | 1368 | } ); |
| 1369 | 1369 | |
| 1370 | 1370 | /** |
| | 1371 | * wp.customize.Widgets.SidebarSection |
| | 1372 | * |
| | 1373 | * Customizer section representing a widget area widget |
| | 1374 | * |
| | 1375 | * @since 4.1.0 |
| | 1376 | */ |
| | 1377 | api.Widgets.SidebarSection = api.Section.extend({ |
| | 1378 | |
| | 1379 | /** |
| | 1380 | * Sync the section's active state back to the Backbone model's is_rendered attribute |
| | 1381 | */ |
| | 1382 | ready: function () { |
| | 1383 | var section = this, registeredSidebar; |
| | 1384 | api.Section.prototype.ready.call( this ); |
| | 1385 | registeredSidebar = api.Widgets.registeredSidebars.get( section.params.sidebarId ); |
| | 1386 | section.active.bind( function ( active ) { |
| | 1387 | registeredSidebar.set( 'is_rendered', active ); |
| | 1388 | }); |
| | 1389 | registeredSidebar.set( 'is_rendered', section.active() ); |
| | 1390 | }, |
| | 1391 | |
| | 1392 | /** |
| | 1393 | * Override Section.isContextuallyActive() to skip considering |
| | 1394 | * SidebarControl as opposed to a WidgetControl. |
| | 1395 | * |
| | 1396 | * @returns {boolean} |
| | 1397 | */ |
| | 1398 | isContextuallyActive: function () { |
| | 1399 | var section, activeCount; |
| | 1400 | section = this; |
| | 1401 | activeCount = 0; |
| | 1402 | _( section.controls() ).each( function ( control ) { |
| | 1403 | if ( control.active() && ! control.extended( api.Widgets.SidebarControl ) ) { |
| | 1404 | activeCount += 1; |
| | 1405 | } |
| | 1406 | }); |
| | 1407 | return ( activeCount !== 0 ); |
| | 1408 | } |
| | 1409 | }); |
| | 1410 | |
| | 1411 | /** |
| 1371 | 1412 | * wp.customize.Widgets.SidebarControl |
| 1372 | 1413 | * |
| 1373 | 1414 | * Customizer control for widgets. |
| 1374 | 1415 | * Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type |
| 1375 | 1416 | * |
| | 1417 | * @since 3.9.0 |
| | 1418 | * |
| 1376 | 1419 | * @constructor |
| 1377 | 1420 | * @augments wp.customize.Control |
| 1378 | 1421 | */ |
| … |
… |
|
| 1395 | 1438 | * Update ordering of widget control forms when the setting is updated |
| 1396 | 1439 | */ |
| 1397 | 1440 | _setupModel: function() { |
| 1398 | | var self = this, |
| 1399 | | registeredSidebar = api.Widgets.registeredSidebars.get( this.params.sidebar_id ); |
| | 1441 | var self = this; |
| 1400 | 1442 | |
| 1401 | 1443 | this.setting.bind( function( newWidgetIds, oldWidgetIds ) { |
| 1402 | 1444 | var widgetFormControls, removedWidgetIds, priority; |
| … |
… |
|
| 1499 | 1541 | |
| 1500 | 1542 | } ); |
| 1501 | 1543 | } ); |
| 1502 | | |
| 1503 | | // Update the model with whether or not the sidebar is rendered |
| 1504 | | self.active.bind( function ( active ) { |
| 1505 | | registeredSidebar.set( 'is_rendered', active ); |
| 1506 | | api.section( self.section.get() ).active( active ); |
| 1507 | | } ); |
| 1508 | | api.section( self.section.get() ).active( self.active() ); |
| 1509 | 1544 | }, |
| 1510 | 1545 | |
| 1511 | 1546 | /** |
| … |
… |
|
| 1816 | 1851 | } |
| 1817 | 1852 | } ); |
| 1818 | 1853 | |
| 1819 | | /** |
| 1820 | | * Extends wp.customizer.controlConstructor with control constructor for |
| 1821 | | * widget_form and sidebar_widgets. |
| 1822 | | */ |
| | 1854 | // Register models for custom section and control types |
| | 1855 | $.extend( api.sectionConstructor, { |
| | 1856 | sidebar: api.Widgets.SidebarSection |
| | 1857 | }); |
| 1823 | 1858 | $.extend( api.controlConstructor, { |
| 1824 | 1859 | widget_form: api.Widgets.WidgetControl, |
| 1825 | 1860 | sidebar_widgets: api.Widgets.SidebarControl |
diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php
index 49dcdc1..57a3bdc 100644
|
|
|
class WP_Widget_Area_Customize_Control extends WP_Customize_Control { |
| 1115 | 1115 | <?php |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | | /** |
| 1119 | | * Whether the current sidebar is rendered on the page. |
| 1120 | | * |
| 1121 | | * @since 4.0.0 |
| 1122 | | * @access public |
| 1123 | | * |
| 1124 | | * @return bool Whether sidebar is rendered. |
| 1125 | | */ |
| 1126 | | public function active_callback() { |
| 1127 | | return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); |
| 1128 | | } |
| 1129 | 1118 | } |
| 1130 | 1119 | |
| 1131 | 1120 | /** |
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index 45ad34f..c3a8273 100644
|
|
|
final class WP_Customize_Manager { |
| 515 | 515 | } |
| 516 | 516 | foreach ( $this->panels as $id => $panel ) { |
| 517 | 517 | $settings['activePanels'][ $id ] = $panel->active(); |
| | 518 | foreach ( $panel->sections as $id => $section ) { |
| | 519 | $settings['activeSections'][ $id ] = $section->active(); |
| | 520 | } |
| 518 | 521 | } |
| 519 | 522 | foreach ( $this->sections as $id => $section ) { |
| 520 | 523 | $settings['activeSections'][ $id ] = $section->active(); |
diff --git src/wp-includes/class-wp-customize-section.php src/wp-includes/class-wp-customize-section.php
index 86c565d..8947f7d 100644
|
|
|
class WP_Customize_Section { |
| 310 | 310 | <?php |
| 311 | 311 | } |
| 312 | 312 | } |
| | 313 | |
| | 314 | /** |
| | 315 | * Customizer section representing widget area (sidebar). |
| | 316 | * |
| | 317 | * @package WordPress |
| | 318 | * @subpackage Customize |
| | 319 | * @since 4.1.0 |
| | 320 | */ |
| | 321 | class WP_Customize_Sidebar_Section extends WP_Customize_Section { |
| | 322 | |
| | 323 | /** |
| | 324 | * @var string |
| | 325 | */ |
| | 326 | public $type = 'sidebar'; |
| | 327 | |
| | 328 | /** |
| | 329 | * @var string |
| | 330 | */ |
| | 331 | public $sidebar_id; |
| | 332 | |
| | 333 | /** |
| | 334 | * @return array |
| | 335 | */ |
| | 336 | public function json() { |
| | 337 | $json = parent::json(); |
| | 338 | $json['sidebarId'] = $this->sidebar_id; |
| | 339 | return $json; |
| | 340 | } |
| | 341 | |
| | 342 | /** |
| | 343 | * Whether the current sidebar is rendered on the page. |
| | 344 | * |
| | 345 | * @since 4.0.0 |
| | 346 | * @access public |
| | 347 | * |
| | 348 | * @return bool Whether sidebar is rendered. |
| | 349 | */ |
| | 350 | public function active_callback() { |
| | 351 | return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); |
| | 352 | } |
| | 353 | } |
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, |