author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
5 | 3 |
* WordPress Customize Control classes |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Customize |
|
7 |
* @since 3.4.0 |
|
8 |
*/ |
|
5 | 9 |
|
10 |
/** |
|
11 |
* Customize Control class. |
|
12 |
* |
|
13 |
* @since 3.4.0 |
|
14 |
*/ |
|
0 | 15 |
class WP_Customize_Control { |
5 | 16 |
|
17 |
/** |
|
18 |
* Incremented with each new class instantiation, then stored in $instance_number. |
|
19 |
* |
|
20 |
* Used when sorting two instances whose priorities are equal. |
|
21 |
* |
|
22 |
* @since 4.1.0 |
|
23 |
* @var int |
|
24 |
*/ |
|
25 |
protected static $instance_count = 0; |
|
26 |
||
27 |
/** |
|
28 |
* Order in which this instance was created in relation to other instances. |
|
29 |
* |
|
30 |
* @since 4.1.0 |
|
31 |
* @var int |
|
32 |
*/ |
|
33 |
public $instance_number; |
|
34 |
||
0 | 35 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* Customizer manager. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* @since 3.4.0 |
0 | 39 |
* @var WP_Customize_Manager |
40 |
*/ |
|
41 |
public $manager; |
|
42 |
||
43 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
* Control ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* @since 3.4.0 |
0 | 47 |
* @var string |
48 |
*/ |
|
49 |
public $id; |
|
50 |
||
51 |
/** |
|
52 |
* All settings tied to the control. |
|
53 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* @since 3.4.0 |
0 | 55 |
* @var array |
56 |
*/ |
|
57 |
public $settings; |
|
58 |
||
59 |
/** |
|
60 |
* The primary setting for the control (if there is one). |
|
61 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* @since 3.4.0 |
18 | 63 |
* @var string|WP_Customize_Setting|null |
0 | 64 |
*/ |
65 |
public $setting = 'default'; |
|
66 |
||
67 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* Capability required to use this control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* Normally this is empty and the capability is derived from the capabilities |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* of the associated `$settings`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
public $capability; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* Order priority to load the control in Customizer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* @since 3.4.0 |
0 | 82 |
* @var int |
83 |
*/ |
|
5 | 84 |
public $priority = 10; |
0 | 85 |
|
86 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* Section the control belongs to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* @since 3.4.0 |
0 | 90 |
* @var string |
91 |
*/ |
|
5 | 92 |
public $section = ''; |
0 | 93 |
|
94 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
* Label for the control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* @since 3.4.0 |
0 | 98 |
* @var string |
99 |
*/ |
|
5 | 100 |
public $label = ''; |
101 |
||
102 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* Description for the control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* @since 4.0.0 |
5 | 106 |
* @var string |
107 |
*/ |
|
108 |
public $description = ''; |
|
0 | 109 |
|
110 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values. |
0 | 112 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
* @since 3.4.0 |
0 | 114 |
* @var array |
115 |
*/ |
|
5 | 116 |
public $choices = array(); |
0 | 117 |
|
118 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* List of custom input attributes for control output, where attribute names are the keys and values are the values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @since 4.0.0 |
0 | 124 |
* @var array |
125 |
*/ |
|
5 | 126 |
public $input_attrs = array(); |
127 |
||
128 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* Show UI for adding new content, currently only used for the dropdown-pages control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
public $allow_addition = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
/** |
5 | 137 |
* @deprecated It is better to just call the json() method |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* @since 3.4.0 |
5 | 139 |
* @var array |
140 |
*/ |
|
0 | 141 |
public $json = array(); |
142 |
||
143 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* Control's Type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @since 3.4.0 |
0 | 147 |
* @var string |
148 |
*/ |
|
149 |
public $type = 'text'; |
|
150 |
||
5 | 151 |
/** |
152 |
* Callback. |
|
153 |
* |
|
154 |
* @since 4.0.0 |
|
155 |
* |
|
156 |
* @see WP_Customize_Control::active() |
|
157 |
* |
|
158 |
* @var callable Callback is called with one argument, the instance of |
|
159 |
* WP_Customize_Control, and returns bool to indicate whether |
|
160 |
* the control is active (such as it relates to the URL |
|
161 |
* currently being previewed). |
|
162 |
*/ |
|
163 |
public $active_callback = ''; |
|
0 | 164 |
|
165 |
/** |
|
166 |
* Constructor. |
|
167 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* Supplied `$args` override class property defaults. |
5 | 169 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* If `$args['settings']` is not defined, use the $id as the setting ID. |
0 | 171 |
* |
172 |
* @since 3.4.0 |
|
173 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @param WP_Customize_Manager $manager Customizer bootstrap instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* @param string $id Control ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* @param array $args { |
16 | 177 |
* Optional. Array of properties for the new Control object. Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* @type int $instance_number Order in which this instance was created in relation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* to other instances. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* @type WP_Customize_Manager $manager Customizer bootstrap instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
* @type string $id Control ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* @type array $settings All settings tied to the control. If undefined, `$id` will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
* be used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
* @type string $setting The primary setting for the control (if there is one). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* Default 'default'. |
16 | 187 |
* @type string $capability Capability required to use this control. Normally this is empty |
188 |
* and the capability is derived from `$settings`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* @type int $priority Order priority to load the control. Default 10. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* @type string $section Section the control belongs to. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* @type string $label Label for the control. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* @type string $description Description for the control. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* @type array $choices List of choices for 'radio' or 'select' type controls, where |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* values are the keys, and labels are the values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* @type array $input_attrs List of custom input attributes for control output, where |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* attribute names are the keys and values are the values. Not |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* used for 'checkbox', 'radio', 'select', 'textarea', or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* 'dropdown-pages' control types. Default empty array. |
16 | 200 |
* @type bool $allow_addition Show UI for adding new content, currently only used for the |
201 |
* dropdown-pages control. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* @type array $json Deprecated. Use WP_Customize_Control::json() instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* @type string $type Control type. Core controls include 'text', 'checkbox', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
* 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* input types such as 'email', 'url', 'number', 'hidden', and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* 'date' are supported implicitly. Default 'text'. |
16 | 207 |
* @type callable $active_callback Active callback. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
* } |
0 | 209 |
*/ |
5 | 210 |
public function __construct( $manager, $id, $args = array() ) { |
0 | 211 |
$keys = array_keys( get_object_vars( $this ) ); |
212 |
foreach ( $keys as $key ) { |
|
5 | 213 |
if ( isset( $args[ $key ] ) ) { |
0 | 214 |
$this->$key = $args[ $key ]; |
5 | 215 |
} |
0 | 216 |
} |
217 |
||
218 |
$this->manager = $manager; |
|
9 | 219 |
$this->id = $id; |
5 | 220 |
if ( empty( $this->active_callback ) ) { |
221 |
$this->active_callback = array( $this, 'active_callback' ); |
|
222 |
} |
|
223 |
self::$instance_count += 1; |
|
224 |
$this->instance_number = self::$instance_count; |
|
0 | 225 |
|
226 |
// Process settings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
if ( ! isset( $this->settings ) ) { |
0 | 228 |
$this->settings = $id; |
5 | 229 |
} |
0 | 230 |
|
231 |
$settings = array(); |
|
232 |
if ( is_array( $this->settings ) ) { |
|
233 |
foreach ( $this->settings as $key => $setting ) { |
|
234 |
$settings[ $key ] = $this->manager->get_setting( $setting ); |
|
235 |
} |
|
9 | 236 |
} elseif ( is_string( $this->settings ) ) { |
237 |
$this->setting = $this->manager->get_setting( $this->settings ); |
|
0 | 238 |
$settings['default'] = $this->setting; |
239 |
} |
|
240 |
$this->settings = $settings; |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Enqueue control related scripts/styles. |
|
245 |
* |
|
246 |
* @since 3.4.0 |
|
247 |
*/ |
|
248 |
public function enqueue() {} |
|
249 |
||
5 | 250 |
/** |
251 |
* Check whether control is active to current Customizer preview. |
|
252 |
* |
|
253 |
* @since 4.0.0 |
|
254 |
* |
|
255 |
* @return bool Whether the control is active to the current preview. |
|
256 |
*/ |
|
257 |
final public function active() { |
|
258 |
$control = $this; |
|
9 | 259 |
$active = call_user_func( $this->active_callback, $this ); |
5 | 260 |
|
261 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
* Filters response of WP_Customize_Control::active(). |
5 | 263 |
* |
264 |
* @since 4.0.0 |
|
265 |
* |
|
266 |
* @param bool $active Whether the Customizer control is active. |
|
267 |
* @param WP_Customize_Control $control WP_Customize_Control instance. |
|
268 |
*/ |
|
269 |
$active = apply_filters( 'customize_control_active', $active, $control ); |
|
270 |
||
271 |
return $active; |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Default callback used when invoking WP_Customize_Control::active(). |
|
276 |
* |
|
277 |
* Subclasses can override this with their specific logic, or they may |
|
278 |
* provide an 'active_callback' argument to the constructor. |
|
279 |
* |
|
280 |
* @since 4.0.0 |
|
281 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
* @return true Always true. |
5 | 283 |
*/ |
284 |
public function active_callback() { |
|
285 |
return true; |
|
286 |
} |
|
0 | 287 |
|
288 |
/** |
|
289 |
* Fetch a setting's value. |
|
290 |
* Grabs the main setting by default. |
|
291 |
* |
|
292 |
* @since 3.4.0 |
|
293 |
* |
|
294 |
* @param string $setting_key |
|
295 |
* @return mixed The requested setting's value, if the setting exists. |
|
296 |
*/ |
|
5 | 297 |
final public function value( $setting_key = 'default' ) { |
298 |
if ( isset( $this->settings[ $setting_key ] ) ) { |
|
0 | 299 |
return $this->settings[ $setting_key ]->value(); |
5 | 300 |
} |
0 | 301 |
} |
302 |
||
303 |
/** |
|
304 |
* Refresh the parameters passed to the JavaScript via JSON. |
|
305 |
* |
|
306 |
* @since 3.4.0 |
|
307 |
*/ |
|
308 |
public function to_json() { |
|
309 |
$this->json['settings'] = array(); |
|
310 |
foreach ( $this->settings as $key => $setting ) { |
|
311 |
$this->json['settings'][ $key ] = $setting->id; |
|
312 |
} |
|
313 |
||
9 | 314 |
$this->json['type'] = $this->type; |
315 |
$this->json['priority'] = $this->priority; |
|
316 |
$this->json['active'] = $this->active(); |
|
317 |
$this->json['section'] = $this->section; |
|
318 |
$this->json['content'] = $this->get_content(); |
|
319 |
$this->json['label'] = $this->label; |
|
320 |
$this->json['description'] = $this->description; |
|
5 | 321 |
$this->json['instanceNumber'] = $this->instance_number; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
if ( 'dropdown-pages' === $this->type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
$this->json['allow_addition'] = $this->allow_addition; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
} |
5 | 326 |
} |
327 |
||
328 |
/** |
|
329 |
* Get the data to export to the client via JSON. |
|
330 |
* |
|
331 |
* @since 4.1.0 |
|
332 |
* |
|
333 |
* @return array Array of parameters passed to the JavaScript. |
|
334 |
*/ |
|
335 |
public function json() { |
|
336 |
$this->to_json(); |
|
337 |
return $this->json; |
|
0 | 338 |
} |
339 |
||
340 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* Checks if the user can use this control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
* Returns false if the user cannot manipulate one of the associated settings, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* or if one of the associated settings does not exist. Also returns false if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
* the associated section does not exist or if its capability check returns |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
* false. |
0 | 347 |
* |
348 |
* @since 3.4.0 |
|
349 |
* |
|
350 |
* @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true. |
|
351 |
*/ |
|
5 | 352 |
final public function check_capabilities() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
|
0 | 357 |
foreach ( $this->settings as $setting ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
if ( ! $setting || ! $setting->check_capabilities() ) { |
0 | 359 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
} |
0 | 361 |
} |
362 |
||
363 |
$section = $this->manager->get_section( $this->section ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
if ( isset( $section ) && ! $section->check_capabilities() ) { |
0 | 365 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
} |
0 | 367 |
|
368 |
return true; |
|
369 |
} |
|
370 |
||
371 |
/** |
|
5 | 372 |
* Get the control's content for insertion into the Customizer pane. |
373 |
* |
|
374 |
* @since 4.1.0 |
|
375 |
* |
|
376 |
* @return string Contents of the control. |
|
377 |
*/ |
|
378 |
final public function get_content() { |
|
379 |
ob_start(); |
|
380 |
$this->maybe_render(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
return trim( ob_get_clean() ); |
5 | 382 |
} |
383 |
||
384 |
/** |
|
0 | 385 |
* Check capabilities and render the control. |
386 |
* |
|
387 |
* @since 3.4.0 |
|
388 |
* @uses WP_Customize_Control::render() |
|
389 |
*/ |
|
5 | 390 |
final public function maybe_render() { |
9 | 391 |
if ( ! $this->check_capabilities() ) { |
0 | 392 |
return; |
9 | 393 |
} |
0 | 394 |
|
5 | 395 |
/** |
396 |
* Fires just before the current Customizer control is rendered. |
|
397 |
* |
|
398 |
* @since 3.4.0 |
|
399 |
* |
|
19 | 400 |
* @param WP_Customize_Control $control WP_Customize_Control instance. |
5 | 401 |
*/ |
0 | 402 |
do_action( 'customize_render_control', $this ); |
5 | 403 |
|
404 |
/** |
|
405 |
* Fires just before a specific Customizer control is rendered. |
|
406 |
* |
|
407 |
* The dynamic portion of the hook name, `$this->id`, refers to |
|
408 |
* the control ID. |
|
409 |
* |
|
410 |
* @since 3.4.0 |
|
411 |
* |
|
19 | 412 |
* @param WP_Customize_Control $control WP_Customize_Control instance. |
5 | 413 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
do_action( "customize_render_control_{$this->id}", $this ); |
0 | 415 |
|
416 |
$this->render(); |
|
417 |
} |
|
418 |
||
419 |
/** |
|
5 | 420 |
* Renders the control wrapper and calls $this->render_content() for the internals. |
0 | 421 |
* |
422 |
* @since 3.4.0 |
|
423 |
*/ |
|
424 |
protected function render() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
$id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id ); |
0 | 426 |
$class = 'customize-control customize-control-' . $this->type; |
427 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
printf( '<li id="%s" class="%s">', esc_attr( $id ), esc_attr( $class ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
$this->render_content(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
echo '</li>'; |
0 | 431 |
} |
432 |
||
433 |
/** |
|
5 | 434 |
* Get the data link attribute for a setting. |
0 | 435 |
* |
436 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @since 4.9.0 Return a `data-customize-setting-key-link` attribute if a setting is not registered for the supplied setting key. |
0 | 438 |
* |
439 |
* @param string $setting_key |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
* @return string Data link parameter, a `data-customize-setting-link` attribute if the `$setting_key` refers to a pre-registered setting, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* and a `data-customize-setting-key-link` attribute if the setting is not yet registered. |
0 | 442 |
*/ |
443 |
public function get_link( $setting_key = 'default' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
if ( isset( $this->settings[ $setting_key ] ) && $this->settings[ $setting_key ] instanceof WP_Customize_Setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
return 'data-customize-setting-key-link="' . esc_attr( $setting_key ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
} |
0 | 449 |
} |
450 |
||
451 |
/** |
|
5 | 452 |
* Render the data link attribute for the control's input element. |
0 | 453 |
* |
454 |
* @since 3.4.0 |
|
455 |
* @uses WP_Customize_Control::get_link() |
|
456 |
* |
|
457 |
* @param string $setting_key |
|
458 |
*/ |
|
459 |
public function link( $setting_key = 'default' ) { |
|
460 |
echo $this->get_link( $setting_key ); |
|
461 |
} |
|
462 |
||
463 |
/** |
|
5 | 464 |
* Render the custom attributes for the control's input element. |
465 |
* |
|
466 |
* @since 4.0.0 |
|
467 |
*/ |
|
468 |
public function input_attrs() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
foreach ( $this->input_attrs as $attr => $value ) { |
5 | 470 |
echo $attr . '="' . esc_attr( $value ) . '" '; |
471 |
} |
|
472 |
} |
|
473 |
||
474 |
/** |
|
0 | 475 |
* Render the control's content. |
476 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
5 | 478 |
* |
479 |
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. |
|
480 |
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. |
|
481 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
0 | 483 |
* |
484 |
* @since 3.4.0 |
|
485 |
*/ |
|
486 |
protected function render_content() { |
|
9 | 487 |
$input_id = '_customize-input-' . $this->id; |
488 |
$description_id = '_customize-description-' . $this->id; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
$describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
switch ( $this->type ) { |
0 | 491 |
case 'checkbox': |
492 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
<span class="customize-inside-control-row"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
<input |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
id="<?php echo esc_attr( $input_id ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
<?php echo $describedby_attr; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
type="checkbox" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
value="<?php echo esc_attr( $this->value() ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
<?php $this->link(); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
<?php checked( $this->value() ); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
/> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
<label for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->label ); ?></label> |
5 | 503 |
<?php if ( ! empty( $this->description ) ) : ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
5 | 505 |
<?php endif; ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
</span> |
0 | 507 |
<?php |
508 |
break; |
|
509 |
case 'radio': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
if ( empty( $this->choices ) ) { |
0 | 511 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
} |
0 | 513 |
|
514 |
$name = '_customize-radio-' . $this->id; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
<?php if ( ! empty( $this->label ) ) : ?> |
5 | 517 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
<?php if ( ! empty( $this->description ) ) : ?> |
9 | 520 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
<?php endif; ?> |
5 | 522 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
<?php foreach ( $this->choices as $value => $label ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
<span class="customize-inside-control-row"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
<input |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
id="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
type="radio" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
<?php echo $describedby_attr; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
value="<?php echo esc_attr( $value ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
name="<?php echo esc_attr( $name ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
<?php $this->link(); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
<?php checked( $this->value(), $value ); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
/> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
<label for="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>"><?php echo esc_html( $label ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
<?php endforeach; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
<?php |
0 | 538 |
break; |
539 |
case 'select': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
if ( empty( $this->choices ) ) { |
0 | 541 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
} |
0 | 543 |
|
544 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
<?php if ( ! empty( $this->label ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
<?php if ( ! empty( $this->description ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
<?php endif; ?> |
5 | 551 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
<select id="<?php echo esc_attr( $input_id ); ?>" <?php echo $describedby_attr; ?> <?php $this->link(); ?>> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
foreach ( $this->choices as $value => $label ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
</select> |
0 | 559 |
<?php |
560 |
break; |
|
5 | 561 |
case 'textarea': |
562 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
<?php if ( ! empty( $this->label ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
<?php if ( ! empty( $this->description ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
<textarea |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
id="<?php echo esc_attr( $input_id ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
rows="5" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
<?php echo $describedby_attr; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
<?php $this->input_attrs(); ?> |
9 | 574 |
<?php $this->link(); ?> |
575 |
><?php echo esc_textarea( $this->value() ); ?></textarea> |
|
5 | 576 |
<?php |
577 |
break; |
|
0 | 578 |
case 'dropdown-pages': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
<?php if ( ! empty( $this->label ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
<?php if ( ! empty( $this->description ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
<?php |
9 | 588 |
$dropdown_name = '_customize-dropdown-pages-' . $this->id; |
589 |
$show_option_none = __( '— Select —' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
$option_none_value = '0'; |
9 | 591 |
$dropdown = wp_dropdown_pages( |
0 | 592 |
array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
'name' => $dropdown_name, |
0 | 594 |
'echo' => 0, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
'show_option_none' => $show_option_none, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
'option_none_value' => $option_none_value, |
0 | 597 |
'selected' => $this->value(), |
598 |
) |
|
599 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
if ( empty( $dropdown ) ) { |
9 | 601 |
$dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
$dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
$dropdown .= '</select>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
} |
0 | 605 |
|
606 |
// Hackily add in the data link parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
$dropdown = str_replace( '<select', '<select ' . $this->get_link() . ' id="' . esc_attr( $input_id ) . '" ' . $describedby_attr, $dropdown ); |
0 | 608 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
// Even more hacikly add auto-draft page stubs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
// @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. See <https://github.com/xwp/wp-customize-posts/pull/250>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
$nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
$auto_draft_page_options = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
$post = get_post( $auto_draft_page_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
if ( $post && 'page' === $post->post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
$auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
if ( $auto_draft_page_options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
$dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
echo $dropdown; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
<?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
<button type="button" class="button-link add-new-toggle"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
<?php |
16 | 630 |
/* translators: %s: Add New Page label. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
printf( __( '+ %s' ), get_post_type_object( 'page' )->labels->add_new_item ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
</button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
<div class="new-content-item"> |
19 | 635 |
<label for="create-input-<?php echo esc_attr( $this->id ); ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label> |
636 |
<input type="text" id="create-input-<?php echo esc_attr( $this->id ); ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title…' ); ?>"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
<button type="button" class="button add-content"><?php _e( 'Add' ); ?></button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
<?php |
0 | 641 |
break; |
5 | 642 |
default: |
643 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
<?php if ( ! empty( $this->label ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
<?php if ( ! empty( $this->description ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
<input |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
id="<?php echo esc_attr( $input_id ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
type="<?php echo esc_attr( $this->type ); ?>" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
<?php echo $describedby_attr; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
<?php $this->input_attrs(); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
<?php if ( ! isset( $this->input_attrs['value'] ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
value="<?php echo esc_attr( $this->value() ); ?>" |
5 | 657 |
<?php endif; ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
<?php $this->link(); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
/> |
5 | 660 |
<?php |
661 |
break; |
|
0 | 662 |
} |
663 |
} |
|
5 | 664 |
|
665 |
/** |
|
666 |
* Render the control's JS template. |
|
667 |
* |
|
668 |
* This function is only run for control types that have been registered with |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* WP_Customize_Manager::register_control_type(). |
5 | 670 |
* |
671 |
* In the future, this will also print the template for the control's container |
|
672 |
* element and be override-able. |
|
673 |
* |
|
674 |
* @since 4.1.0 |
|
675 |
*/ |
|
676 |
final public function print_template() { |
|
677 |
?> |
|
19 | 678 |
<script type="text/html" id="tmpl-customize-control-<?php echo esc_attr( $this->type ); ?>-content"> |
5 | 679 |
<?php $this->content_template(); ?> |
680 |
</script> |
|
681 |
<?php |
|
682 |
} |
|
683 |
||
684 |
/** |
|
685 |
* An Underscore (JS) template for this control's content (but not its container). |
|
686 |
* |
|
687 |
* Class variables for this control class are available in the `data` JS object; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* export custom variables by overriding WP_Customize_Control::to_json(). |
5 | 689 |
* |
690 |
* @see WP_Customize_Control::print_template() |
|
691 |
* |
|
692 |
* @since 4.1.0 |
|
693 |
*/ |
|
694 |
protected function content_template() {} |
|
695 |
||
0 | 696 |
} |
697 |
||
698 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* WP_Customize_Color_Control class. |
0 | 700 |
*/ |
16 | 701 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php'; |
0 | 702 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
* WP_Customize_Media_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
*/ |
16 | 706 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php'; |
0 | 707 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
* WP_Customize_Upload_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
*/ |
16 | 711 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php'; |
0 | 712 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
* WP_Customize_Image_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
*/ |
16 | 716 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php'; |
0 | 717 |
|
718 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* WP_Customize_Background_Image_Control class. |
0 | 720 |
*/ |
16 | 721 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php'; |
5 | 722 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* WP_Customize_Background_Position_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
*/ |
16 | 726 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php'; |
0 | 727 |
|
5 | 728 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* WP_Customize_Cropped_Image_Control class. |
5 | 730 |
*/ |
16 | 731 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php'; |
5 | 732 |
|
733 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
* WP_Customize_Site_Icon_Control class. |
5 | 735 |
*/ |
16 | 736 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php'; |
0 | 737 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* WP_Customize_Header_Image_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
*/ |
16 | 741 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php'; |
0 | 742 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
* WP_Customize_Theme_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
*/ |
16 | 746 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php'; |
0 | 747 |
|
748 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* WP_Widget_Area_Customize_Control class. |
0 | 750 |
*/ |
16 | 751 |
require_once ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
* WP_Widget_Form_Customize_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
*/ |
16 | 756 |
require_once ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php'; |
0 | 757 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
* WP_Customize_Nav_Menu_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
*/ |
16 | 761 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php'; |
0 | 762 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
* WP_Customize_Nav_Menu_Item_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
*/ |
16 | 766 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php'; |
0 | 767 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
* WP_Customize_Nav_Menu_Location_Control class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
*/ |
16 | 771 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php'; |
0 | 772 |
|
773 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
* WP_Customize_Nav_Menu_Name_Control class. |
0 | 775 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
* As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent |
16 | 777 |
* release, the require_once here will be removed and _deprecated_file() will be called if file is |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
* required at all. |
5 | 779 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* @deprecated 4.9.0 This file is no longer used due to new menu creation UX. |
0 | 781 |
*/ |
16 | 782 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php'; |
0 | 783 |
|
5 | 784 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
* WP_Customize_Nav_Menu_Locations_Control class. |
5 | 786 |
*/ |
16 | 787 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php'; |
0 | 788 |
|
5 | 789 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* WP_Customize_Nav_Menu_Auto_Add_Control class. |
5 | 791 |
*/ |
16 | 792 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php'; |
5 | 793 |
|
794 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* WP_Customize_Date_Time_Control class. |
5 | 796 |
*/ |
16 | 797 |
require_once ABSPATH . WPINC . '/customize/class-wp-customize-date-time-control.php'; |
18 | 798 |
|
799 |
/** |
|
800 |
* WP_Sidebar_Block_Editor_Control class. |
|
801 |
*/ |
|
802 |
require_once ABSPATH . WPINC . '/customize/class-wp-sidebar-block-editor-control.php'; |