Make WordPress Core

Ticket #30235: 30235.2.diff

File 30235.2.diff, 7.2 KB (added by westonruter, 9 years ago)

https://github.com/xwp/wordpress-develop/commit/9f422f5e254e00e42ae4c586cfcae83f33b40369

  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index ae38187..7b9f7b1 100644
     
    13481348                                        return;
    13491349                                }
    13501350
     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                                 */
    13511356                                var constructs = {
    13521357                                        panel: data.activePanels,
    13531358                                        section: data.activeSections,
    13541359                                        control: data.activeControls
    13551360                                };
    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                                        } );
    13661366                                } );
    1367 
    13681367                        } );
    13691368
    13701369                        this.request = $.ajax( this.previewUrl(), {
  • src/wp-admin/js/customize-widgets.js

    diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
    index 0c7c0fe..fb28d30 100644
     
    13681368        } );
    13691369
    13701370        /**
     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        /**
    13711412         * wp.customize.Widgets.SidebarControl
    13721413         *
    13731414         * Customizer control for widgets.
    13741415         * Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type
    13751416         *
     1417         * @since 3.9.0
     1418         *
    13761419         * @constructor
    13771420         * @augments wp.customize.Control
    13781421         */
     
    13951438                 * Update ordering of widget control forms when the setting is updated
    13961439                 */
    13971440                _setupModel: function() {
    1398                         var self = this,
    1399                                 registeredSidebar = api.Widgets.registeredSidebars.get( this.params.sidebar_id );
     1441                        var self = this;
    14001442
    14011443                        this.setting.bind( function( newWidgetIds, oldWidgetIds ) {
    14021444                                var widgetFormControls, removedWidgetIds, priority;
     
    14991541
    15001542                                } );
    15011543                        } );
    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() );
    15091544                },
    15101545
    15111546                /**
     
    18161851                }
    18171852        } );
    18181853
    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        });
    18231858        $.extend( api.controlConstructor, {
    18241859                widget_form: api.Widgets.WidgetControl,
    18251860                sidebar_widgets: api.Widgets.SidebarControl
  • src/wp-includes/class-wp-customize-control.php

    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 { 
    11151115                <?php
    11161116        }
    11171117
    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         }
    11291118}
    11301119
    11311120/**
  • src/wp-includes/class-wp-customize-manager.php

    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 { 
    515515                }
    516516                foreach ( $this->panels as $id => $panel ) {
    517517                        $settings['activePanels'][ $id ] = $panel->active();
     518                        foreach ( $panel->sections as $id => $section ) {
     519                                $settings['activeSections'][ $id ] = $section->active();
     520                        }
    518521                }
    519522                foreach ( $this->sections as $id => $section ) {
    520523                        $settings['activeSections'][ $id ] = $section->active();
  • src/wp-includes/class-wp-customize-section.php

    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 { 
    310310                <?php
    311311        }
    312312}
     313
     314/**
     315 * Customizer section representing widget area (sidebar).
     316 *
     317 * @package WordPress
     318 * @subpackage Customize
     319 * @since 4.1.0
     320 */
     321class 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}
  • src/wp-includes/class-wp-customize-widgets.php

    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 { 
    468468                                                'description' => $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['description'],
    469469                                                'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
    470470                                                'panel' => 'widgets',
     471                                                'sidebar_id' => $sidebar_id,
    471472                                        );
    472473
    473474                                        /**
    final class WP_Customize_Widgets { 
    481482                                         */
    482483                                        $section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id );
    483484
    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 );
    485487
    486488                                        $control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array(
    487489                                                'section'    => $section_id,