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', 'selective_refresh' ); |
||
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() { |
||
308 | |||
309 | /** |
||
310 | * Return true if it's an AJAX request. |
||
311 | * |
||
312 | * @since 3.4.0 |
||
313 | * @since 4.2.0 Added `$action` param. |
||
314 | * @access public |
||
315 | * |
||
316 | * @param string|null $action Whether the supplied AJAX action is being run. |
||
317 | * @return bool True if it's an AJAX request, false otherwise. |
||
318 | */ |
||
319 | public function doing_ajax( $action = null ) { |
||
335 | |||
336 | /** |
||
337 | * Custom wp_die wrapper. Returns either the standard message for UI |
||
338 | * or the AJAX message. |
||
339 | * |
||
340 | * @since 3.4.0 |
||
341 | * |
||
342 | * @param mixed $ajax_message AJAX return |
||
343 | * @param mixed $message UI message |
||
344 | */ |
||
345 | protected function wp_die( $ajax_message, $message = null ) { |
||
356 | |||
357 | /** |
||
358 | * Return the AJAX wp_die() handler if it's a customized request. |
||
359 | * |
||
360 | * @since 3.4.0 |
||
361 | * |
||
362 | * @return string |
||
363 | */ |
||
364 | public function wp_die_handler() { |
||
371 | |||
372 | /** |
||
373 | * Start preview and customize theme. |
||
374 | * |
||
375 | * Check if customize query variable exist. Init filters to filter the current theme. |
||
376 | * |
||
377 | * @since 3.4.0 |
||
378 | */ |
||
379 | public function setup_theme() { |
||
422 | |||
423 | /** |
||
424 | * Callback to validate a theme once it is loaded |
||
425 | * |
||
426 | * @since 3.4.0 |
||
427 | */ |
||
428 | public function after_setup_theme() { |
||
435 | |||
436 | /** |
||
437 | * If the theme to be previewed isn't the active theme, add filter callbacks |
||
438 | * to swap it out at runtime. |
||
439 | * |
||
440 | * @since 3.4.0 |
||
441 | */ |
||
442 | View Code Duplication | public function start_previewing_theme() { |
|
473 | |||
474 | /** |
||
475 | * Stop previewing the selected theme. |
||
476 | * |
||
477 | * Removes filters to change the current theme. |
||
478 | * |
||
479 | * @since 3.4.0 |
||
480 | */ |
||
481 | View Code Duplication | public function stop_previewing_theme() { |
|
511 | |||
512 | /** |
||
513 | * Get the theme being customized. |
||
514 | * |
||
515 | * @since 3.4.0 |
||
516 | * |
||
517 | * @return WP_Theme |
||
518 | */ |
||
519 | public function theme() { |
||
525 | |||
526 | /** |
||
527 | * Get the registered settings. |
||
528 | * |
||
529 | * @since 3.4.0 |
||
530 | * |
||
531 | * @return array |
||
532 | */ |
||
533 | public function settings() { |
||
536 | |||
537 | /** |
||
538 | * Get the registered controls. |
||
539 | * |
||
540 | * @since 3.4.0 |
||
541 | * |
||
542 | * @return array |
||
543 | */ |
||
544 | public function controls() { |
||
547 | |||
548 | /** |
||
549 | * Get the registered containers. |
||
550 | * |
||
551 | * @since 4.0.0 |
||
552 | * |
||
553 | * @return array |
||
554 | */ |
||
555 | public function containers() { |
||
558 | |||
559 | /** |
||
560 | * Get the registered sections. |
||
561 | * |
||
562 | * @since 3.4.0 |
||
563 | * |
||
564 | * @return array |
||
565 | */ |
||
566 | public function sections() { |
||
569 | |||
570 | /** |
||
571 | * Get the registered panels. |
||
572 | * |
||
573 | * @since 4.0.0 |
||
574 | * @access public |
||
575 | * |
||
576 | * @return array Panels. |
||
577 | */ |
||
578 | public function panels() { |
||
581 | |||
582 | /** |
||
583 | * Checks if the current theme is active. |
||
584 | * |
||
585 | * @since 3.4.0 |
||
586 | * |
||
587 | * @return bool |
||
588 | */ |
||
589 | public function is_theme_active() { |
||
592 | |||
593 | /** |
||
594 | * Register styles/scripts and initialize the preview of each setting |
||
595 | * |
||
596 | * @since 3.4.0 |
||
597 | */ |
||
598 | public function wp_loaded() { |
||
612 | |||
613 | /** |
||
614 | * Prevents AJAX requests from following redirects when previewing a theme |
||
615 | * by issuing a 200 response instead of a 30x. |
||
616 | * |
||
617 | * Instead, the JS will sniff out the location header. |
||
618 | * |
||
619 | * @since 3.4.0 |
||
620 | * |
||
621 | * @param $status |
||
622 | * @return int |
||
623 | */ |
||
624 | public function wp_redirect_status( $status ) { |
||
630 | |||
631 | /** |
||
632 | * Parse the incoming $_POST['customized'] JSON data and store the unsanitized |
||
633 | * settings for subsequent post_value() lookups. |
||
634 | * |
||
635 | * @since 4.1.1 |
||
636 | * |
||
637 | * @return array |
||
638 | */ |
||
639 | public function unsanitized_post_values() { |
||
654 | |||
655 | /** |
||
656 | * Return the sanitized value for a given setting from the request's POST data. |
||
657 | * |
||
658 | * @since 3.4.0 |
||
659 | * @since 4.1.1 Introduced 'default' parameter. |
||
660 | * |
||
661 | * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object |
||
662 | * @param mixed $default value returned $setting has no post value (added in 4.2.0). |
||
663 | * @return string|mixed $post_value Sanitized value or the $default provided |
||
664 | */ |
||
665 | public function post_value( $setting, $default = null ) { |
||
673 | |||
674 | /** |
||
675 | * Override a setting's (unsanitized) value as found in any incoming $_POST['customized']. |
||
676 | * |
||
677 | * @since 4.2.0 |
||
678 | * @access public |
||
679 | * |
||
680 | * @param string $setting_id ID for the WP_Customize_Setting instance. |
||
681 | * @param mixed $value Post value. |
||
682 | */ |
||
683 | public function set_post_value( $setting_id, $value ) { |
||
717 | |||
718 | /** |
||
719 | * Print JavaScript settings. |
||
720 | * |
||
721 | * @since 3.4.0 |
||
722 | */ |
||
723 | public function customize_preview_init() { |
||
751 | |||
752 | /** |
||
753 | * Prevent sending a 404 status when returning the response for the customize |
||
754 | * preview, since it causes the jQuery AJAX to fail. Send 200 instead. |
||
755 | * |
||
756 | * @since 4.0.0 |
||
757 | * @access public |
||
758 | */ |
||
759 | public function customize_preview_override_404_status() { |
||
764 | |||
765 | /** |
||
766 | * Print base element for preview frame. |
||
767 | * |
||
768 | * @since 3.4.0 |
||
769 | */ |
||
770 | public function customize_preview_base() { |
||
773 | |||
774 | /** |
||
775 | * Print a workaround to handle HTML5 tags in IE < 9. |
||
776 | * |
||
777 | * @since 3.4.0 |
||
778 | */ |
||
779 | public function customize_preview_html5() { ?> |
||
791 | |||
792 | /** |
||
793 | * Print CSS for loading indicators for the Customizer preview. |
||
794 | * |
||
795 | * @since 4.2.0 |
||
796 | * @access public |
||
797 | */ |
||
798 | public function customize_preview_loading_style() { |
||
811 | |||
812 | /** |
||
813 | * Print JavaScript settings for preview frame. |
||
814 | * |
||
815 | * @since 3.4.0 |
||
816 | */ |
||
817 | public function customize_preview_settings() { |
||
883 | |||
884 | /** |
||
885 | * Prints a signature so we can ensure the Customizer was properly executed. |
||
886 | * |
||
887 | * @since 3.4.0 |
||
888 | */ |
||
889 | public function customize_preview_signature() { |
||
892 | |||
893 | /** |
||
894 | * Removes the signature in case we experience a case where the Customizer was not properly executed. |
||
895 | * |
||
896 | * @since 3.4.0 |
||
897 | * |
||
898 | * @param mixed $return Value passed through for wp_die_handler filter. |
||
899 | * @return mixed Value passed through for wp_die_handler filter. |
||
900 | */ |
||
901 | public function remove_preview_signature( $return = null ) { |
||
906 | |||
907 | /** |
||
908 | * Is it a theme preview? |
||
909 | * |
||
910 | * @since 3.4.0 |
||
911 | * |
||
912 | * @return bool True if it's a preview, false if not. |
||
913 | */ |
||
914 | public function is_preview() { |
||
917 | |||
918 | /** |
||
919 | * Retrieve the template name of the previewed theme. |
||
920 | * |
||
921 | * @since 3.4.0 |
||
922 | * |
||
923 | * @return string Template name. |
||
924 | */ |
||
925 | public function get_template() { |
||
928 | |||
929 | /** |
||
930 | * Retrieve the stylesheet name of the previewed theme. |
||
931 | * |
||
932 | * @since 3.4.0 |
||
933 | * |
||
934 | * @return string Stylesheet name. |
||
935 | */ |
||
936 | public function get_stylesheet() { |
||
939 | |||
940 | /** |
||
941 | * Retrieve the template root of the previewed theme. |
||
942 | * |
||
943 | * @since 3.4.0 |
||
944 | * |
||
945 | * @return string Theme root. |
||
946 | */ |
||
947 | public function get_template_root() { |
||
950 | |||
951 | /** |
||
952 | * Retrieve the stylesheet root of the previewed theme. |
||
953 | * |
||
954 | * @since 3.4.0 |
||
955 | * |
||
956 | * @return string Theme root. |
||
957 | */ |
||
958 | public function get_stylesheet_root() { |
||
961 | |||
962 | /** |
||
963 | * Filter the current theme and return the name of the previewed theme. |
||
964 | * |
||
965 | * @since 3.4.0 |
||
966 | * |
||
967 | * @param $current_theme {@internal Parameter is not used} |
||
968 | * @return string Theme name. |
||
969 | */ |
||
970 | public function current_theme( $current_theme ) { |
||
973 | |||
974 | /** |
||
975 | * Switch the theme and trigger the save() method on each setting. |
||
976 | * |
||
977 | * @since 3.4.0 |
||
978 | */ |
||
979 | public function save() { |
||
1036 | |||
1037 | /** |
||
1038 | * Refresh nonces for the current preview. |
||
1039 | * |
||
1040 | * @since 4.2.0 |
||
1041 | */ |
||
1042 | public function refresh_nonces() { |
||
1049 | |||
1050 | /** |
||
1051 | * Add a customize setting. |
||
1052 | * |
||
1053 | * @since 3.4.0 |
||
1054 | * @since 4.5.0 Return added WP_Customize_Setting instance. |
||
1055 | * @access public |
||
1056 | * |
||
1057 | * @param WP_Customize_Setting|string $id Customize Setting object, or ID. |
||
1058 | * @param array $args Setting arguments; passed to WP_Customize_Setting |
||
1059 | * constructor. |
||
1060 | * @return WP_Customize_Setting The instance of the setting that was added. |
||
1061 | */ |
||
1062 | public function add_setting( $id, $args = array() ) { |
||
1080 | |||
1081 | /** |
||
1082 | * Register any dynamically-created settings, such as those from $_POST['customized'] |
||
1083 | * that have no corresponding setting created. |
||
1084 | * |
||
1085 | * This is a mechanism to "wake up" settings that have been dynamically created |
||
1086 | * on the front end and have been sent to WordPress in `$_POST['customized']`. When WP |
||
1087 | * loads, the dynamically-created settings then will get created and previewed |
||
1088 | * even though they are not directly created statically with code. |
||
1089 | * |
||
1090 | * @since 4.2.0 |
||
1091 | * @access public |
||
1092 | * |
||
1093 | * @param array $setting_ids The setting IDs to add. |
||
1094 | * @return array The WP_Customize_Setting objects added. |
||
1095 | */ |
||
1096 | public function add_dynamic_settings( $setting_ids ) { |
||
1142 | |||
1143 | /** |
||
1144 | * Retrieve a customize setting. |
||
1145 | * |
||
1146 | * @since 3.4.0 |
||
1147 | * |
||
1148 | * @param string $id Customize Setting ID. |
||
1149 | * @return WP_Customize_Setting|void The setting, if set. |
||
1150 | */ |
||
1151 | public function get_setting( $id ) { |
||
1156 | |||
1157 | /** |
||
1158 | * Remove a customize setting. |
||
1159 | * |
||
1160 | * @since 3.4.0 |
||
1161 | * |
||
1162 | * @param string $id Customize Setting ID. |
||
1163 | */ |
||
1164 | public function remove_setting( $id ) { |
||
1167 | |||
1168 | /** |
||
1169 | * Add a customize panel. |
||
1170 | * |
||
1171 | * @since 4.0.0 |
||
1172 | * @since 4.5.0 Return added WP_Customize_Panel instance. |
||
1173 | * @access public |
||
1174 | * |
||
1175 | * @param WP_Customize_Panel|string $id Customize Panel object, or Panel ID. |
||
1176 | * @param array $args Optional. Panel arguments. Default empty array. |
||
1177 | * |
||
1178 | * @return WP_Customize_Panel The instance of the panel that was added. |
||
1179 | */ |
||
1180 | public function add_panel( $id, $args = array() ) { |
||
1190 | |||
1191 | /** |
||
1192 | * Retrieve a customize panel. |
||
1193 | * |
||
1194 | * @since 4.0.0 |
||
1195 | * @access public |
||
1196 | * |
||
1197 | * @param string $id Panel ID to get. |
||
1198 | * @return WP_Customize_Panel|void Requested panel instance, if set. |
||
1199 | */ |
||
1200 | public function get_panel( $id ) { |
||
1205 | |||
1206 | /** |
||
1207 | * Remove a customize panel. |
||
1208 | * |
||
1209 | * @since 4.0.0 |
||
1210 | * @access public |
||
1211 | * |
||
1212 | * @param string $id Panel ID to remove. |
||
1213 | */ |
||
1214 | public function remove_panel( $id ) { |
||
1227 | |||
1228 | /** |
||
1229 | * Register a customize panel type. |
||
1230 | * |
||
1231 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1232 | * |
||
1233 | * @since 4.3.0 |
||
1234 | * @access public |
||
1235 | * |
||
1236 | * @see WP_Customize_Panel |
||
1237 | * |
||
1238 | * @param string $panel Name of a custom panel which is a subclass of WP_Customize_Panel. |
||
1239 | */ |
||
1240 | public function register_panel_type( $panel ) { |
||
1243 | |||
1244 | /** |
||
1245 | * Render JS templates for all registered panel types. |
||
1246 | * |
||
1247 | * @since 4.3.0 |
||
1248 | * @access public |
||
1249 | */ |
||
1250 | public function render_panel_templates() { |
||
1256 | |||
1257 | /** |
||
1258 | * Add a customize section. |
||
1259 | * |
||
1260 | * @since 3.4.0 |
||
1261 | * @since 4.5.0 Return added WP_Customize_Section instance. |
||
1262 | * @access public |
||
1263 | * |
||
1264 | * @param WP_Customize_Section|string $id Customize Section object, or Section ID. |
||
1265 | * @param array $args Section arguments. |
||
1266 | * |
||
1267 | * @return WP_Customize_Section The instance of the section that was added. |
||
1268 | */ |
||
1269 | public function add_section( $id, $args = array() ) { |
||
1279 | |||
1280 | /** |
||
1281 | * Retrieve a customize section. |
||
1282 | * |
||
1283 | * @since 3.4.0 |
||
1284 | * |
||
1285 | * @param string $id Section ID. |
||
1286 | * @return WP_Customize_Section|void The section, if set. |
||
1287 | */ |
||
1288 | public function get_section( $id ) { |
||
1292 | |||
1293 | /** |
||
1294 | * Remove a customize section. |
||
1295 | * |
||
1296 | * @since 3.4.0 |
||
1297 | * |
||
1298 | * @param string $id Section ID. |
||
1299 | */ |
||
1300 | public function remove_section( $id ) { |
||
1303 | |||
1304 | /** |
||
1305 | * Register a customize section type. |
||
1306 | * |
||
1307 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1308 | * |
||
1309 | * @since 4.3.0 |
||
1310 | * @access public |
||
1311 | * |
||
1312 | * @see WP_Customize_Section |
||
1313 | * |
||
1314 | * @param string $section Name of a custom section which is a subclass of WP_Customize_Section. |
||
1315 | */ |
||
1316 | public function register_section_type( $section ) { |
||
1319 | |||
1320 | /** |
||
1321 | * Render JS templates for all registered section types. |
||
1322 | * |
||
1323 | * @since 4.3.0 |
||
1324 | * @access public |
||
1325 | */ |
||
1326 | public function render_section_templates() { |
||
1332 | |||
1333 | /** |
||
1334 | * Add a customize control. |
||
1335 | * |
||
1336 | * @since 3.4.0 |
||
1337 | * @since 4.5.0 Return added WP_Customize_Control instance. |
||
1338 | * @access public |
||
1339 | * |
||
1340 | * @param WP_Customize_Control|string $id Customize Control object, or ID. |
||
1341 | * @param array $args Control arguments; passed to WP_Customize_Control |
||
1342 | * constructor. |
||
1343 | * @return WP_Customize_Control The instance of the control that was added. |
||
1344 | */ |
||
1345 | public function add_control( $id, $args = array() ) { |
||
1355 | |||
1356 | /** |
||
1357 | * Retrieve a customize control. |
||
1358 | * |
||
1359 | * @since 3.4.0 |
||
1360 | * |
||
1361 | * @param string $id ID of the control. |
||
1362 | * @return WP_Customize_Control|void The control object, if set. |
||
1363 | */ |
||
1364 | public function get_control( $id ) { |
||
1368 | |||
1369 | /** |
||
1370 | * Remove a customize control. |
||
1371 | * |
||
1372 | * @since 3.4.0 |
||
1373 | * |
||
1374 | * @param string $id ID of the control. |
||
1375 | */ |
||
1376 | public function remove_control( $id ) { |
||
1379 | |||
1380 | /** |
||
1381 | * Register a customize control type. |
||
1382 | * |
||
1383 | * Registered types are eligible to be rendered via JS and created dynamically. |
||
1384 | * |
||
1385 | * @since 4.1.0 |
||
1386 | * @access public |
||
1387 | * |
||
1388 | * @param string $control Name of a custom control which is a subclass of |
||
1389 | * {@see WP_Customize_Control}. |
||
1390 | */ |
||
1391 | public function register_control_type( $control ) { |
||
1394 | |||
1395 | /** |
||
1396 | * Render JS templates for all registered control types. |
||
1397 | * |
||
1398 | * @since 4.1.0 |
||
1399 | * @access public |
||
1400 | */ |
||
1401 | public function render_control_templates() { |
||
1409 | |||
1410 | /** |
||
1411 | * Helper function to compare two objects by priority, ensuring sort stability via instance_number. |
||
1412 | * |
||
1413 | * @since 3.4.0 |
||
1414 | * |
||
1415 | * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $a Object A. |
||
1416 | * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $b Object B. |
||
1417 | * @return int |
||
1418 | */ |
||
1419 | protected function _cmp_priority( $a, $b ) { |
||
1426 | |||
1427 | /** |
||
1428 | * Prepare panels, sections, and controls. |
||
1429 | * |
||
1430 | * For each, check if required related components exist, |
||
1431 | * whether the user has the necessary capabilities, |
||
1432 | * and sort by priority. |
||
1433 | * |
||
1434 | * @since 3.4.0 |
||
1435 | */ |
||
1436 | public function prepare_controls() { |
||
1492 | |||
1493 | /** |
||
1494 | * Enqueue scripts for customize controls. |
||
1495 | * |
||
1496 | * @since 3.4.0 |
||
1497 | */ |
||
1498 | public function enqueue_control_scripts() { |
||
1503 | |||
1504 | /** |
||
1505 | * Determine whether the user agent is iOS. |
||
1506 | * |
||
1507 | * @since 4.4.0 |
||
1508 | * @access public |
||
1509 | * |
||
1510 | * @return bool Whether the user agent is iOS. |
||
1511 | */ |
||
1512 | public function is_ios() { |
||
1515 | |||
1516 | /** |
||
1517 | * Get the template string for the Customizer pane document title. |
||
1518 | * |
||
1519 | * @since 4.4.0 |
||
1520 | * @access public |
||
1521 | * |
||
1522 | * @return string The template string for the document title. |
||
1523 | */ |
||
1524 | public function get_document_title_template() { |
||
1535 | |||
1536 | /** |
||
1537 | * Set the initial URL to be previewed. |
||
1538 | * |
||
1539 | * URL is validated. |
||
1540 | * |
||
1541 | * @since 4.4.0 |
||
1542 | * @access public |
||
1543 | * |
||
1544 | * @param string $preview_url URL to be previewed. |
||
1545 | */ |
||
1546 | public function set_preview_url( $preview_url ) { |
||
1549 | |||
1550 | /** |
||
1551 | * Get the initial URL to be previewed. |
||
1552 | * |
||
1553 | * @since 4.4.0 |
||
1554 | * @access public |
||
1555 | * |
||
1556 | * @return string URL being previewed. |
||
1557 | */ |
||
1558 | public function get_preview_url() { |
||
1566 | |||
1567 | /** |
||
1568 | * Set URL to link the user to when closing the Customizer. |
||
1569 | * |
||
1570 | * URL is validated. |
||
1571 | * |
||
1572 | * @since 4.4.0 |
||
1573 | * @access public |
||
1574 | * |
||
1575 | * @param string $return_url URL for return link. |
||
1576 | */ |
||
1577 | public function set_return_url( $return_url ) { |
||
1582 | |||
1583 | /** |
||
1584 | * Get URL to link the user to when closing the Customizer. |
||
1585 | * |
||
1586 | * @since 4.4.0 |
||
1587 | * @access public |
||
1588 | * |
||
1589 | * @return string URL for link to close Customizer. |
||
1590 | */ |
||
1591 | public function get_return_url() { |
||
1606 | |||
1607 | /** |
||
1608 | * Set the autofocused constructs. |
||
1609 | * |
||
1610 | * @since 4.4.0 |
||
1611 | * @access public |
||
1612 | * |
||
1613 | * @param array $autofocus { |
||
1614 | * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused. |
||
1615 | * |
||
1616 | * @type string [$control] ID for control to be autofocused. |
||
1617 | * @type string [$section] ID for section to be autofocused. |
||
1618 | * @type string [$panel] ID for panel to be autofocused. |
||
1619 | * } |
||
1620 | */ |
||
1621 | public function set_autofocus( $autofocus ) { |
||
1624 | |||
1625 | /** |
||
1626 | * Get the autofocused constructs. |
||
1627 | * |
||
1628 | * @since 4.4.0 |
||
1629 | * @access public |
||
1630 | * |
||
1631 | * @return array { |
||
1632 | * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused. |
||
1633 | * |
||
1634 | * @type string [$control] ID for control to be autofocused. |
||
1635 | * @type string [$section] ID for section to be autofocused. |
||
1636 | * @type string [$panel] ID for panel to be autofocused. |
||
1637 | * } |
||
1638 | */ |
||
1639 | public function get_autofocus() { |
||
1642 | |||
1643 | /** |
||
1644 | * Get nonces for the Customizer. |
||
1645 | * |
||
1646 | * @since 4.5.0 |
||
1647 | * @return array Nonces. |
||
1648 | */ |
||
1649 | public function get_nonces() { |
||
1650 | $nonces = array( |
||
1651 | 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), |
||
1652 | 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), |
||
1653 | ); |
||
1654 | |||
1655 | /** |
||
1656 | * Filter nonces for Customizer. |
||
1657 | * |
||
1658 | * @since 4.2.0 |
||
1659 | * |
||
1660 | * @param array $nonces Array of refreshed nonces for save and |
||
1661 | * preview actions. |
||
1662 | * @param WP_Customize_Manager $this WP_Customize_Manager instance. |
||
1663 | */ |
||
1664 | $nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this ); |
||
1665 | |||
1666 | return $nonces; |
||
1667 | } |
||
1668 | |||
1669 | /** |
||
1670 | * Print JavaScript settings for parent window. |
||
1671 | * |
||
1672 | * @since 4.4.0 |
||
1673 | */ |
||
1674 | public function customize_pane_settings() { |
||
1795 | |||
1796 | /** |
||
1797 | * Returns a list of devices to allow previewing. |
||
1798 | * |
||
1799 | * @access public |
||
1800 | * @since 4.5.0 |
||
1801 | * |
||
1802 | * @return array List of devices with labels and default setting. |
||
1803 | */ |
||
1804 | public function get_previewable_devices() { |
||
1805 | $devices = array( |
||
1806 | 'desktop' => array( |
||
1807 | 'label' => __( 'Enter desktop preview mode' ), |
||
1808 | 'default' => true, |
||
1809 | ), |
||
1810 | 'tablet' => array( |
||
1811 | 'label' => __( 'Enter tablet preview mode' ), |
||
1812 | ), |
||
1813 | 'mobile' => array( |
||
1814 | 'label' => __( 'Enter mobile preview mode' ), |
||
1815 | ), |
||
1816 | ); |
||
1817 | |||
1818 | /** |
||
1819 | * Filter the available devices to allow previewing in the Customizer. |
||
1820 | * |
||
1821 | * @since 4.5.0 |
||
1822 | * |
||
1823 | * @see WP_Customize_Manager::get_previewable_devices() |
||
1824 | * |
||
1825 | * @param array $devices List of devices with labels and default setting. |
||
1826 | */ |
||
1827 | $devices = apply_filters( 'customize_previewable_devices', $devices ); |
||
1828 | |||
1829 | return $devices; |
||
1830 | } |
||
1831 | |||
1832 | /** |
||
1833 | * Register some default controls. |
||
1834 | * |
||
1835 | * @since 3.4.0 |
||
1836 | */ |
||
1837 | public function register_controls() { |
||
2185 | |||
2186 | /** |
||
2187 | * Add settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets |
||
2188 | * |
||
2189 | * @since 4.2.0 |
||
2190 | * @access public |
||
2191 | * |
||
2192 | * @see add_dynamic_settings() |
||
2193 | */ |
||
2194 | public function register_dynamic_settings() { |
||
2197 | |||
2198 | /** |
||
2199 | * Callback for validating the header_textcolor value. |
||
2200 | * |
||
2201 | * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash(). |
||
2202 | * Returns default text color if hex color is empty. |
||
2203 | * |
||
2204 | * @since 3.4.0 |
||
2205 | * |
||
2206 | * @param string $color |
||
2207 | * @return mixed |
||
2208 | */ |
||
2209 | public function _sanitize_header_textcolor( $color ) { |
||
2219 | |||
2220 | /** |
||
2221 | * Callback for rendering the custom logo, used in the custom_logo partial. |
||
2222 | * |
||
2223 | * This method exists because the partial object and context data are passed |
||
2224 | * into a partial's render_callback so we cannot use get_custom_logo() as |
||
2225 | * the render_callback directly since it expects a blog ID as the first |
||
2226 | * argument. When WP no longer supports PHP 5.3, this method can be removed |
||
2227 | * in favor of an anonymous function. |
||
2228 | * |
||
2229 | * @see WP_Customize_Manager::register_controls() |
||
2230 | * |
||
2231 | * @since 4.5.0 |
||
2232 | * @access private |
||
2233 | * |
||
2234 | * @return string Custom logo. |
||
2235 | */ |
||
2236 | public function _render_custom_logo_partial() { |
||
2239 | } |
||
2240 | |||
2301 |
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: