Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WP_Customize_Manager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WP_Customize_Manager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | final class WP_Customize_Manager { |
||
24 | /** |
||
25 | * An instance of the theme being previewed. |
||
26 | * |
||
27 | * @since 3.4.0 |
||
28 | * @access protected |
||
29 | * @var WP_Theme |
||
30 | */ |
||
31 | protected $theme; |
||
32 | |||
33 | /** |
||
34 | * The directory name of the previously active theme (within the theme_root). |
||
35 | * |
||
36 | * @since 3.4.0 |
||
37 | * @access protected |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $original_stylesheet; |
||
41 | |||
42 | /** |
||
43 | * Whether this is a Customizer pageload. |
||
44 | * |
||
45 | * @since 3.4.0 |
||
46 | * @access protected |
||
47 | * @var bool |
||
48 | */ |
||
49 | protected $previewing = false; |
||
50 | |||
51 | /** |
||
52 | * Methods and properties dealing with managing widgets in the Customizer. |
||
53 | * |
||
54 | * @since 3.9.0 |
||
55 | * @access public |
||
56 | * @var WP_Customize_Widgets |
||
57 | */ |
||
58 | public $widgets; |
||
59 | |||
60 | /** |
||
61 | * Methods and properties dealing with managing nav menus in the Customizer. |
||
62 | * |
||
63 | * @since 4.3.0 |
||
64 | * @access public |
||
65 | * @var WP_Customize_Nav_Menus |
||
66 | */ |
||
67 | public $nav_menus; |
||
68 | |||
69 | /** |
||
70 | * Methods and properties dealing with selective refresh in the Customizer preview. |
||
71 | * |
||
72 | * @since 4.5.0 |
||
73 | * @access public |
||
74 | * @var WP_Customize_Selective_Refresh |
||
75 | */ |
||
76 | public $selective_refresh; |
||
77 | |||
78 | /** |
||
79 | * Registered instances of WP_Customize_Setting. |
||
80 | * |
||
81 | * @since 3.4.0 |
||
82 | * @access protected |
||
83 | * @var array |
||
84 | */ |
||
85 | protected $settings = array(); |
||
86 | |||
87 | /** |
||
88 | * Sorted top-level instances of WP_Customize_Panel and WP_Customize_Section. |
||
89 | * |
||
90 | * @since 4.0.0 |
||
91 | * @access protected |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $containers = array(); |
||
95 | |||
96 | /** |
||
97 | * Registered instances of WP_Customize_Panel. |
||
98 | * |
||
99 | * @since 4.0.0 |
||
100 | * @access protected |
||
101 | * @var array |
||
102 | */ |
||
103 | protected $panels = array(); |
||
104 | |||
105 | /** |
||
106 | * List of core components. |
||
107 | * |
||
108 | * @since 4.5.0 |
||
109 | * @access protected |
||
110 | * @var array |
||
111 | */ |
||
112 | protected $components = array( 'widgets', 'nav_menus' ); |
||
113 | |||
114 | /** |
||
115 | * Registered instances of WP_Customize_Section. |
||
116 | * |
||
117 | * @since 3.4.0 |
||
118 | * @access protected |
||
119 | * @var array |
||
120 | */ |
||
121 | protected $sections = array(); |
||
122 | |||
123 | /** |
||
124 | * Registered instances of WP_Customize_Control. |
||
125 | * |
||
126 | * @since 3.4.0 |
||
127 | * @access protected |
||
128 | * @var array |
||
129 | */ |
||
130 | protected $controls = array(); |
||
131 | |||
132 | /** |
||
133 | * Return value of check_ajax_referer() in customize_preview_init() method. |
||
134 | * |
||
135 | * @since 3.5.0 |
||
136 | * @access protected |
||
137 | * @var false|int |
||
138 | */ |
||
139 | protected $nonce_tick; |
||
140 | |||
141 | /** |
||
142 | * Panel types that may be rendered from JS templates. |
||
143 | * |
||
144 | * @since 4.3.0 |
||
145 | * @access protected |
||
146 | * @var array |
||
147 | */ |
||
148 | protected $registered_panel_types = array(); |
||
149 | |||
150 | /** |
||
151 | * Section types that may be rendered from JS templates. |
||
152 | * |
||
153 | * @since 4.3.0 |
||
154 | * @access protected |
||
155 | * @var array |
||
156 | */ |
||
157 | protected $registered_section_types = array(); |
||
158 | |||
159 | /** |
||
160 | * Control types that may be rendered from JS templates. |
||
161 | * |
||
162 | * @since 4.1.0 |
||
163 | * @access protected |
||
164 | * @var array |
||
165 | */ |
||
166 | protected $registered_control_types = array(); |
||
167 | |||
168 | /** |
||
169 | * Initial URL being previewed. |
||
170 | * |
||
171 | * @since 4.4.0 |
||
172 | * @access protected |
||
173 | * @var string |
||
174 | */ |
||
175 | protected $preview_url; |
||
176 | |||
177 | /** |
||
178 | * URL to link the user to when closing the Customizer. |
||
179 | * |
||
180 | * @since 4.4.0 |
||
181 | * @access protected |
||
182 | * @var string |
||
183 | */ |
||
184 | protected $return_url; |
||
185 | |||
186 | /** |
||
187 | * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused. |
||
188 | * |
||
189 | * @since 4.4.0 |
||
190 | * @access protected |
||
191 | * @var array |
||
192 | */ |
||
193 | protected $autofocus = array(); |
||
194 | |||
195 | /** |
||
196 | * Unsanitized values for Customize Settings parsed from $_POST['customized']. |
||
197 | * |
||
198 | * @var array |
||
199 | */ |
||
200 | private $_post_values; |
||
201 | |||
202 | /** |
||
203 | * Constructor. |
||
204 | * |
||
205 | * @since 3.4.0 |
||
206 | */ |
||
207 | public function __construct() { |
||
208 | require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' ); |
||
209 | require_once( ABSPATH . WPINC . '/class-wp-customize-panel.php' ); |
||
210 | require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' ); |
||
211 | require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' ); |
||
212 | |||
213 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php' ); |
||
214 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php' ); |
||
215 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php' ); |
||
216 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php' ); |
||
217 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' ); |
||
218 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' ); |
||
219 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' ); |
||
220 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' ); |
||
221 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' ); |
||
222 | require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' ); |
||
223 | require_once( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' ); |
||
224 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php' ); |
||
225 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php' ); |
||
226 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php' ); |
||
227 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' ); |
||
228 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' ); |
||
229 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-control.php' ); |
||
230 | |||
231 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' ); |
||
232 | |||
233 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' ); |
||
234 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' ); |
||
235 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' ); |
||
236 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' ); |
||
237 | |||
238 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php' ); |
||
239 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php' ); |
||
240 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-setting.php' ); |
||
241 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-setting.php' ); |
||
242 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-setting.php' ); |
||
243 | |||
244 | /** |
||
245 | * Filters the core Customizer components to load. |
||
246 | * |
||
247 | * This allows Core components to be excluded from being instantiated by |
||
248 | * filtering them out of the array. Note that this filter generally runs |
||
249 | * during the {@see 'plugins_loaded'} action, so it cannot be added |
||
250 | * in a theme. |
||
251 | * |
||
252 | * @since 4.4.0 |
||
253 | * |
||
254 | * @see WP_Customize_Manager::__construct() |
||
255 | * |
||
256 | * @param array $components List of core components to load. |
||
257 | * @param WP_Customize_Manager $this WP_Customize_Manager instance. |
||
258 | */ |
||
259 | $components = apply_filters( 'customize_loaded_components', $this->components, $this ); |
||
260 | |||
261 | require_once( ABSPATH . WPINC . '/customize/class-wp-customize-selective-refresh.php' ); |
||
262 | $this->selective_refresh = new WP_Customize_Selective_Refresh( $this ); |
||
263 | |||
264 | View Code Duplication | if ( in_array( 'widgets', $components, true ) ) { |
|
265 | require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' ); |
||
266 | $this->widgets = new WP_Customize_Widgets( $this ); |
||
267 | } |
||
268 | |||
269 | View Code Duplication | if ( in_array( 'nav_menus', $components, true ) ) { |
|
270 | require_once( ABSPATH . WPINC . '/class-wp-customize-nav-menus.php' ); |
||
271 | $this->nav_menus = new WP_Customize_Nav_Menus( $this ); |
||
272 | } |
||
273 | |||
274 | add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) ); |
||
275 | |||
276 | add_action( 'setup_theme', array( $this, 'setup_theme' ) ); |
||
277 | add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); |
||
278 | |||
279 | // Run wp_redirect_status late to make sure we override the status last. |
||
280 | add_action( 'wp_redirect_status', array( $this, 'wp_redirect_status' ), 1000 ); |
||
281 | |||
282 | // Do not spawn cron (especially the alternate cron) while running the Customizer. |
||
283 | remove_action( 'init', 'wp_cron' ); |
||
284 | |||
285 | // Do not run update checks when rendering the controls. |
||
286 | remove_action( 'admin_init', '_maybe_update_core' ); |
||
287 | remove_action( 'admin_init', '_maybe_update_plugins' ); |
||
288 | remove_action( 'admin_init', '_maybe_update_themes' ); |
||
289 | |||
290 | add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); |
||
291 | add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); |
||
292 | |||
293 | add_action( 'customize_register', array( $this, 'register_controls' ) ); |
||
294 | add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first |
||
295 | add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) ); |
||
296 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) ); |
||
297 | |||
298 | // Render Panel, Section, and Control templates. |
||
299 | add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_panel_templates' ), 1 ); |
||
300 | add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_section_templates' ), 1 ); |
||
301 | add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_control_templates' ), 1 ); |
||
302 | |||
303 | // Export the settings to JS via the _wpCustomizeSettings variable. |
||
304 | add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 ); |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * Return true if it's an Ajax request. |
||
309 | * |
||
310 | * @since 3.4.0 |
||
311 | * @since 4.2.0 Added `$action` param. |
||
312 | * @access public |
||
313 | * |
||
314 | * @param string|null $action Whether the supplied Ajax action is being run. |
||
315 | * @return bool True if it's an Ajax request, false otherwise. |
||
316 | */ |
||
317 | public function doing_ajax( $action = null ) { |
||
318 | $doing_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
||
319 | if ( ! $doing_ajax ) { |
||
320 | return false; |
||
321 | } |
||
322 | |||
323 | if ( ! $action ) { |
||
|
|||
324 | return true; |
||
325 | } else { |
||
326 | /* |
||
327 | * Note: we can't just use doing_action( "wp_ajax_{$action}" ) because we need |
||
328 | * to check before admin-ajax.php gets to that point. |
||
329 | */ |
||
330 | return isset( $_REQUEST['action'] ) && wp_unslash( $_REQUEST['action'] ) === $action; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Custom wp_die wrapper. Returns either the standard message for UI |
||
336 | * or the Ajax message. |
||
337 | * |
||
338 | * @since 3.4.0 |
||
339 | * |
||
340 | * @param mixed $ajax_message Ajax return |
||
341 | * @param mixed $message UI message |
||
342 | */ |
||
343 | protected function wp_die( $ajax_message, $message = null ) { |
||
344 | if ( $this->doing_ajax() || isset( $_POST['customized'] ) ) { |
||
345 | wp_die( $ajax_message ); |
||
346 | } |
||
347 | |||
348 | if ( ! $message ) { |
||
349 | $message = __( 'Cheatin’ uh?' ); |
||
350 | } |
||
351 | |||
352 | wp_die( $message ); |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * Return the Ajax wp_die() handler if it's a customized request. |
||
357 | * |
||
358 | * @since 3.4.0 |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | public function wp_die_handler() { |
||
369 | |||
370 | /** |
||
371 | * Start preview and customize theme. |
||
372 | * |
||
373 | * Check if customize query variable exist. Init filters to filter the current theme. |
||
374 | * |
||
375 | * @since 3.4.0 |
||
376 | */ |
||
377 | public function setup_theme() { |
||
378 | send_origin_headers(); |
||
379 | |||
380 | $doing_ajax_or_is_customized = ( $this->doing_ajax() || isset( $_POST['customized'] ) ); |
||
381 | if ( is_admin() && ! $doing_ajax_or_is_customized ) { |
||
382 | auth_redirect(); |
||
383 | } elseif ( $doing_ajax_or_is_customized && ! is_user_logged_in() ) { |
||
384 | $this->wp_die( 0, __( 'You must be logged in to complete this action.' ) ); |
||
385 | } |
||
386 | |||
387 | show_admin_bar( false ); |
||
388 | |||
389 | if ( ! current_user_can( 'customize' ) ) { |
||
390 | $this->wp_die( -1, __( 'Sorry, you are not allowed to customize this site.' ) ); |
||
391 | } |
||
392 | |||
393 | $this->original_stylesheet = get_stylesheet(); |
||
394 | |||
395 | $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null ); |
||
396 | |||
397 | if ( $this->is_theme_active() ) { |
||
398 | // Once the theme is loaded, we'll validate it. |
||
399 | add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) ); |
||
400 | } else { |
||
401 | // If the requested theme is not the active theme and the user doesn't have the |
||
402 | // switch_themes cap, bail. |
||
403 | if ( ! current_user_can( 'switch_themes' ) ) { |
||
404 | $this->wp_die( -1, __( 'Sorry, you are not allowed to edit theme options on this site.' ) ); |
||
405 | } |
||
406 | |||
407 | // If the theme has errors while loading, bail. |
||
408 | if ( $this->theme()->errors() ) { |
||
409 | $this->wp_die( -1, $this->theme()->errors()->get_error_message() ); |
||
410 | } |
||
411 | |||
412 | // If the theme isn't allowed per multisite settings, bail. |
||
413 | if ( ! $this->theme()->is_allowed() ) { |
||
414 | $this->wp_die( -1, __( 'The requested theme does not exist.' ) ); |
||
415 | } |
||
416 | } |
||
417 | |||
418 | $this->start_previewing_theme(); |
||
419 | } |
||
420 | |||
421 | /** |
||
422 | * Callback to validate a theme once it is loaded |
||
423 | * |
||
424 | * @since 3.4.0 |
||
425 | */ |
||
426 | public function after_setup_theme() { |
||
427 | $doing_ajax_or_is_customized = ( $this->doing_ajax() || isset( $_POST['customized'] ) ); |
||
428 | if ( ! $doing_ajax_or_is_customized && ! validate_current_theme() ) { |
||
429 | wp_redirect( 'themes.php?broken=true' ); |
||
430 | exit; |
||
431 | } |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * If the theme to be previewed isn't the active theme, add filter callbacks |
||
436 | * to swap it out at runtime. |
||
437 | * |
||
438 | * @since 3.4.0 |
||
439 | */ |
||
440 | View Code Duplication | public function start_previewing_theme() { |
|
471 | |||
472 | /** |
||
473 | * Stop previewing the selected theme. |
||
474 | * |
||
475 | * Removes filters to change the current theme. |
||
476 | * |
||
477 | * @since 3.4.0 |
||
478 | */ |
||
479 | View Code Duplication | public function stop_previewing_theme() { |
|
509 | |||
510 | /** |
||
511 | * Get the theme being customized. |
||
512 | * |
||
513 | * @since 3.4.0 |
||
514 | * |
||
515 | * @return WP_Theme |
||
516 | */ |
||
517 | public function theme() { |
||
523 | |||
524 | /** |
||
525 | * Get the registered settings. |
||
526 | * |
||
527 | * @since 3.4.0 |
||
528 | * |
||
529 | * @return array |
||
530 | */ |
||
531 | public function settings() { |
||
534 | |||
535 | /** |
||
536 | * Get the registered controls. |
||
537 | * |
||
538 | * @since 3.4.0 |
||
539 | * |
||
540 | * @return array |
||
541 | */ |
||
542 | public function controls() { |
||
545 | |||
546 | /** |
||
547 | * Get the registered containers. |
||
548 | * |
||
549 | * @since 4.0.0 |
||
550 | * |
||
551 | * @return array |
||
552 | */ |
||
553 | public function containers() { |
||
556 | |||
557 | /** |
||
558 | * Get the registered sections. |
||
559 | * |
||
560 | * @since 3.4.0 |
||
561 | * |
||
562 | * @return array |
||
563 | */ |
||
564 | public function sections() { |
||
567 | |||
568 | /** |
||
569 | * Get the registered panels. |
||
570 | * |
||
571 | * @since 4.0.0 |
||
572 | * @access public |
||
573 | * |
||
574 | * @return array Panels. |
||
575 | */ |
||
576 | public function panels() { |
||
579 | |||
580 | /** |
||
581 | * Checks if the current theme is active. |
||
582 | * |
||
583 | * @since 3.4.0 |
||
584 | * |
||
585 | * @return bool |
||
586 | */ |
||
587 | public function is_theme_active() { |
||
588 | return $this->get_stylesheet() == $this->original_stylesheet; |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * Register styles/scripts and initialize the preview of each setting |
||
593 | * |
||
594 | * @since 3.4.0 |
||
595 | */ |
||
596 | public function wp_loaded() { |
||
610 | |||
611 | /** |
||
612 | * Prevents Ajax requests from following redirects when previewing a theme |
||
613 | * by issuing a 200 response instead of a 30x. |
||
614 | * |
||
615 | * Instead, the JS will sniff out the location header. |
||
616 | * |
||
617 | * @since 3.4.0 |
||
618 | * |
||
619 | * @param $status |
||
620 | * @return int |
||
621 | */ |
||
622 | public function wp_redirect_status( $status ) { |
||
628 | |||
629 | /** |
||
630 | * Parse the incoming $_POST['customized'] JSON data and store the unsanitized |
||
631 | * settings for subsequent post_value() lookups. |
||
632 | * |
||
633 | * @since 4.1.1 |
||
634 | * |
||
635 | * @return array |
||
636 | */ |
||
637 | public function unsanitized_post_values() { |
||
638 | if ( ! isset( $this->_post_values ) ) { |
||
639 | if ( isset( $_POST['customized'] ) ) { |
||
640 | $this->_post_values = json_decode( wp_unslash( $_POST['customized'] ), true ); |
||
641 | } |
||
642 | if ( empty( $this->_post_values ) ) { // if not isset or if JSON error |
||
643 | $this->_post_values = array(); |
||
644 | } |
||
645 | } |
||
646 | if ( empty( $this->_post_values ) ) { |
||
647 | return array(); |
||
648 | } else { |
||
649 | return $this->_post_values; |
||
650 | } |
||
651 | } |
||
652 | |||
653 | /** |
||
654 | * Returns the sanitized value for a given setting from the request's POST data. |
||
655 | * |
||
656 | * @since 3.4.0 |
||
657 | * @since 4.1.1 Introduced the `$default` parameter. |
||
658 | * @since 4.6.0 `$default` is now returned early when the setting post value is invalid. |
||
659 | * @access public |
||
660 | * |
||
661 | * @see WP_REST_Server::dispatch() |
||
662 | * @see WP_Rest_Request::sanitize_params() |
||
663 | * @see WP_Rest_Request::has_valid_params() |
||
664 | * |
||
665 | * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object. |
||
666 | * @param mixed $default Value returned $setting has no post value (added in 4.2.0) |
||
667 | * or the post value is invalid (added in 4.6.0). |
||
668 | * @return string|mixed $post_value Sanitized value or the $default provided. |
||
669 | */ |
||
670 | public function post_value( $setting, $default = null ) { |
||
671 | $post_values = $this->unsanitized_post_values(); |
||
672 | if ( ! array_key_exists( $setting->id, $post_values ) ) { |
||
673 | return $default; |
||
674 | } |
||
675 | $value = $post_values[ $setting->id ]; |
||
676 | $valid = $setting->validate( $value ); |
||
677 | if ( is_wp_error( $valid ) ) { |
||
678 | return $default; |
||
679 | } |
||
680 | $value = $setting->sanitize( $value ); |
||
681 | if ( is_null( $value ) || is_wp_error( $value ) ) { |
||
682 | return $default; |
||
683 | } |
||
684 | return $value; |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Override a setting's (unsanitized) value as found in any incoming $_POST['customized']. |
||
689 | * |
||
690 | * @since 4.2.0 |
||
691 | * @access public |
||
692 | * |
||
693 | * @param string $setting_id ID for the WP_Customize_Setting instance. |
||
694 | * @param mixed $value Post value. |
||
695 | */ |
||
696 | public function set_post_value( $setting_id, $value ) { |
||
697 | $this->unsanitized_post_values(); |
||
698 | $this->_post_values[ $setting_id ] = $value; |
||
699 | |||
700 | /** |
||
701 | * Announce when a specific setting's unsanitized post value has been set. |
||
702 | * |
||
703 | * Fires when the WP_Customize_Manager::set_post_value() method is called. |
||
704 | * |
||
705 | * The dynamic portion of the hook name, `$setting_id`, refers to the setting ID. |
||
706 | * |
||
707 | * @since 4.4.0 |
||
708 | * |
||
709 | * @param mixed $value Unsanitized setting post value. |
||
710 | * @param WP_Customize_Manager $this WP_Customize_Manager instance. |
||
711 | */ |
||
712 | do_action( "customize_post_value_set_{$setting_id}", $value, $this ); |
||
713 | |||
714 | /** |
||
715 | * Announce when any setting's unsanitized post value has been set. |
||
716 | * |
||
717 | * Fires when the WP_Customize_Manager::set_post_value() method is called. |
||
718 | * |
||
719 | * This is useful for `WP_Customize_Setting` instances to watch |
||
720 | * in order to update a cached previewed value. |
||
721 | * |
||
722 | * @since 4.4.0 |
||
723 | * |
||
724 | * @param string $setting_id Setting ID. |
||
725 | * @param mixed $value Unsanitized setting post value. |
||
726 | * @param WP_Customize_Manager $this WP_Customize_Manager instance. |
||
727 | */ |
||
728 | do_action( 'customize_post_value_set', $setting_id, $value, $this ); |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * Print JavaScript settings. |
||
733 | * |
||
734 | * @since 3.4.0 |
||
735 | */ |
||
736 | public function customize_preview_init() { |
||
764 | |||
765 | /** |
||
766 | * Prevent sending a 404 status when returning the response for the customize |
||
767 | * preview, since it causes the jQuery Ajax to fail. Send 200 instead. |
||
768 | * |
||
769 | * @since 4.0.0 |
||
770 | * @access public |
||
771 | */ |
||
772 | public function customize_preview_override_404_status() { |
||
777 | |||
778 | /** |
||
779 | * Print base element for preview frame. |
||
780 | * |
||
781 | * @since 3.4.0 |
||
782 | */ |
||
783 | public function customize_preview_base() { |
||
786 | |||
787 | /** |
||
788 | * Print a workaround to handle HTML5 tags in IE < 9. |
||
789 | * |
||
790 | * @since 3.4.0 |
||
791 | */ |
||
792 | public function customize_preview_html5() { ?> |
||
804 | |||
805 | /** |
||
806 | * Print CSS for loading indicators for the Customizer preview. |
||
807 | * |
||
808 | * @since 4.2.0 |
||
809 | * @access public |
||
810 | */ |
||
811 | public function customize_preview_loading_style() { |
||
824 | |||
825 | /** |
||
826 | * Print JavaScript settings for preview frame. |
||
827 | * |
||
828 | * @since 3.4.0 |
||
829 | */ |
||
830 | public function customize_preview_settings() { |
||
831 | $setting_validities = $this->validate_setting_values( $this->unsanitized_post_values() ); |
||
832 | $exported_setting_validities = array_map( array( $this, 'prepare_setting_validity_for_js' ), $setting_validities ); |
||
833 | |||
834 | $settings = array( |
||
835 | 'theme' => array( |
||
836 | 'stylesheet' => $this->get_stylesheet(), |
||
837 | 'active' => $this->is_theme_active(), |
||
838 | ), |
||
839 | 'url' => array( |
||
840 | 'self' => empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), |
||
841 | ), |
||
842 | 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), |
||
843 | 'activePanels' => array(), |
||
844 | 'activeSections' => array(), |
||
845 | 'activeControls' => array(), |
||
846 | 'settingValidities' => $exported_setting_validities, |
||
847 | 'nonce' => $this->get_nonces(), |
||
848 | 'l10n' => array( |
||
849 | 'shiftClickToEdit' => __( 'Shift-click to edit this element.' ), |
||
850 | ), |
||
851 | '_dirty' => array_keys( $this->unsanitized_post_values() ), |
||
852 | ); |
||
853 | |||
854 | View Code Duplication | foreach ( $this->panels as $panel_id => $panel ) { |
|
855 | if ( $panel->check_capabilities() ) { |
||
856 | $settings['activePanels'][ $panel_id ] = $panel->active(); |
||
857 | foreach ( $panel->sections as $section_id => $section ) { |
||
858 | if ( $section->check_capabilities() ) { |
||
859 | $settings['activeSections'][ $section_id ] = $section->active(); |
||
860 | } |
||
861 | } |
||
862 | } |
||
863 | } |
||
864 | foreach ( $this->sections as $id => $section ) { |
||
865 | if ( $section->check_capabilities() ) { |
||
866 | $settings['activeSections'][ $id ] = $section->active(); |
||
867 | } |
||
868 | } |
||
869 | foreach ( $this->controls as $id => $control ) { |
||
870 | if ( $control->check_capabilities() ) { |
||
871 | $settings['activeControls'][ $id ] = $control->active(); |
||
872 | } |
||
873 | } |
||
874 | |||
875 | ?> |
||
876 | <script type="text/javascript"> |
||
877 | var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>; |
||
878 | _wpCustomizeSettings.values = {}; |
||
879 | (function( v ) { |
||
880 | <?php |
||
881 | /* |
||
882 | * Serialize settings separately from the initial _wpCustomizeSettings |
||
883 | * serialization in order to avoid a peak memory usage spike. |
||
884 | * @todo We may not even need to export the values at all since the pane syncs them anyway. |
||
885 | */ |
||
886 | View Code Duplication | foreach ( $this->settings as $id => $setting ) { |
|
887 | if ( $setting->check_capabilities() ) { |
||
888 | printf( |
||
889 | "v[%s] = %s;\n", |
||
890 | wp_json_encode( $id ), |
||
891 | wp_json_encode( $setting->js_value() ) |
||
892 | ); |
||
893 | } |
||
894 | } |
||
895 | ?> |
||
896 | })( _wpCustomizeSettings.values ); |
||
897 | </script> |
||
898 | <?php |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Prints a signature so we can ensure the Customizer was properly executed. |
||
903 | * |
||
904 | * @since 3.4.0 |
||
905 | */ |
||
906 | public function customize_preview_signature() { |
||
909 | |||
910 | /** |
||
911 | * Removes the signature in case we experience a case where the Customizer was not properly executed. |
||
912 | * |
||
913 | * @since 3.4.0 |
||
914 | * |
||
915 | * @param mixed $return Value passed through for {@see 'wp_die_handler'} filter. |
||
916 | * @return mixed Value passed through for {@see 'wp_die_handler'} filter. |
||
917 | */ |
||
918 | public function remove_preview_signature( $return = null ) { |
||
923 | |||
924 | /** |
||
925 | * Is it a theme preview? |
||
926 | * |
||
927 | * @since 3.4.0 |
||
928 | * |
||
929 | * @return bool True if it's a preview, false if not. |
||
930 | */ |
||
931 | public function is_preview() { |
||
934 | |||
935 | /** |
||
936 | * Retrieve the template name of the previewed theme. |
||
937 | * |
||
938 | * @since 3.4.0 |
||
939 | * |
||
940 | * @return string Template name. |
||
941 | */ |
||
942 | public function get_template() { |
||
943 | return $this->theme()->get_template(); |
||
944 | } |
||
945 | |||
946 | /** |
||
947 | * Retrieve the stylesheet name of the previewed theme. |
||
948 | * |
||
949 | * @since 3.4.0 |
||
950 | * |
||
951 | * @return string Stylesheet name. |
||
952 | */ |
||
953 | public function get_stylesheet() { |
||
954 | return $this->theme()->get_stylesheet(); |
||
955 | } |
||
956 | |||
957 | /** |
||
958 | * Retrieve the template root of the previewed theme. |
||
959 | * |
||
960 | * @since 3.4.0 |
||
961 | * |
||
962 | * @return string Theme root. |
||
963 | */ |
||
964 | public function get_template_root() { |
||
965 | return get_raw_theme_root( $this->get_template(), true ); |
||
966 | } |
||
967 | |||
968 | /** |
||
969 | * Retrieve the stylesheet root of the previewed theme. |
||
970 | * |
||
971 | * @since 3.4.0 |
||
972 | * |
||
973 | * @return string Theme root. |
||
974 | */ |
||
975 | public function get_stylesheet_root() { |
||
978 | |||
979 | /** |
||
980 | * Filters the current theme and return the name of the previewed theme. |
||
981 | * |
||
982 | * @since 3.4.0 |
||
983 | * |
||
984 | * @param $current_theme {@internal Parameter is not used} |
||
985 | * @return string Theme name. |
||
986 | */ |
||
987 | public function current_theme( $current_theme ) { |
||
988 | return $this->theme()->display('Name'); |
||
989 | } |
||
990 | |||
991 | /** |
||
992 | * Validates setting values. |
||
993 | * |
||
994 | * Validation is skipped for unregistered settings or for values that are |
||
995 | * already null since they will be skipped anyway. Sanitization is applied |
||
996 | * to values that pass validation, and values that become null or `WP_Error` |
||
997 | * after sanitizing are marked invalid. |
||
998 | * |
||
999 | * @since 4.6.0 |
||
1000 | * @access public |
||
1001 | * |
||
1002 | * @see WP_REST_Request::has_valid_params() |
||
1003 | * @see WP_Customize_Setting::validate() |
||
1004 | * |
||
1005 | * @param array $setting_values Mapping of setting IDs to values to validate and sanitize. |
||
1006 | * @return array Mapping of setting IDs to return value of validate method calls, either `true` or `WP_Error`. |
||
1007 | */ |
||
1008 | public function validate_setting_values( $setting_values ) { |
||
1009 | $validities = array(); |
||
1010 | foreach ( $setting_values as $setting_id => $unsanitized_value ) { |
||
1011 | $setting = $this->get_setting( $setting_id ); |
||
1012 | if ( ! $setting || is_null( $unsanitized_value ) ) { |
||
1013 | continue; |
||
1014 | } |
||
1015 | $validity = $setting->validate( $unsanitized_value ); |
||
1016 | if ( ! is_wp_error( $validity ) ) { |
||
1017 | $value = $setting->sanitize( $unsanitized_value ); |
||
1018 | if ( is_null( $value ) ) { |
||
1019 | $validity = false; |
||
1020 | } elseif ( is_wp_error( $value ) ) { |
||
1021 | $validity = $value; |
||
1022 | } |
||
1023 | } |
||
1024 | if ( false === $validity ) { |
||
1025 | $validity = new WP_Error( 'invalid_value', __( 'Invalid value.' ) ); |
||
1026 | } |
||
1027 | $validities[ $setting_id ] = $validity; |
||
1028 | } |
||
1029 | return $validities; |
||
1030 | } |
||
1031 | |||
1032 | /** |
||
1033 | * Prepares setting validity for exporting to the client (JS). |
||
1034 | * |
||
1035 | * Converts `WP_Error` instance into array suitable for passing into the |
||
1036 | * `wp.customize.Notification` JS model. |
||
1037 | * |
||
1038 | * @since 4.6.0 |
||
1039 | * @access public |
||
1040 | * |
||
1041 | * @param true|WP_Error $validity Setting validity. |
||
1042 | * @return true|array If `$validity` was a WP_Error, the error codes will be array-mapped |
||
1043 | * to their respective `message` and `data` to pass into the |
||
1044 | * `wp.customize.Notification` JS model. |
||
1045 | */ |
||
1046 | public function prepare_setting_validity_for_js( $validity ) { |
||
1068 | |||
1069 | /** |
||
1070 | * Switch the theme and trigger the save() method on each setting. |
||
1071 | * |
||
1072 | * @since 3.4.0 |
||
1073 | */ |
||
1074 | public function save() { |
||
1163 | |||
1164 | /** |
||
1165 | * Refresh nonces for the current preview. |
||
1166 | * |
||
1167 | * @since 4.2.0 |
||
1168 | */ |
||
1169 | public function refresh_nonces() { |
||
1176 | |||
1177 | /** |
||
1178 | * Add a customize setting. |
||
1179 | * |
||
1180 | * @since 3.4.0 |
||
1181 | * @since 4.5.0 Return added WP_Customize_Setting instance. |
||
1182 | * @access public |
||
1183 | * |
||
1184 | * @param WP_Customize_Setting|string $id Customize Setting object, or ID. |
||
1185 | * @param array $args Setting arguments; passed to WP_Customize_Setting |
||
1186 | * constructor. |
||
1187 | * @return WP_Customize_Setting The instance of the setting that was added. |
||
1188 | */ |
||
1189 | public function add_setting( $id, $args = array() ) { |
||
1207 | |||
1208 | /** |
||
1209 | * Register any dynamically-created settings, such as those from $_POST['customized'] |
||
1210 | * that have no corresponding setting created. |
||
1211 | * |
||
1212 | * This is a mechanism to "wake up" settings that have been dynamically created |
||
1213 | * on the front end and have been sent to WordPress in `$_POST['customized']`. When WP |
||
1214 | * loads, the dynamically-created settings then will get created and previewed |
||
1215 | * even though they are not directly created statically with code. |
||
1216 | * |
||
1217 | * @since 4.2.0 |
||
1218 | * @access public |
||
1219 | * |
||
1220 | * @param array $setting_ids The setting IDs to add. |
||
1221 | * @return array The WP_Customize_Setting objects added. |
||
1222 | */ |
||
1223 | public function add_dynamic_settings( $setting_ids ) { |
||
1269 | |||
1270 | /** |
||
1271 | * Retrieve a customize setting. |
||
1272 | * |
||
1273 | * @since 3.4.0 |
||
1274 | * |
||
1275 | * @param string $id Customize Setting ID. |
||
1276 | * @return WP_Customize_Setting|void The setting, if set. |
||
1277 | */ |
||
1278 | public function get_setting( $id ) { |
||
1283 | |||
1284 | /** |
||
1285 | * Remove a customize setting. |
||
1286 | * |
||
1287 | * @since 3.4.0 |
||
1288 | * |
||
1289 | * @param string $id Customize Setting ID. |
||
1290 | */ |
||
1291 | public function remove_setting( $id ) { |
||
1294 | |||
1295 | /** |
||
1296 | * Add a customize panel. |
||
1297 | * |
||
1298 | * @since 4.0.0 |
||
1299 | * @since 4.5.0 Return added WP_Customize_Panel instance. |
||
1300 | * @access public |
||
1301 | * |
||
1302 | * @param WP_Customize_Panel|string $id Customize Panel object, or Panel ID. |
||
1303 | * @param array $args Optional. Panel arguments. Default empty array. |
||
1304 | * |
||
1305 | * @return WP_Customize_Panel The instance of the panel that was added. |
||
1306 | */ |
||
1307 | public function add_panel( $id, $args = array() ) { |
||
1317 | |||
1318 | /** |
||
1319 | * Retrieve a customize panel. |
||
1320 | * |
||
1321 | * @since 4.0.0 |
||
1322 | * @access public |
||
1323 | * |
||
1324 | * @param string $id Panel ID to get. |
||
1325 | * @return WP_Customize_Panel|void Requested panel instance, if set. |
||
1326 | */ |
||
1327 | public function get_panel( $id ) { |
||
1332 | |||
1333 | /** |
||
1334 | * Remove a customize panel. |
||
1335 | * |
||
1336 | * @since 4.0.0 |
||
1337 | * @access public |
||
1338 | * |
||
1339 | * @param string $id Panel ID to remove. |
||
1340 | */ |
||
1341 | public function remove_panel( $id ) { |
||
1354 | |||
1355 | /** |
||
1356 | * Register a customize panel type. |
||
1357 | * |
||
1358 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1359 | * |
||
1360 | * @since 4.3.0 |
||
1361 | * @access public |
||
1362 | * |
||
1363 | * @see WP_Customize_Panel |
||
1364 | * |
||
1365 | * @param string $panel Name of a custom panel which is a subclass of WP_Customize_Panel. |
||
1366 | */ |
||
1367 | public function register_panel_type( $panel ) { |
||
1370 | |||
1371 | /** |
||
1372 | * Render JS templates for all registered panel types. |
||
1373 | * |
||
1374 | * @since 4.3.0 |
||
1375 | * @access public |
||
1376 | */ |
||
1377 | public function render_panel_templates() { |
||
1383 | |||
1384 | /** |
||
1385 | * Add a customize section. |
||
1386 | * |
||
1387 | * @since 3.4.0 |
||
1388 | * @since 4.5.0 Return added WP_Customize_Section instance. |
||
1389 | * @access public |
||
1390 | * |
||
1391 | * @param WP_Customize_Section|string $id Customize Section object, or Section ID. |
||
1392 | * @param array $args Section arguments. |
||
1393 | * |
||
1394 | * @return WP_Customize_Section The instance of the section that was added. |
||
1395 | */ |
||
1396 | public function add_section( $id, $args = array() ) { |
||
1406 | |||
1407 | /** |
||
1408 | * Retrieve a customize section. |
||
1409 | * |
||
1410 | * @since 3.4.0 |
||
1411 | * |
||
1412 | * @param string $id Section ID. |
||
1413 | * @return WP_Customize_Section|void The section, if set. |
||
1414 | */ |
||
1415 | public function get_section( $id ) { |
||
1419 | |||
1420 | /** |
||
1421 | * Remove a customize section. |
||
1422 | * |
||
1423 | * @since 3.4.0 |
||
1424 | * |
||
1425 | * @param string $id Section ID. |
||
1426 | */ |
||
1427 | public function remove_section( $id ) { |
||
1430 | |||
1431 | /** |
||
1432 | * Register a customize section type. |
||
1433 | * |
||
1434 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1435 | * |
||
1436 | * @since 4.3.0 |
||
1437 | * @access public |
||
1438 | * |
||
1439 | * @see WP_Customize_Section |
||
1440 | * |
||
1441 | * @param string $section Name of a custom section which is a subclass of WP_Customize_Section. |
||
1442 | */ |
||
1443 | public function register_section_type( $section ) { |
||
1446 | |||
1447 | /** |
||
1448 | * Render JS templates for all registered section types. |
||
1449 | * |
||
1450 | * @since 4.3.0 |
||
1451 | * @access public |
||
1452 | */ |
||
1453 | public function render_section_templates() { |
||
1459 | |||
1460 | /** |
||
1461 | * Add a customize control. |
||
1462 | * |
||
1463 | * @since 3.4.0 |
||
1464 | * @since 4.5.0 Return added WP_Customize_Control instance. |
||
1465 | * @access public |
||
1466 | * |
||
1467 | * @param WP_Customize_Control|string $id Customize Control object, or ID. |
||
1468 | * @param array $args Control arguments; passed to WP_Customize_Control |
||
1469 | * constructor. |
||
1470 | * @return WP_Customize_Control The instance of the control that was added. |
||
1471 | */ |
||
1472 | public function add_control( $id, $args = array() ) { |
||
1482 | |||
1483 | /** |
||
1484 | * Retrieve a customize control. |
||
1485 | * |
||
1486 | * @since 3.4.0 |
||
1487 | * |
||
1488 | * @param string $id ID of the control. |
||
1489 | * @return WP_Customize_Control|void The control object, if set. |
||
1490 | */ |
||
1491 | public function get_control( $id ) { |
||
1495 | |||
1496 | /** |
||
1497 | * Remove a customize control. |
||
1498 | * |
||
1499 | * @since 3.4.0 |
||
1500 | * |
||
1501 | * @param string $id ID of the control. |
||
1502 | */ |
||
1503 | public function remove_control( $id ) { |
||
1506 | |||
1507 | /** |
||
1508 | * Register a customize control type. |
||
1509 | * |
||
1510 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1511 | * |
||
1512 | * @since 4.1.0 |
||
1513 | * @access public |
||
1514 | * |
||
1515 | * @param string $control Name of a custom control which is a subclass of |
||
1516 | * WP_Customize_Control. |
||
1517 | */ |
||
1518 | public function register_control_type( $control ) { |
||
1521 | |||
1522 | /** |
||
1523 | * Render JS templates for all registered control types. |
||
1524 | * |
||
1525 | * @since 4.1.0 |
||
1526 | * @access public |
||
1527 | */ |
||
1528 | public function render_control_templates() { |
||
1545 | |||
1546 | /** |
||
1547 | * Helper function to compare two objects by priority, ensuring sort stability via instance_number. |
||
1548 | * |
||
1549 | * @since 3.4.0 |
||
1550 | * |
||
1551 | * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $a Object A. |
||
1552 | * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $b Object B. |
||
1553 | * @return int |
||
1554 | */ |
||
1555 | protected function _cmp_priority( $a, $b ) { |
||
1562 | |||
1563 | /** |
||
1564 | * Prepare panels, sections, and controls. |
||
1565 | * |
||
1566 | * For each, check if required related components exist, |
||
1567 | * whether the user has the necessary capabilities, |
||
1568 | * and sort by priority. |
||
1569 | * |
||
1570 | * @since 3.4.0 |
||
1571 | */ |
||
1572 | public function prepare_controls() { |
||
1628 | |||
1629 | /** |
||
1630 | * Enqueue scripts for customize controls. |
||
1631 | * |
||
1632 | * @since 3.4.0 |
||
1633 | */ |
||
1634 | public function enqueue_control_scripts() { |
||
1639 | |||
1640 | /** |
||
1641 | * Determine whether the user agent is iOS. |
||
1642 | * |
||
1643 | * @since 4.4.0 |
||
1644 | * @access public |
||
1645 | * |
||
1646 | * @return bool Whether the user agent is iOS. |
||
1647 | */ |
||
1648 | public function is_ios() { |
||
1651 | |||
1652 | /** |
||
1653 | * Get the template string for the Customizer pane document title. |
||
1654 | * |
||
1655 | * @since 4.4.0 |
||
1656 | * @access public |
||
1657 | * |
||
1658 | * @return string The template string for the document title. |
||
1659 | */ |
||
1660 | public function get_document_title_template() { |
||
1671 | |||
1672 | /** |
||
1673 | * Set the initial URL to be previewed. |
||
1674 | * |
||
1675 | * URL is validated. |
||
1676 | * |
||
1677 | * @since 4.4.0 |
||
1678 | * @access public |
||
1679 | * |
||
1680 | * @param string $preview_url URL to be previewed. |
||
1681 | */ |
||
1682 | public function set_preview_url( $preview_url ) { |
||
1686 | |||
1687 | /** |
||
1688 | * Get the initial URL to be previewed. |
||
1689 | * |
||
1690 | * @since 4.4.0 |
||
1691 | * @access public |
||
1692 | * |
||
1693 | * @return string URL being previewed. |
||
1694 | */ |
||
1695 | public function get_preview_url() { |
||
1703 | |||
1704 | /** |
||
1705 | * Set URL to link the user to when closing the Customizer. |
||
1706 | * |
||
1707 | * URL is validated. |
||
1708 | * |
||
1709 | * @since 4.4.0 |
||
1710 | * @access public |
||
1711 | * |
||
1712 | * @param string $return_url URL for return link. |
||
1713 | */ |
||
1714 | public function set_return_url( $return_url ) { |
||
1720 | |||
1721 | /** |
||
1722 | * Get URL to link the user to when closing the Customizer. |
||
1723 | * |
||
1724 | * @since 4.4.0 |
||
1725 | * @access public |
||
1726 | * |
||
1727 | * @return string URL for link to close Customizer. |
||
1728 | */ |
||
1729 | public function get_return_url() { |
||
1744 | |||
1745 | /** |
||
1746 | * Set the autofocused constructs. |
||
1747 | * |
||
1748 | * @since 4.4.0 |
||
1749 | * @access public |
||
1750 | * |
||
1751 | * @param array $autofocus { |
||
1752 | * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused. |
||
1753 | * |
||
1754 | * @type string [$control] ID for control to be autofocused. |
||
1755 | * @type string [$section] ID for section to be autofocused. |
||
1756 | * @type string [$panel] ID for panel to be autofocused. |
||
1757 | * } |
||
1758 | */ |
||
1759 | public function set_autofocus( $autofocus ) { |
||
1762 | |||
1763 | /** |
||
1764 | * Get the autofocused constructs. |
||
1765 | * |
||
1766 | * @since 4.4.0 |
||
1767 | * @access public |
||
1768 | * |
||
1769 | * @return array { |
||
1770 | * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused. |
||
1771 | * |
||
1772 | * @type string [$control] ID for control to be autofocused. |
||
1773 | * @type string [$section] ID for section to be autofocused. |
||
1774 | * @type string [$panel] ID for panel to be autofocused. |
||
1775 | * } |
||
1776 | */ |
||
1777 | public function get_autofocus() { |
||
1780 | |||
1781 | /** |
||
1782 | * Get nonces for the Customizer. |
||
1783 | * |
||
1784 | * @since 4.5.0 |
||
1785 | * @return array Nonces. |
||
1786 | */ |
||
1787 | public function get_nonces() { |
||
1788 | $nonces = array( |
||
1789 | 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), |
||
1790 | 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), |
||
1791 | ); |
||
1792 | |||
1793 | /** |
||
1794 | * Filters nonces for Customizer. |
||
1795 | * |
||
1796 | * @since 4.2.0 |
||
1797 | * |
||
1798 | * @param array $nonces Array of refreshed nonces for save and |
||
1799 | * preview actions. |
||
1800 | * @param WP_Customize_Manager $this WP_Customize_Manager instance. |
||
1801 | */ |
||
1802 | $nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this ); |
||
1803 | |||
1804 | return $nonces; |
||
1805 | } |
||
1806 | |||
1807 | /** |
||
1808 | * Print JavaScript settings for parent window. |
||
1809 | * |
||
1810 | * @since 4.4.0 |
||
1811 | */ |
||
1812 | public function customize_pane_settings() { |
||
1928 | |||
1929 | /** |
||
1930 | * Returns a list of devices to allow previewing. |
||
1931 | * |
||
1932 | * @access public |
||
1933 | * @since 4.5.0 |
||
1934 | * |
||
1935 | * @return array List of devices with labels and default setting. |
||
1936 | */ |
||
1937 | public function get_previewable_devices() { |
||
1938 | $devices = array( |
||
1939 | 'desktop' => array( |
||
1940 | 'label' => __( 'Enter desktop preview mode' ), |
||
1941 | 'default' => true, |
||
1942 | ), |
||
1943 | 'tablet' => array( |
||
1944 | 'label' => __( 'Enter tablet preview mode' ), |
||
1945 | ), |
||
1946 | 'mobile' => array( |
||
1947 | 'label' => __( 'Enter mobile preview mode' ), |
||
1948 | ), |
||
1949 | ); |
||
1950 | |||
1951 | /** |
||
1952 | * Filters the available devices to allow previewing in the Customizer. |
||
1953 | * |
||
1954 | * @since 4.5.0 |
||
1955 | * |
||
1956 | * @see WP_Customize_Manager::get_previewable_devices() |
||
1957 | * |
||
1958 | * @param array $devices List of devices with labels and default setting. |
||
1959 | */ |
||
1960 | $devices = apply_filters( 'customize_previewable_devices', $devices ); |
||
1961 | |||
1962 | return $devices; |
||
1963 | } |
||
1964 | |||
1965 | /** |
||
1966 | * Register some default controls. |
||
1967 | * |
||
1968 | * @since 3.4.0 |
||
1969 | */ |
||
1970 | public function register_controls() { |
||
2320 | |||
2321 | /** |
||
2322 | * Add settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets |
||
2323 | * |
||
2324 | * @since 4.2.0 |
||
2325 | * @access public |
||
2326 | * |
||
2327 | * @see add_dynamic_settings() |
||
2328 | */ |
||
2329 | public function register_dynamic_settings() { |
||
2332 | |||
2333 | /** |
||
2334 | * Callback for validating the header_textcolor value. |
||
2335 | * |
||
2336 | * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash(). |
||
2337 | * Returns default text color if hex color is empty. |
||
2338 | * |
||
2339 | * @since 3.4.0 |
||
2340 | * |
||
2341 | * @param string $color |
||
2342 | * @return mixed |
||
2343 | */ |
||
2344 | public function _sanitize_header_textcolor( $color ) { |
||
2354 | |||
2355 | /** |
||
2356 | * Callback for rendering the custom logo, used in the custom_logo partial. |
||
2357 | * |
||
2358 | * This method exists because the partial object and context data are passed |
||
2359 | * into a partial's render_callback so we cannot use get_custom_logo() as |
||
2360 | * the render_callback directly since it expects a blog ID as the first |
||
2361 | * argument. When WP no longer supports PHP 5.3, this method can be removed |
||
2362 | * in favor of an anonymous function. |
||
2363 | * |
||
2364 | * @see WP_Customize_Manager::register_controls() |
||
2365 | * |
||
2366 | * @since 4.5.0 |
||
2367 | * @access private |
||
2368 | * |
||
2369 | * @return string Custom logo. |
||
2370 | */ |
||
2371 | public function _render_custom_logo_partial() { |
||
2374 | } |
||
2375 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: