Make WordPress Core

Ticket #29758: 29758.2.diff

File 29758.2.diff, 10.0 KB (added by westonruter, 10 years ago)

https://github.com/xwpco/wordpress-develop/commit/1d2034b2205aa171e2c1d00c43749d002b42b244

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

    diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
    index a0688a7..31593ef 100644
    a b  
    8080                        bubbleChildValueChanges( self, [ 'priority', 'active' ] );
    8181
    8282                        self.priority.set( isNaN( self.params.priority ) ? 100 : self.params.priority );
    83                         self.active.set( true ); // @todo pass from params, eventually from active_callback when defining panel/section
     83                        self.active.set( self.params.active );
    8484                        self.expanded.set( false ); // @todo True if deeplinking?
    8585                },
    8686
     
    11011101                                loaded = false,
    11021102                                ready  = false;
    11031103
    1104                         if ( this._ready )
     1104                        if ( this._ready ) {
    11051105                                this.unbind( 'ready', this._ready );
     1106                        }
    11061107
    11071108                        this._ready = function() {
    11081109                                ready = true;
    11091110
    1110                                 if ( loaded )
     1111                                if ( loaded ) {
    11111112                                        deferred.resolveWith( self );
     1113                                }
    11121114                        };
    11131115
    11141116                        this.bind( 'ready', this._ready );
    11151117
    11161118                        this.bind( 'ready', function ( data ) {
    1117                                 if ( ! data || ! data.activeControls ) {
     1119                                if ( ! data ) {
    11181120                                        return;
    11191121                                }
    11201122
    1121                                 $.each( data.activeControls, function ( id, active ) {
    1122                                         var control = api.control( id );
    1123                                         if ( control ) {
    1124                                                 control.active( active );
     1123                                var constructs = {
     1124                                        panel: data.activePanels,
     1125                                        section: data.activeSections,
     1126                                        control: data.activeControls
     1127                                };
     1128
     1129                                $.each( constructs, function ( type, activeConstructs ) {
     1130                                        if ( activeConstructs ) {
     1131                                                $.each( activeConstructs, function ( id, active ) {
     1132                                                        var construct = api[ type ]( id );
     1133                                                        if ( construct ) {
     1134                                                                construct.active( active );
     1135                                                        }
     1136                                                } );
    11251137                                        }
    11261138                                } );
     1139
    11271140                        } );
    11281141
    11291142                        this.request = $.ajax( this.previewUrl(), {
     
    11451158
    11461159                                // Check if the location response header differs from the current URL.
    11471160                                // If so, the request was redirected; try loading the requested page.
    1148                                 if ( location && location != self.previewUrl() ) {
     1161                                if ( location && location !== self.previewUrl() ) {
    11491162                                        deferred.rejectWith( self, [ 'redirect', location ] );
    11501163                                        return;
    11511164                                }
  • src/wp-includes/class-wp-customize-manager.php

    diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php
    index 5041f82..ac70bdb 100644
    a b public function customize_preview_settings() { 
    491491                $settings = array(
    492492                        'values'  => array(),
    493493                        'channel' => wp_unslash( $_POST['customize_messenger_channel'] ),
     494                        'activePanels' => array(),
     495                        'activeSections' => array(),
    494496                        'activeControls' => array(),
    495497                );
    496498
    public function customize_preview_settings() { 
    504506                foreach ( $this->settings as $id => $setting ) {
    505507                        $settings['values'][ $id ] = $setting->js_value();
    506508                }
     509                foreach ( $this->panels as $id => $panel ) {
     510                        $settings['activePanels'][ $id ] = $panel->active();
     511                }
     512                foreach ( $this->sections as $id => $section ) {
     513                        $settings['activeSections'][ $id ] = $section->active();
     514                }
    507515                foreach ( $this->controls as $id => $control ) {
    508516                        $settings['activeControls'][ $id ] = $control->active();
    509517                }
  • src/wp-includes/class-wp-customize-panel.php

    diff --git a/src/wp-includes/class-wp-customize-panel.php b/src/wp-includes/class-wp-customize-panel.php
    index 9ba0295..201c4b9 100644
    a b class WP_Customize_Panel { 
    9090        public $type;
    9191
    9292        /**
     93         * Callback.
     94         *
     95         * @since 4.1.0
     96         * @access public
     97         *
     98         * @see WP_Customize_Section::active()
     99         *
     100         * @var callable Callback is called with one argument, the instance of
     101         *               WP_Customize_Section, and returns bool to indicate whether
     102         *               the section is active (such as it relates to the URL
     103         *               currently being previewed).
     104         */
     105        public $active_callback = '';
     106
     107        /**
    93108         * Constructor.
    94109         *
    95110         * Any supplied $args override class property defaults.
    public function __construct( $manager, $id, $args = array() ) { 
    110125
    111126                $this->manager = $manager;
    112127                $this->id = $id;
     128                if ( empty( $this->active_callback ) ) {
     129                        $this->active_callback = array( $this, 'active_callback' );
     130                }
    113131
    114132                $this->sections = array(); // Users cannot customize the $sections array.
    115133
    public function __construct( $manager, $id, $args = array() ) { 
    117135        }
    118136
    119137        /**
     138         * Check whether panel is active to current Customizer preview.
     139         *
     140         * @since 4.1.0
     141         * @access public
     142         *
     143         * @return bool Whether the panel is active to the current preview.
     144         */
     145        public final function active() {
     146                $panel = $this;
     147                $active = call_user_func( $this->active_callback, $this );
     148
     149                /**
     150                 * Filter response of WP_Customize_Panel::active().
     151                 *
     152                 * @since 4.1.0
     153                 *
     154                 * @param bool                 $active  Whether the Customizer panel is active.
     155                 * @param WP_Customize_Panel $panel WP_Customize_Panel instance.
     156                 */
     157                $active = apply_filters( 'customize_panel_active', $active, $panel );
     158
     159                return $active;
     160        }
     161
     162        /**
     163         * Default callback used when invoking WP_Customize_Panel::active().
     164         *
     165         * Subclasses can override this with their specific logic, or they may
     166         * provide an 'active_callback' argument to the constructor.
     167         *
     168         * @since 4.1.0
     169         * @access public
     170         *
     171         * @return bool Always true.
     172         */
     173        public function active_callback() {
     174                return true;
     175        }
     176
     177        /**
    120178         * Gather the parameters passed to client JavaScript via JSON.
    121179         *
    122180         * @since 4.1.0
    public function __construct( $manager, $id, $args = array() ) { 
    126184        public function json() {
    127185                $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) );
    128186                $array['content'] = $this->get_content();
     187                $array['active'] = $this->active();
    129188                return $array;
    130189        }
    131190
  • src/wp-includes/class-wp-customize-section.php

    diff --git a/src/wp-includes/class-wp-customize-section.php b/src/wp-includes/class-wp-customize-section.php
    index a905f32..3553285 100644
    a b class WP_Customize_Section { 
    9999        public $type;
    100100
    101101        /**
     102         * Callback.
     103         *
     104         * @since 4.1.0
     105         * @access public
     106         *
     107         * @see WP_Customize_Section::active()
     108         *
     109         * @var callable Callback is called with one argument, the instance of
     110         *               WP_Customize_Section, and returns bool to indicate whether
     111         *               the section is active (such as it relates to the URL
     112         *               currently being previewed).
     113         */
     114        public $active_callback = '';
     115
     116        /**
    102117         * Constructor.
    103118         *
    104119         * Any supplied $args override class property defaults.
    class WP_Customize_Section { 
    112127        public function __construct( $manager, $id, $args = array() ) {
    113128                $keys = array_keys( get_object_vars( $this ) );
    114129                foreach ( $keys as $key ) {
    115                         if ( isset( $args[ $key ] ) )
     130                        if ( isset( $args[ $key ] ) ) {
    116131                                $this->$key = $args[ $key ];
     132                        }
    117133                }
    118134
    119135                $this->manager = $manager;
    120136                $this->id = $id;
     137                if ( empty( $this->active_callback ) ) {
     138                        $this->active_callback = array( $this, 'active_callback' );
     139                }
    121140
    122141                $this->controls = array(); // Users cannot customize the $controls array.
    123142
    public function __construct( $manager, $id, $args = array() ) { 
    125144        }
    126145
    127146        /**
     147         * Check whether section is active to current Customizer preview.
     148         *
     149         * @since 4.1.0
     150         * @access public
     151         *
     152         * @return bool Whether the section is active to the current preview.
     153         */
     154        public final function active() {
     155                $section = $this;
     156                $active = call_user_func( $this->active_callback, $this );
     157
     158                /**
     159                 * Filter response of WP_Customize_Section::active().
     160                 *
     161                 * @since 4.1.0
     162                 *
     163                 * @param bool                 $active  Whether the Customizer section is active.
     164                 * @param WP_Customize_Section $section WP_Customize_Section instance.
     165                 */
     166                $active = apply_filters( 'customize_section_active', $active, $section );
     167
     168                return $active;
     169        }
     170
     171        /**
     172         * Default callback used when invoking WP_Customize_Section::active().
     173         *
     174         * Subclasses can override this with their specific logic, or they may
     175         * provide an 'active_callback' argument to the constructor.
     176         *
     177         * @since 4.1.0
     178         * @access public
     179         *
     180         * @return bool Always true.
     181         */
     182        public function active_callback() {
     183                return true;
     184        }
     185
     186        /**
    128187         * Gather the parameters passed to client JavaScript via JSON.
    129188         *
    130189         * @since 4.1.0
    public function __construct( $manager, $id, $args = array() ) { 
    134193        public function json() {
    135194                $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) );
    136195                $array['content'] = $this->get_content();
     196                $array['active'] = $this->active();
    137197                return $array;
    138198        }
    139199
    public function json() { 
    146206         * @return bool False if theme doesn't support the section or user doesn't have the capability.
    147207         */
    148208        public final function check_capabilities() {
    149                 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
     209                if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
    150210                        return false;
     211                }
    151212
    152                 if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
     213                if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
    153214                        return false;
     215                }
    154216
    155217                return true;
    156218        }
    public function json() { 
    176238         * @since 3.4.0
    177239         */
    178240        public final function maybe_render() {
    179                 if ( ! $this->check_capabilities() )
     241                if ( ! $this->check_capabilities() ) {
    180242                        return;
     243                }
    181244
    182245                /**
    183246                 * Fires before rendering a Customizer section.
  • src/wp-includes/js/customize-preview.js

    diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js
    index 6da26f4..1a82565 100644
    a b  
    107107        });
    108108
    109109                preview.send( 'ready', {
     110                        activePanels: api.settings.activePanels,
     111                        activeSections: api.settings.activeSections,
    110112                        activeControls: api.settings.activeControls
    111113                } );
    112114