diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index a0688a7..31593ef 100644
a
|
b
|
|
80 | 80 | bubbleChildValueChanges( self, [ 'priority', 'active' ] ); |
81 | 81 | |
82 | 82 | 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 ); |
84 | 84 | self.expanded.set( false ); // @todo True if deeplinking? |
85 | 85 | }, |
86 | 86 | |
… |
… |
|
1101 | 1101 | loaded = false, |
1102 | 1102 | ready = false; |
1103 | 1103 | |
1104 | | if ( this._ready ) |
| 1104 | if ( this._ready ) { |
1105 | 1105 | this.unbind( 'ready', this._ready ); |
| 1106 | } |
1106 | 1107 | |
1107 | 1108 | this._ready = function() { |
1108 | 1109 | ready = true; |
1109 | 1110 | |
1110 | | if ( loaded ) |
| 1111 | if ( loaded ) { |
1111 | 1112 | deferred.resolveWith( self ); |
| 1113 | } |
1112 | 1114 | }; |
1113 | 1115 | |
1114 | 1116 | this.bind( 'ready', this._ready ); |
1115 | 1117 | |
1116 | 1118 | this.bind( 'ready', function ( data ) { |
1117 | | if ( ! data || ! data.activeControls ) { |
| 1119 | if ( ! data ) { |
1118 | 1120 | return; |
1119 | 1121 | } |
1120 | 1122 | |
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 | } ); |
1125 | 1137 | } |
1126 | 1138 | } ); |
| 1139 | |
1127 | 1140 | } ); |
1128 | 1141 | |
1129 | 1142 | this.request = $.ajax( this.previewUrl(), { |
… |
… |
|
1145 | 1158 | |
1146 | 1159 | // Check if the location response header differs from the current URL. |
1147 | 1160 | // If so, the request was redirected; try loading the requested page. |
1148 | | if ( location && location != self.previewUrl() ) { |
| 1161 | if ( location && location !== self.previewUrl() ) { |
1149 | 1162 | deferred.rejectWith( self, [ 'redirect', location ] ); |
1150 | 1163 | return; |
1151 | 1164 | } |
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() { |
491 | 491 | $settings = array( |
492 | 492 | 'values' => array(), |
493 | 493 | 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), |
| 494 | 'activePanels' => array(), |
| 495 | 'activeSections' => array(), |
494 | 496 | 'activeControls' => array(), |
495 | 497 | ); |
496 | 498 | |
… |
… |
public function customize_preview_settings() { |
504 | 506 | foreach ( $this->settings as $id => $setting ) { |
505 | 507 | $settings['values'][ $id ] = $setting->js_value(); |
506 | 508 | } |
| 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 | } |
507 | 515 | foreach ( $this->controls as $id => $control ) { |
508 | 516 | $settings['activeControls'][ $id ] = $control->active(); |
509 | 517 | } |
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 { |
90 | 90 | public $type; |
91 | 91 | |
92 | 92 | /** |
| 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 | /** |
93 | 108 | * Constructor. |
94 | 109 | * |
95 | 110 | * Any supplied $args override class property defaults. |
… |
… |
public function __construct( $manager, $id, $args = array() ) { |
110 | 125 | |
111 | 126 | $this->manager = $manager; |
112 | 127 | $this->id = $id; |
| 128 | if ( empty( $this->active_callback ) ) { |
| 129 | $this->active_callback = array( $this, 'active_callback' ); |
| 130 | } |
113 | 131 | |
114 | 132 | $this->sections = array(); // Users cannot customize the $sections array. |
115 | 133 | |
… |
… |
public function __construct( $manager, $id, $args = array() ) { |
117 | 135 | } |
118 | 136 | |
119 | 137 | /** |
| 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 | /** |
120 | 178 | * Gather the parameters passed to client JavaScript via JSON. |
121 | 179 | * |
122 | 180 | * @since 4.1.0 |
… |
… |
public function __construct( $manager, $id, $args = array() ) { |
126 | 184 | public function json() { |
127 | 185 | $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) ); |
128 | 186 | $array['content'] = $this->get_content(); |
| 187 | $array['active'] = $this->active(); |
129 | 188 | return $array; |
130 | 189 | } |
131 | 190 | |
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 { |
99 | 99 | public $type; |
100 | 100 | |
101 | 101 | /** |
| 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 | /** |
102 | 117 | * Constructor. |
103 | 118 | * |
104 | 119 | * Any supplied $args override class property defaults. |
… |
… |
class WP_Customize_Section { |
112 | 127 | public function __construct( $manager, $id, $args = array() ) { |
113 | 128 | $keys = array_keys( get_object_vars( $this ) ); |
114 | 129 | foreach ( $keys as $key ) { |
115 | | if ( isset( $args[ $key ] ) ) |
| 130 | if ( isset( $args[ $key ] ) ) { |
116 | 131 | $this->$key = $args[ $key ]; |
| 132 | } |
117 | 133 | } |
118 | 134 | |
119 | 135 | $this->manager = $manager; |
120 | 136 | $this->id = $id; |
| 137 | if ( empty( $this->active_callback ) ) { |
| 138 | $this->active_callback = array( $this, 'active_callback' ); |
| 139 | } |
121 | 140 | |
122 | 141 | $this->controls = array(); // Users cannot customize the $controls array. |
123 | 142 | |
… |
… |
public function __construct( $manager, $id, $args = array() ) { |
125 | 144 | } |
126 | 145 | |
127 | 146 | /** |
| 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 | /** |
128 | 187 | * Gather the parameters passed to client JavaScript via JSON. |
129 | 188 | * |
130 | 189 | * @since 4.1.0 |
… |
… |
public function __construct( $manager, $id, $args = array() ) { |
134 | 193 | public function json() { |
135 | 194 | $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) ); |
136 | 195 | $array['content'] = $this->get_content(); |
| 196 | $array['active'] = $this->active(); |
137 | 197 | return $array; |
138 | 198 | } |
139 | 199 | |
… |
… |
public function json() { |
146 | 206 | * @return bool False if theme doesn't support the section or user doesn't have the capability. |
147 | 207 | */ |
148 | 208 | 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 ) ) { |
150 | 210 | return false; |
| 211 | } |
151 | 212 | |
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 ) ) { |
153 | 214 | return false; |
| 215 | } |
154 | 216 | |
155 | 217 | return true; |
156 | 218 | } |
… |
… |
public function json() { |
176 | 238 | * @since 3.4.0 |
177 | 239 | */ |
178 | 240 | public final function maybe_render() { |
179 | | if ( ! $this->check_capabilities() ) |
| 241 | if ( ! $this->check_capabilities() ) { |
180 | 242 | return; |
| 243 | } |
181 | 244 | |
182 | 245 | /** |
183 | 246 | * Fires before rendering a Customizer section. |
diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js
index 6da26f4..1a82565 100644
a
|
b
|
|
107 | 107 | }); |
108 | 108 | |
109 | 109 | preview.send( 'ready', { |
| 110 | activePanels: api.settings.activePanels, |
| 111 | activeSections: api.settings.activeSections, |
110 | 112 | activeControls: api.settings.activeControls |
111 | 113 | } ); |
112 | 114 | |