@@ -133,10 +133,8 @@ discard block |
||
133 | 133 | * Check user capabilities and theme supports, and then save |
134 | 134 | * the value of the field. |
135 | 135 | * |
136 | - * @param mixed $value The value to save. |
|
137 | - * @param int $item_id The Item ID. |
|
138 | 136 | * |
139 | - * @return false|mixed False if cap check fails or value isn't set. |
|
137 | + * @return null|boolean False if cap check fails or value isn't set. |
|
140 | 138 | */ |
141 | 139 | public function save() { |
142 | 140 | |
@@ -188,9 +186,8 @@ discard block |
||
188 | 186 | * Save the value of the field, using the related API. |
189 | 187 | * |
190 | 188 | * @param mixed $value The value to update. |
191 | - * @param int $item_id Item ID. |
|
192 | 189 | * |
193 | - * @return mixed The result of saving the value. |
|
190 | + * @return null|boolean The result of saving the value. |
|
194 | 191 | */ |
195 | 192 | protected function update( $value ) { |
196 | 193 | |
@@ -538,7 +535,7 @@ discard block |
||
538 | 535 | * |
539 | 536 | * @param $root |
540 | 537 | * @param $keys |
541 | - * @param mixed $default A default value which is used as a fallback. Default is null. |
|
538 | + * @param string $default A default value which is used as a fallback. Default is null. |
|
542 | 539 | * |
543 | 540 | * @return mixed The requested value or the default value. |
544 | 541 | */ |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Fields API Field Class |
|
4 | - * |
|
5 | - * Handles saving and sanitizing of fields. |
|
6 | - * |
|
7 | - * @package WordPress |
|
8 | - * @subpackage Fields_API |
|
9 | - */ |
|
3 | + * Fields API Field Class |
|
4 | + * |
|
5 | + * Handles saving and sanitizing of fields. |
|
6 | + * |
|
7 | + * @package WordPress |
|
8 | + * @subpackage Fields_API |
|
9 | + */ |
|
10 | 10 | class WP_Fields_API_Field { |
11 | 11 | |
12 | 12 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $args = func_get_args(); |
76 | 76 | |
77 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
77 | + call_user_func_array(array($this, 'init'), $args); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return WP_Fields_API_Field $field |
90 | 90 | */ |
91 | - public function init( $object_type, $id, $args = array() ) { |
|
91 | + public function init($object_type, $id, $args = array()) { |
|
92 | 92 | |
93 | 93 | $this->object_type = $object_type; |
94 | 94 | |
95 | - if ( is_array( $id ) ) { |
|
95 | + if (is_array($id)) { |
|
96 | 96 | $args = $id; |
97 | 97 | |
98 | 98 | $id = ''; |
@@ -100,31 +100,31 @@ discard block |
||
100 | 100 | $this->id = $id; |
101 | 101 | } |
102 | 102 | |
103 | - $keys = array_keys( get_object_vars( $this ) ); |
|
103 | + $keys = array_keys(get_object_vars($this)); |
|
104 | 104 | |
105 | - foreach ( $keys as $key ) { |
|
106 | - if ( isset( $args[ $key ] ) ) { |
|
107 | - $this->$key = $args[ $key ]; |
|
105 | + foreach ($keys as $key) { |
|
106 | + if (isset($args[$key])) { |
|
107 | + $this->$key = $args[$key]; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Parse the ID for array keys. |
112 | - $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
|
113 | - $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
|
112 | + $this->id_data['keys'] = preg_split('/\[/', str_replace(']', '', $this->id)); |
|
113 | + $this->id_data['base'] = array_shift($this->id_data['keys']); |
|
114 | 114 | |
115 | 115 | // Rebuild the ID. |
116 | 116 | $this->id = $this->id_data['base']; |
117 | 117 | |
118 | - if ( ! empty( $this->id_data['keys'] ) ) { |
|
119 | - $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; |
|
118 | + if ( ! empty($this->id_data['keys'])) { |
|
119 | + $this->id .= '['.implode('][', $this->id_data['keys']).']'; |
|
120 | 120 | } |
121 | 121 | |
122 | - if ( $this->sanitize_callback ) { |
|
123 | - add_filter( "fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_callback, 10, 2 ); |
|
122 | + if ($this->sanitize_callback) { |
|
123 | + add_filter("fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_callback, 10, 2); |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( $this->sanitize_js_callback ) { |
|
127 | - add_filter( "fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_js_callback, 10, 2 ); |
|
126 | + if ($this->sanitize_js_callback) { |
|
127 | + add_filter("fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_js_callback, 10, 2); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $value = func_get_arg(0); |
144 | 144 | $item_id = func_get_arg(1); |
145 | 145 | |
146 | - if ( ! $this->check_capabilities() || false === $value ) { |
|
146 | + if ( ! $this->check_capabilities() || false === $value) { |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param WP_Fields_API_Field $this {@see WP_Fields_API_Field} instance. |
159 | 159 | */ |
160 | - do_action( 'field_save_' . $this->object_type . ' _' . $this->id_data[ 'base' ], $this, $value, $item_id ); |
|
160 | + do_action('field_save_'.$this->object_type.' _'.$this->id_data['base'], $this, $value, $item_id); |
|
161 | 161 | |
162 | - return $this->update( $value, $item_id ); |
|
162 | + return $this->update($value, $item_id); |
|
163 | 163 | |
164 | 164 | } |
165 | 165 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return mixed Null if an input isn't valid, otherwise the sanitized value. |
172 | 172 | */ |
173 | - public function sanitize( $value ) { |
|
173 | + public function sanitize($value) { |
|
174 | 174 | |
175 | - $value = wp_unslash( $value ); |
|
175 | + $value = wp_unslash($value); |
|
176 | 176 | |
177 | 177 | /** |
178 | 178 | * Filter a Customize field value in un-slashed form. |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @param mixed $value Value of the field. |
181 | 181 | * @param WP_Fields_API_Field $this WP_Fields_API_Field instance. |
182 | 182 | */ |
183 | - return apply_filters( "fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this ); |
|
183 | + return apply_filters("fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this); |
|
184 | 184 | |
185 | 185 | } |
186 | 186 | |
@@ -192,22 +192,22 @@ discard block |
||
192 | 192 | * |
193 | 193 | * @return mixed The result of saving the value. |
194 | 194 | */ |
195 | - protected function update( $value ) { |
|
195 | + protected function update($value) { |
|
196 | 196 | |
197 | 197 | $item_id = func_get_arg(1); |
198 | 198 | |
199 | - switch ( $this->object_type ) { |
|
199 | + switch ($this->object_type) { |
|
200 | 200 | case 'customizer' : |
201 | - return $this->_update_theme_mod( $value ); |
|
201 | + return $this->_update_theme_mod($value); |
|
202 | 202 | |
203 | 203 | case 'settings' : |
204 | - return $this->_update_option( $value ); |
|
204 | + return $this->_update_option($value); |
|
205 | 205 | |
206 | 206 | case 'post' : |
207 | - return $this->_update_post_meta( $value, $item_id ); |
|
207 | + return $this->_update_post_meta($value, $item_id); |
|
208 | 208 | |
209 | 209 | case 'user' : |
210 | - return $this->_update_user_meta( $value, $item_id ); |
|
210 | + return $this->_update_user_meta($value, $item_id); |
|
211 | 211 | |
212 | 212 | default : |
213 | 213 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param int $item_id Item ID. |
222 | 222 | * @param WP_Fields_API_Field $this WP_Fields_API_Field instance. |
223 | 223 | */ |
224 | - do_action( "fields_update_{$this->object_type}", $value, $item_id, $this ); |
|
224 | + do_action("fields_update_{$this->object_type}", $value, $item_id, $this); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return null; |
@@ -235,22 +235,22 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return null |
237 | 237 | */ |
238 | - protected function _update_theme_mod( $value ) { |
|
238 | + protected function _update_theme_mod($value) { |
|
239 | 239 | |
240 | - if ( is_null( $value ) ) { |
|
241 | - remove_theme_mod( $this->id_data['base'] ); |
|
240 | + if (is_null($value)) { |
|
241 | + remove_theme_mod($this->id_data['base']); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Handle non-array theme mod. |
245 | - if ( empty( $this->id_data['keys'] ) ) { |
|
246 | - set_theme_mod( $this->id_data['base'], $value ); |
|
245 | + if (empty($this->id_data['keys'])) { |
|
246 | + set_theme_mod($this->id_data['base'], $value); |
|
247 | 247 | } else { |
248 | 248 | // Handle array-based theme mod. |
249 | - $mods = get_theme_mod( $this->id_data['base'] ); |
|
250 | - $mods = $this->multidimensional_replace( $mods, $this->id_data['keys'], $value ); |
|
249 | + $mods = get_theme_mod($this->id_data['base']); |
|
250 | + $mods = $this->multidimensional_replace($mods, $this->id_data['keys'], $value); |
|
251 | 251 | |
252 | - if ( isset( $mods ) ) { |
|
253 | - set_theme_mod( $this->id_data['base'], $mods ); |
|
252 | + if (isset($mods)) { |
|
253 | + set_theme_mod($this->id_data['base'], $mods); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return bool|null The result of saving the value. |
267 | 267 | */ |
268 | - protected function _update_option( $value ) { |
|
268 | + protected function _update_option($value) { |
|
269 | 269 | |
270 | - if ( is_null( $value ) ) { |
|
271 | - delete_option( $this->id_data['base'] ); |
|
270 | + if (is_null($value)) { |
|
271 | + delete_option($this->id_data['base']); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | // Handle non-array option. |
275 | - if ( empty( $this->id_data['keys'] ) ) { |
|
276 | - return update_option( $this->id_data['base'], $value ); |
|
275 | + if (empty($this->id_data['keys'])) { |
|
276 | + return update_option($this->id_data['base'], $value); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | // Handle array-based options. |
280 | - $options = get_option( $this->id_data['base'] ); |
|
281 | - $options = $this->multidimensional_replace( $options, $this->id_data['keys'], $value ); |
|
280 | + $options = get_option($this->id_data['base']); |
|
281 | + $options = $this->multidimensional_replace($options, $this->id_data['keys'], $value); |
|
282 | 282 | |
283 | - if ( isset( $options ) ) { |
|
284 | - return update_option( $this->id_data['base'], $options ); |
|
283 | + if (isset($options)) { |
|
284 | + return update_option($this->id_data['base'], $options); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | return null; |
@@ -296,23 +296,23 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return bool|null The result of saving the value. |
298 | 298 | */ |
299 | - protected function _update_post_meta( $value, $item_id = 0 ) { |
|
299 | + protected function _update_post_meta($value, $item_id = 0) { |
|
300 | 300 | |
301 | - if ( is_null( $value ) ) { |
|
302 | - delete_post_meta( $item_id, $this->id_data['base'] ); |
|
301 | + if (is_null($value)) { |
|
302 | + delete_post_meta($item_id, $this->id_data['base']); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Handle non-array option. |
306 | - if ( empty( $this->id_data['keys'] ) ) { |
|
307 | - return update_post_meta( $item_id, $this->id_data['base'], $value ); |
|
306 | + if (empty($this->id_data['keys'])) { |
|
307 | + return update_post_meta($item_id, $this->id_data['base'], $value); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Handle array-based keys. |
311 | - $keys = get_post_meta( 0, $this->id_data['base'] ); |
|
312 | - $keys = $this->multidimensional_replace( $keys, $this->id_data['keys'], $value ); |
|
311 | + $keys = get_post_meta(0, $this->id_data['base']); |
|
312 | + $keys = $this->multidimensional_replace($keys, $this->id_data['keys'], $value); |
|
313 | 313 | |
314 | - if ( isset( $keys ) ) { |
|
315 | - return update_post_meta( $item_id, $this->id_data['base'], $keys ); |
|
314 | + if (isset($keys)) { |
|
315 | + return update_post_meta($item_id, $this->id_data['base'], $keys); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return null; |
@@ -327,23 +327,23 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return bool|null The result of saving the value. |
329 | 329 | */ |
330 | - protected function _update_user_meta( $value, $item_id = 0 ) { |
|
330 | + protected function _update_user_meta($value, $item_id = 0) { |
|
331 | 331 | |
332 | - if ( is_null( $value ) ) { |
|
333 | - delete_user_meta( $item_id, $this->id_data['base'] ); |
|
332 | + if (is_null($value)) { |
|
333 | + delete_user_meta($item_id, $this->id_data['base']); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | // Handle non-array option. |
337 | - if ( empty( $this->id_data['keys'] ) ) { |
|
338 | - return update_user_meta( $item_id, $this->id_data['base'], $value ); |
|
337 | + if (empty($this->id_data['keys'])) { |
|
338 | + return update_user_meta($item_id, $this->id_data['base'], $value); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | // Handle array-based options. |
342 | - $keys = get_user_meta( 0, $this->id_data['base'] ); |
|
343 | - $keys = $this->multidimensional_replace( $keys, $this->id_data['keys'], $value ); |
|
342 | + $keys = get_user_meta(0, $this->id_data['base']); |
|
343 | + $keys = $this->multidimensional_replace($keys, $this->id_data['keys'], $value); |
|
344 | 344 | |
345 | - if ( isset( $keys ) ) { |
|
346 | - return update_user_meta( $item_id, $this->id_data['base'], $keys ); |
|
345 | + if (isset($keys)) { |
|
346 | + return update_user_meta($item_id, $this->id_data['base'], $keys); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | return null; |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | public function value() { |
359 | 359 | |
360 | - switch ( $this->object_type ) { |
|
360 | + switch ($this->object_type) { |
|
361 | 361 | case 'customizer' : |
362 | 362 | $function = 'get_theme_mod'; |
363 | 363 | break; |
@@ -388,18 +388,18 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @param mixed $default The field default value. Default empty. |
390 | 390 | */ |
391 | - return apply_filters( 'fields_value_' . $this->object_type . '_' . $this->object_name . '_' . $this->id_data['base'], $this->default ); |
|
391 | + return apply_filters('fields_value_'.$this->object_type.'_'.$this->object_name.'_'.$this->id_data['base'], $this->default); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Handle non-array value |
395 | - if ( empty( $this->id_data['keys'] ) ) { |
|
396 | - return $function( $this->id_data['base'], $this->default ); |
|
395 | + if (empty($this->id_data['keys'])) { |
|
396 | + return $function($this->id_data['base'], $this->default); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | // Handle array-based value |
400 | - $values = $function( $this->id_data['base'] ); |
|
400 | + $values = $function($this->id_data['base']); |
|
401 | 401 | |
402 | - return $this->multidimensional_get( $values, $this->id_data['keys'], $this->default ); |
|
402 | + return $this->multidimensional_get($values, $this->id_data['keys'], $this->default); |
|
403 | 403 | |
404 | 404 | } |
405 | 405 | |
@@ -420,10 +420,10 @@ discard block |
||
420 | 420 | * @param mixed $value The field value. |
421 | 421 | * @param WP_Fields_API_Field $this {@see WP_Fields_API_Field} instance. |
422 | 422 | */ |
423 | - $value = apply_filters( "fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this ); |
|
423 | + $value = apply_filters("fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this); |
|
424 | 424 | |
425 | - if ( is_string( $value ) ) { |
|
426 | - return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); |
|
425 | + if (is_string($value)) { |
|
426 | + return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return $value; |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function check_capabilities() { |
439 | 439 | |
440 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
440 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
441 | 441 | return false; |
442 | 442 | } |
443 | 443 | |
444 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
444 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | |
@@ -458,42 +458,42 @@ discard block |
||
458 | 458 | * |
459 | 459 | * @return null|array Keys are 'root', 'node', and 'key'. |
460 | 460 | */ |
461 | - final protected function multidimensional( &$root, $keys, $create = false ) { |
|
461 | + final protected function multidimensional(&$root, $keys, $create = false) { |
|
462 | 462 | |
463 | - if ( $create && empty( $root ) ) { |
|
463 | + if ($create && empty($root)) { |
|
464 | 464 | $root = array(); |
465 | 465 | } |
466 | 466 | |
467 | - if ( ! isset( $root ) || empty( $keys ) ) { |
|
467 | + if ( ! isset($root) || empty($keys)) { |
|
468 | 468 | return null; |
469 | 469 | } |
470 | 470 | |
471 | - $last = array_pop( $keys ); |
|
471 | + $last = array_pop($keys); |
|
472 | 472 | $node = &$root; |
473 | 473 | |
474 | - foreach ( $keys as $key ) { |
|
475 | - if ( $create && ! isset( $node[ $key ] ) ) { |
|
476 | - $node[ $key ] = array(); |
|
474 | + foreach ($keys as $key) { |
|
475 | + if ($create && ! isset($node[$key])) { |
|
476 | + $node[$key] = array(); |
|
477 | 477 | } |
478 | 478 | |
479 | - if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { |
|
479 | + if ( ! is_array($node) || ! isset($node[$key])) { |
|
480 | 480 | return null; |
481 | 481 | } |
482 | 482 | |
483 | - $node = &$node[ $key ]; |
|
483 | + $node = &$node[$key]; |
|
484 | 484 | } |
485 | 485 | |
486 | - if ( $create ) { |
|
487 | - if ( ! is_array( $node ) ) { |
|
486 | + if ($create) { |
|
487 | + if ( ! is_array($node)) { |
|
488 | 488 | // account for an array overriding a string or object value |
489 | 489 | $node = array(); |
490 | 490 | } |
491 | - if ( ! isset( $node[ $last ] ) ) { |
|
492 | - $node[ $last ] = array(); |
|
491 | + if ( ! isset($node[$last])) { |
|
492 | + $node[$last] = array(); |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | |
496 | - if ( ! isset( $node[ $last ] ) ) { |
|
496 | + if ( ! isset($node[$last])) { |
|
497 | 497 | return null; |
498 | 498 | } |
499 | 499 | |
@@ -514,19 +514,19 @@ discard block |
||
514 | 514 | * |
515 | 515 | * @return |
516 | 516 | */ |
517 | - final protected function multidimensional_replace( $root, $keys, $value ) { |
|
517 | + final protected function multidimensional_replace($root, $keys, $value) { |
|
518 | 518 | |
519 | - if ( ! isset( $value ) ) { |
|
519 | + if ( ! isset($value)) { |
|
520 | 520 | return $root; |
521 | - } elseif ( empty( $keys ) ) { |
|
521 | + } elseif (empty($keys)) { |
|
522 | 522 | // If there are no keys, we're replacing the root. |
523 | 523 | return $value; |
524 | 524 | } |
525 | 525 | |
526 | - $result = $this->multidimensional( $root, $keys, true ); |
|
526 | + $result = $this->multidimensional($root, $keys, true); |
|
527 | 527 | |
528 | - if ( isset( $result ) ) { |
|
529 | - $result['node'][ $result['key'] ] = $value; |
|
528 | + if (isset($result)) { |
|
529 | + $result['node'][$result['key']] = $value; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $root; |
@@ -542,18 +542,18 @@ discard block |
||
542 | 542 | * |
543 | 543 | * @return mixed The requested value or the default value. |
544 | 544 | */ |
545 | - final protected function multidimensional_get( $root, $keys, $default = null ) { |
|
545 | + final protected function multidimensional_get($root, $keys, $default = null) { |
|
546 | 546 | |
547 | 547 | // If there are no keys, test the root. |
548 | - if ( empty( $keys ) ) { |
|
549 | - if ( isset( $root ) ) { |
|
548 | + if (empty($keys)) { |
|
549 | + if (isset($root)) { |
|
550 | 550 | return $root; |
551 | 551 | } |
552 | 552 | } else { |
553 | - $result = $this->multidimensional( $root, $keys ); |
|
553 | + $result = $this->multidimensional($root, $keys); |
|
554 | 554 | |
555 | - if ( isset( $result ) ) { |
|
556 | - return $result['node'][ $result['key'] ]; |
|
555 | + if (isset($result)) { |
|
556 | + return $result['node'][$result['key']]; |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
@@ -569,11 +569,11 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @return bool True if value is set, false if not. |
571 | 571 | */ |
572 | - final protected function multidimensional_isset( $root, $keys ) { |
|
572 | + final protected function multidimensional_isset($root, $keys) { |
|
573 | 573 | |
574 | - $result = $this->multidimensional_get( $root, $keys ); |
|
574 | + $result = $this->multidimensional_get($root, $keys); |
|
575 | 575 | |
576 | - return isset( $result ); |
|
576 | + return isset($result); |
|
577 | 577 | |
578 | 578 | } |
579 | 579 | } |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | * |
596 | 596 | * @return mixed The result of saving the value. |
597 | 597 | */ |
598 | - public function update( $value ) { |
|
598 | + public function update($value) { |
|
599 | 599 | |
600 | 600 | return null; |
601 | 601 |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @access public |
133 | 133 | * |
134 | 134 | * @param string|null $object_type Object type. Null for all containers for all object types. |
135 | - * @param string|boolean|null $object_name Object name (for post types and taxonomies). |
|
135 | + * @param string|boolean $object_name Object name (for post types and taxonomies). |
|
136 | 136 | * True for all containers for all object names. |
137 | 137 | * |
138 | 138 | * @return WP_Fields_API_Screen[]|WP_Fields_API_Section[] |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @access public |
227 | 227 | * |
228 | 228 | * @param string $object_type Object type. |
229 | - * @param WP_Fields_API_Screen|string $id Field Screen object, or Screen ID. |
|
229 | + * @param string|null $id Field Screen object, or Screen ID. |
|
230 | 230 | * @param string $object_name Object name (for post types and taxonomies). |
231 | 231 | * @param array $args Optional. Screen arguments. Default empty array. |
232 | 232 | */ |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * @access public |
499 | 499 | * |
500 | 500 | * @param string $object_type Object type. |
501 | - * @param WP_Fields_API_Section|string $id Field Section object, or Section ID. |
|
501 | + * @param string $id Field Section object, or Section ID. |
|
502 | 502 | * @param string $object_name Object name (for post types and taxonomies). |
503 | 503 | * @param array $args Section arguments. |
504 | 504 | */ |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @access public |
731 | 731 | * |
732 | 732 | * @param string $object_type Object type. |
733 | - * @param WP_Fields_API_Field|string $id Fields API Field object, or ID. |
|
733 | + * @param string $id Fields API Field object, or ID. |
|
734 | 734 | * @param string $object_name Object name (for post types and taxonomies). |
735 | 735 | * @param array $args Field arguments; passed to WP_Fields_API_Field |
736 | 736 | * constructor. |
@@ -908,7 +908,6 @@ discard block |
||
908 | 908 | * @see WP_Fields_API_Field |
909 | 909 | * |
910 | 910 | * @param string $type Field type ID. |
911 | - * @param string $screen_class Name of a custom field type which is a subclass of WP_Fields_API_Field. |
|
912 | 911 | */ |
913 | 912 | public function register_field_type( $type, $field_class = null ) { |
914 | 913 |
@@ -96,15 +96,15 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function __construct() { |
98 | 98 | |
99 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api-field.php' ); |
|
100 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api-control.php' ); |
|
101 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api-section.php' ); |
|
102 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api-screen.php' ); |
|
99 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api-field.php'); |
|
100 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api-control.php'); |
|
101 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api-section.php'); |
|
102 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api-screen.php'); |
|
103 | 103 | |
104 | 104 | // Register our wp_loaded() first before WP_Customize_Manage::wp_loaded() |
105 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 9 ); |
|
105 | + add_action('wp_loaded', array($this, 'wp_loaded'), 9); |
|
106 | 106 | |
107 | - add_action( 'fields_register', array( $this, 'register_controls' ) ); |
|
107 | + add_action('fields_register', array($this, 'register_controls')); |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param WP_Fields_API $this The Fields manager object. |
124 | 124 | */ |
125 | - do_action( 'fields_register', $this ); |
|
125 | + do_action('fields_register', $this); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 | |
@@ -137,34 +137,34 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return WP_Fields_API_Screen[]|WP_Fields_API_Section[] |
139 | 139 | */ |
140 | - public function get_containers( $object_type = null, $object_name = null ) { |
|
140 | + public function get_containers($object_type = null, $object_name = null) { |
|
141 | 141 | |
142 | 142 | // $object_name defaults to '_{$object_type}' for internal handling. |
143 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
144 | - $object_name = '_' . $object_type; |
|
143 | + if (empty($object_name) && ! empty($object_type)) { |
|
144 | + $object_name = '_'.$object_type; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // Setup containers. |
148 | - if ( empty( self::$containers ) ) { |
|
149 | - if ( true === $object_name ) { |
|
150 | - $this->prepare_controls( $object_type ); |
|
148 | + if (empty(self::$containers)) { |
|
149 | + if (true === $object_name) { |
|
150 | + $this->prepare_controls($object_type); |
|
151 | 151 | } else { |
152 | - $this->prepare_object_controls( $object_type, $object_name ); |
|
152 | + $this->prepare_object_controls($object_type, $object_name); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | 156 | $containers = array(); |
157 | 157 | |
158 | - if ( null === $object_type ) { |
|
158 | + if (null === $object_type) { |
|
159 | 159 | // Get all containers. |
160 | 160 | $containers = self::$containers; |
161 | - } elseif ( isset( self::$containers[ $object_type ][ $object_name ] ) ) { |
|
161 | + } elseif (isset(self::$containers[$object_type][$object_name])) { |
|
162 | 162 | // Get all containers by object name. |
163 | - $containers = self::$containers[ $object_type ][ $object_name ]; |
|
164 | - } elseif ( true === $object_name ) { |
|
163 | + $containers = self::$containers[$object_type][$object_name]; |
|
164 | + } elseif (true === $object_name) { |
|
165 | 165 | // Get all containers by object type. |
166 | - foreach ( self::$containers[ $object_type ] as $object_name => $object_containers ) { |
|
167 | - $containers = array_merge( $containers, array_values( $object_containers ) ); |
|
166 | + foreach (self::$containers[$object_type] as $object_name => $object_containers) { |
|
167 | + $containers = array_merge($containers, array_values($object_containers)); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -182,37 +182,37 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return WP_Fields_API_Screen[] |
184 | 184 | */ |
185 | - public function get_screens( $object_type = null, $object_name = null ) { |
|
185 | + public function get_screens($object_type = null, $object_name = null) { |
|
186 | 186 | |
187 | 187 | // $object_name defaults to '_{$object_type}' for internal handling. |
188 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
189 | - $object_name = '_' . $object_type; |
|
188 | + if (empty($object_name) && ! empty($object_type)) { |
|
189 | + $object_name = '_'.$object_type; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $screens = array(); |
193 | 193 | |
194 | - if ( null === $object_type ) { |
|
194 | + if (null === $object_type) { |
|
195 | 195 | // Late init. |
196 | - foreach ( self::$screens as $object_type => $object_names ) { |
|
197 | - foreach ( $object_names as $object_name => $screens ) { |
|
198 | - $this->get_screens( $object_type, $object_name ); |
|
196 | + foreach (self::$screens as $object_type => $object_names) { |
|
197 | + foreach ($object_names as $object_name => $screens) { |
|
198 | + $this->get_screens($object_type, $object_name); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | 202 | $screens = self::$screens; |
203 | - } elseif ( isset( self::$screens[ $object_type ][ $object_name ] ) ) { |
|
203 | + } elseif (isset(self::$screens[$object_type][$object_name])) { |
|
204 | 204 | // Late init. |
205 | - foreach ( self::$screens[ $object_type ][ $object_name ] as $id => $screen ) { |
|
205 | + foreach (self::$screens[$object_type][$object_name] as $id => $screen) { |
|
206 | 206 | // Late init |
207 | - self::$screens[ $object_type ][ $object_name ][ $id ] = $this->setup_screen( $object_type, $id, $object_name, $screen ); |
|
207 | + self::$screens[$object_type][$object_name][$id] = $this->setup_screen($object_type, $id, $object_name, $screen); |
|
208 | 208 | } |
209 | 209 | |
210 | - $screens = self::$screens[ $object_type ][ $object_name ]; |
|
211 | - } elseif ( true === $object_name ) { |
|
210 | + $screens = self::$screens[$object_type][$object_name]; |
|
211 | + } elseif (true === $object_name) { |
|
212 | 212 | // Get all screens. |
213 | 213 | // Late init. |
214 | - foreach ( self::$screens[ $object_type ] as $object_name => $object_screens ) { |
|
215 | - $screens = array_merge( $screens, array_values( $this->get_screens( $object_type, $object_name ) ) ); |
|
214 | + foreach (self::$screens[$object_type] as $object_name => $object_screens) { |
|
215 | + $screens = array_merge($screens, array_values($this->get_screens($object_type, $object_name))); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | * @param string $object_name Object name (for post types and taxonomies). |
231 | 231 | * @param array $args Optional. Screen arguments. Default empty array. |
232 | 232 | */ |
233 | - public function add_screen( $object_type, $id, $object_name = null, $args = array() ) { |
|
233 | + public function add_screen($object_type, $id, $object_name = null, $args = array()) { |
|
234 | 234 | |
235 | - if ( empty( $id ) && empty( $args ) ) { |
|
235 | + if (empty($id) && empty($args)) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ( is_a( $id, 'WP_Fields_API_Screen' ) ) { |
|
239 | + if (is_a($id, 'WP_Fields_API_Screen')) { |
|
240 | 240 | $screen = $id; |
241 | 241 | |
242 | 242 | $id = $screen->id; |
@@ -246,19 +246,19 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | // $object_name defaults to '_{$object_type}' for internal handling. |
249 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
250 | - $object_name = '_' . $object_type; |
|
249 | + if (empty($object_name) && ! empty($object_type)) { |
|
250 | + $object_name = '_'.$object_type; |
|
251 | 251 | } |
252 | 252 | |
253 | - if ( ! isset( self::$screens[ $object_type ] ) ) { |
|
254 | - self::$screens[ $object_type ] = array(); |
|
253 | + if ( ! isset(self::$screens[$object_type])) { |
|
254 | + self::$screens[$object_type] = array(); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! isset( self::$screens[ $object_type ][ $object_name ] ) ) { |
|
258 | - self::$screens[ $object_type ][ $object_name ] = array(); |
|
257 | + if ( ! isset(self::$screens[$object_type][$object_name])) { |
|
258 | + self::$screens[$object_type][$object_name] = array(); |
|
259 | 259 | } |
260 | 260 | |
261 | - self::$screens[ $object_type ][ $object_name ][ $id ] = $screen; |
|
261 | + self::$screens[$object_type][$object_name][$id] = $screen; |
|
262 | 262 | |
263 | 263 | } |
264 | 264 | |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return WP_Fields_API_Screen|null Requested screen instance. |
275 | 275 | */ |
276 | - public function get_screen( $object_type, $id, $object_name = null ) { |
|
276 | + public function get_screen($object_type, $id, $object_name = null) { |
|
277 | 277 | |
278 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
279 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
278 | + if (empty($object_name) && ! empty($object_type)) { |
|
279 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | $screen = null; |
283 | 283 | |
284 | - if ( isset( self::$screens[ $object_type ][ $object_name ][ $id ] ) ) { |
|
284 | + if (isset(self::$screens[$object_type][$object_name][$id])) { |
|
285 | 285 | // Late init |
286 | - self::$screens[ $object_type ][ $object_name ][ $id ] = $this->setup_screen( $object_type, $id, $object_name, self::$screens[ $object_type ][ $object_name ][ $id ] ); |
|
286 | + self::$screens[$object_type][$object_name][$id] = $this->setup_screen($object_type, $id, $object_name, self::$screens[$object_type][$object_name][$id]); |
|
287 | 287 | |
288 | - $screen = self::$screens[ $object_type ][ $object_name ][ $id ]; |
|
288 | + $screen = self::$screens[$object_type][$object_name][$id]; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | return $screen; |
@@ -304,26 +304,26 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return WP_Fields_API_Screen|null $screen The screen object. |
306 | 306 | */ |
307 | - public function setup_screen( $object_type, $id, $object_name = null, $args = null ) { |
|
307 | + public function setup_screen($object_type, $id, $object_name = null, $args = null) { |
|
308 | 308 | |
309 | 309 | $screen = null; |
310 | 310 | |
311 | 311 | $screen_class = 'WP_Fields_API_Screen'; |
312 | 312 | |
313 | - if ( is_a( $args, $screen_class ) ) { |
|
313 | + if (is_a($args, $screen_class)) { |
|
314 | 314 | $screen = $args; |
315 | - } elseif ( is_array( $args ) ) { |
|
315 | + } elseif (is_array($args)) { |
|
316 | 316 | $args['object_name'] = $object_name; |
317 | 317 | |
318 | - if ( ! empty( $args['type'] ) ) { |
|
319 | - if ( ! empty( self::$registered_screen_types[ $args['type'] ] ) ) { |
|
320 | - $screen_class = self::$registered_screen_types[ $args['type'] ]; |
|
321 | - } elseif ( in_array( $args['type'], self::$registered_screen_types ) ) { |
|
318 | + if ( ! empty($args['type'])) { |
|
319 | + if ( ! empty(self::$registered_screen_types[$args['type']])) { |
|
320 | + $screen_class = self::$registered_screen_types[$args['type']]; |
|
321 | + } elseif (in_array($args['type'], self::$registered_screen_types)) { |
|
322 | 322 | $screen_class = $args['type']; |
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - $screen = new $screen_class( $object_type, $id, $args ); |
|
326 | + $screen = new $screen_class($object_type, $id, $args); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | return $screen; |
@@ -339,29 +339,29 @@ discard block |
||
339 | 339 | * @param string $id Screen ID to remove, set true to remove all screens from an object. |
340 | 340 | * @param string $object_name Object name (for post types and taxonomies), set true to remove to all objects from an object type. |
341 | 341 | */ |
342 | - public function remove_screen( $object_type, $id, $object_name = null ) { |
|
342 | + public function remove_screen($object_type, $id, $object_name = null) { |
|
343 | 343 | |
344 | - if ( true === $object_type ) { |
|
344 | + if (true === $object_type) { |
|
345 | 345 | // Remove all screens |
346 | 346 | self::$screens = array(); |
347 | - } elseif ( true === $object_name ) { |
|
347 | + } elseif (true === $object_name) { |
|
348 | 348 | // Remove all screens for an object type |
349 | - if ( isset( self::$screens[ $object_type ] ) ) { |
|
350 | - unset( self::$screens[ $object_type ] ); |
|
349 | + if (isset(self::$screens[$object_type])) { |
|
350 | + unset(self::$screens[$object_type]); |
|
351 | 351 | } |
352 | 352 | } else { |
353 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
354 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
353 | + if (empty($object_name) && ! empty($object_type)) { |
|
354 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
355 | 355 | } |
356 | 356 | |
357 | - if ( true === $id && null !== $object_name ) { |
|
357 | + if (true === $id && null !== $object_name) { |
|
358 | 358 | // Remove all screens for an object type |
359 | - if ( isset( self::$screens[ $object_type ][ $object_name ] ) ) { |
|
360 | - unset( self::$screens[ $object_type ][ $object_name ] ); |
|
359 | + if (isset(self::$screens[$object_type][$object_name])) { |
|
360 | + unset(self::$screens[$object_type][$object_name]); |
|
361 | 361 | } |
362 | - } elseif ( isset( self::$screens[ $object_type ][ $object_name ][ $id ] ) ) { |
|
362 | + } elseif (isset(self::$screens[$object_type][$object_name][$id])) { |
|
363 | 363 | // Remove screen from object type and name |
364 | - unset( self::$screens[ $object_type ][ $object_name ][ $id ] ); |
|
364 | + unset(self::$screens[$object_type][$object_name][$id]); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | * @param string $type Screen type ID. |
378 | 378 | * @param string $screen_class Name of a custom screen which is a subclass of WP_Fields_API_Screen. |
379 | 379 | */ |
380 | - public function register_screen_type( $type, $screen_class = null ) { |
|
380 | + public function register_screen_type($type, $screen_class = null) { |
|
381 | 381 | |
382 | - if ( null === $screen_class ) { |
|
382 | + if (null === $screen_class) { |
|
383 | 383 | $screen_class = $type; |
384 | 384 | } |
385 | 385 | |
386 | - self::$registered_screen_types[ $type ] = $screen_class; |
|
386 | + self::$registered_screen_types[$type] = $screen_class; |
|
387 | 387 | |
388 | 388 | } |
389 | 389 | |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | /** |
398 | 398 | * @var WP_Fields_API_Screen $screen |
399 | 399 | */ |
400 | - foreach ( self::$registered_screen_types as $screen_type => $screen_class ) { |
|
401 | - $screen = $this->setup_screen( null, 'temp', null, array( 'type' => $screen_type ) ); |
|
400 | + foreach (self::$registered_screen_types as $screen_type => $screen_class) { |
|
401 | + $screen = $this->setup_screen(null, 'temp', null, array('type' => $screen_type)); |
|
402 | 402 | |
403 | 403 | $screen->print_template(); |
404 | 404 | } |
@@ -416,41 +416,41 @@ discard block |
||
416 | 416 | * |
417 | 417 | * @return WP_Fields_API_Section[] |
418 | 418 | */ |
419 | - public function get_sections( $object_type = null, $object_name = null, $screen = null ) { |
|
419 | + public function get_sections($object_type = null, $object_name = null, $screen = null) { |
|
420 | 420 | |
421 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
422 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
421 | + if (empty($object_name) && ! empty($object_type)) { |
|
422 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | $sections = array(); |
426 | 426 | |
427 | - if ( null === $object_type ) { |
|
427 | + if (null === $object_type) { |
|
428 | 428 | // Late init |
429 | - foreach ( self::$sections as $object_type => $object_names ) { |
|
430 | - foreach ( $object_names as $object_name => $sections ) { |
|
431 | - $this->get_sections( $object_type, $object_name ); |
|
429 | + foreach (self::$sections as $object_type => $object_names) { |
|
430 | + foreach ($object_names as $object_name => $sections) { |
|
431 | + $this->get_sections($object_type, $object_name); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | 435 | $sections = self::$sections; |
436 | 436 | |
437 | 437 | // Get only sections for a specific screen |
438 | - if ( null !== $screen ) { |
|
438 | + if (null !== $screen) { |
|
439 | 439 | $screen_sections = array(); |
440 | 440 | |
441 | - foreach ( $sections as $object_type => $object_names ) { |
|
442 | - foreach ( $object_names as $object_name => $object_sections ) { |
|
443 | - foreach ( $object_sections as $id => $section ) { |
|
444 | - if ( $screen == $section->screen->id ) { |
|
445 | - if ( ! isset( $screen_sections[ $object_type ] ) ) { |
|
446 | - $screen_sections[ $object_type ] = array(); |
|
441 | + foreach ($sections as $object_type => $object_names) { |
|
442 | + foreach ($object_names as $object_name => $object_sections) { |
|
443 | + foreach ($object_sections as $id => $section) { |
|
444 | + if ($screen == $section->screen->id) { |
|
445 | + if ( ! isset($screen_sections[$object_type])) { |
|
446 | + $screen_sections[$object_type] = array(); |
|
447 | 447 | } |
448 | 448 | |
449 | - if ( ! isset( $screen_sections[ $object_type ][ $object_name ] ) ) { |
|
450 | - $screen_sections[ $object_type ][ $object_name ] = array(); |
|
449 | + if ( ! isset($screen_sections[$object_type][$object_name])) { |
|
450 | + $screen_sections[$object_type][$object_name] = array(); |
|
451 | 451 | } |
452 | 452 | |
453 | - $screen_sections[ $object_type ][ $object_name ][ $id ] = $screen; |
|
453 | + $screen_sections[$object_type][$object_name][$id] = $screen; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
@@ -458,33 +458,33 @@ discard block |
||
458 | 458 | |
459 | 459 | $sections = $screen_sections; |
460 | 460 | } |
461 | - } elseif ( isset( self::$sections[ $object_type ][ $object_name ] ) ) { |
|
461 | + } elseif (isset(self::$sections[$object_type][$object_name])) { |
|
462 | 462 | // Late init |
463 | - foreach ( self::$sections[ $object_type ][ $object_name ] as $id => $section ) { |
|
463 | + foreach (self::$sections[$object_type][$object_name] as $id => $section) { |
|
464 | 464 | // Late init |
465 | - self::$sections[ $object_type ][ $object_name ][ $id ] = $this->setup_section( $object_type, $id, $object_name, $section ); |
|
465 | + self::$sections[$object_type][$object_name][$id] = $this->setup_section($object_type, $id, $object_name, $section); |
|
466 | 466 | } |
467 | 467 | |
468 | - $sections = self::$sections[ $object_type ][ $object_name ]; |
|
468 | + $sections = self::$sections[$object_type][$object_name]; |
|
469 | 469 | |
470 | 470 | // Get only sections for a specific screen |
471 | - if ( null !== $screen ) { |
|
471 | + if (null !== $screen) { |
|
472 | 472 | $screen_sections = array(); |
473 | 473 | |
474 | - foreach ( $sections as $id => $section ) { |
|
475 | - if ( $screen == $section->screen ) { |
|
476 | - $screen_sections[ $id ] = $section; |
|
474 | + foreach ($sections as $id => $section) { |
|
475 | + if ($screen == $section->screen) { |
|
476 | + $screen_sections[$id] = $section; |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | 480 | $sections = $screen_sections; |
481 | 481 | } |
482 | - } elseif ( true === $object_name ) { |
|
482 | + } elseif (true === $object_name) { |
|
483 | 483 | // Get all sections |
484 | 484 | |
485 | 485 | // Late init |
486 | - foreach ( self::$sections[ $object_type ] as $object_name => $object_sections ) { |
|
487 | - $sections = array_merge( $sections, array_values( $this->get_sections( $object_type, $object_name, $screen ) ) ); |
|
486 | + foreach (self::$sections[$object_type] as $object_name => $object_sections) { |
|
487 | + $sections = array_merge($sections, array_values($this->get_sections($object_type, $object_name, $screen))); |
|
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | * @param string $object_name Object name (for post types and taxonomies). |
503 | 503 | * @param array $args Section arguments. |
504 | 504 | */ |
505 | - public function add_section( $object_type, $id, $object_name = null, $args = array() ) { |
|
505 | + public function add_section($object_type, $id, $object_name = null, $args = array()) { |
|
506 | 506 | |
507 | - if ( empty( $id ) && empty( $args ) ) { |
|
507 | + if (empty($id) && empty($args)) { |
|
508 | 508 | return; |
509 | 509 | } |
510 | 510 | |
511 | - if ( is_a( $id, 'WP_Fields_API_Section' ) ) { |
|
511 | + if (is_a($id, 'WP_Fields_API_Section')) { |
|
512 | 512 | $section = $id; |
513 | 513 | |
514 | 514 | $id = $section->id; |
@@ -517,19 +517,19 @@ discard block |
||
517 | 517 | $section = $args; |
518 | 518 | } |
519 | 519 | |
520 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
521 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
520 | + if (empty($object_name) && ! empty($object_type)) { |
|
521 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( ! isset( self::$sections[ $object_type ] ) ) { |
|
525 | - self::$sections[ $object_type ] = array(); |
|
524 | + if ( ! isset(self::$sections[$object_type])) { |
|
525 | + self::$sections[$object_type] = array(); |
|
526 | 526 | } |
527 | 527 | |
528 | - if ( ! isset( self::$sections[ $object_type ][ $object_name ] ) ) { |
|
529 | - self::$sections[ $object_type ][ $object_name ] = array(); |
|
528 | + if ( ! isset(self::$sections[$object_type][$object_name])) { |
|
529 | + self::$sections[$object_type][$object_name] = array(); |
|
530 | 530 | } |
531 | 531 | |
532 | - self::$sections[ $object_type ][ $object_name ][ $id ] = $section; |
|
532 | + self::$sections[$object_type][$object_name][$id] = $section; |
|
533 | 533 | |
534 | 534 | } |
535 | 535 | |
@@ -544,19 +544,19 @@ discard block |
||
544 | 544 | * |
545 | 545 | * @return WP_Fields_API_Section|null Requested section instance. |
546 | 546 | */ |
547 | - public function get_section( $object_type, $id, $object_name = null ) { |
|
547 | + public function get_section($object_type, $id, $object_name = null) { |
|
548 | 548 | |
549 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
550 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
549 | + if (empty($object_name) && ! empty($object_type)) { |
|
550 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | $section = null; |
554 | 554 | |
555 | - if ( isset( self::$sections[ $object_type ][ $object_name ][ $id ] ) ) { |
|
555 | + if (isset(self::$sections[$object_type][$object_name][$id])) { |
|
556 | 556 | // Late init |
557 | - self::$sections[ $object_type ][ $object_name ][ $id ] = $this->setup_section( $object_type, $id, $object_name, self::$sections[ $object_type ][ $object_name ][ $id ] ); |
|
557 | + self::$sections[$object_type][$object_name][$id] = $this->setup_section($object_type, $id, $object_name, self::$sections[$object_type][$object_name][$id]); |
|
558 | 558 | |
559 | - $section = self::$sections[ $object_type ][ $object_name ][ $id ]; |
|
559 | + $section = self::$sections[$object_type][$object_name][$id]; |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | return $section; |
@@ -575,26 +575,26 @@ discard block |
||
575 | 575 | * |
576 | 576 | * @return WP_Fields_API_Screen|null $section The section object. |
577 | 577 | */ |
578 | - public function setup_section( $object_type, $id, $object_name = null, $args = null ) { |
|
578 | + public function setup_section($object_type, $id, $object_name = null, $args = null) { |
|
579 | 579 | |
580 | 580 | $section = null; |
581 | 581 | |
582 | 582 | $section_class = 'WP_Fields_API_Section'; |
583 | 583 | |
584 | - if ( is_a( $args, $section_class ) ) { |
|
584 | + if (is_a($args, $section_class)) { |
|
585 | 585 | $section = $args; |
586 | - } elseif ( is_array( $args ) ) { |
|
586 | + } elseif (is_array($args)) { |
|
587 | 587 | $args['object_name'] = $object_name; |
588 | 588 | |
589 | - if ( ! empty( $args['type'] ) ) { |
|
590 | - if ( ! empty( self::$registered_section_types[ $args['type'] ] ) ) { |
|
591 | - $section_class = self::$registered_section_types[ $args['type'] ]; |
|
592 | - } elseif ( in_array( $args['type'], self::$registered_section_types ) ) { |
|
589 | + if ( ! empty($args['type'])) { |
|
590 | + if ( ! empty(self::$registered_section_types[$args['type']])) { |
|
591 | + $section_class = self::$registered_section_types[$args['type']]; |
|
592 | + } elseif (in_array($args['type'], self::$registered_section_types)) { |
|
593 | 593 | $section_class = $args['type']; |
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
597 | - $section = new $section_class( $object_type, $id, $args ); |
|
597 | + $section = new $section_class($object_type, $id, $args); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | return $section; |
@@ -610,29 +610,29 @@ discard block |
||
610 | 610 | * @param string $id Section ID to remove, set true to remove all sections from an object. |
611 | 611 | * @param string $object_name Object name (for post types and taxonomies), set true to remove to all objects from an object type. |
612 | 612 | */ |
613 | - public function remove_section( $object_type, $id, $object_name = null ) { |
|
613 | + public function remove_section($object_type, $id, $object_name = null) { |
|
614 | 614 | |
615 | - if ( true === $object_type ) { |
|
615 | + if (true === $object_type) { |
|
616 | 616 | // Remove all sections |
617 | 617 | self::$sections = array(); |
618 | - } elseif ( true === $object_name ) { |
|
618 | + } elseif (true === $object_name) { |
|
619 | 619 | // Remove all sections for an object type |
620 | - if ( isset( self::$sections[ $object_type ] ) ) { |
|
621 | - unset( self::$sections[ $object_type ] ); |
|
620 | + if (isset(self::$sections[$object_type])) { |
|
621 | + unset(self::$sections[$object_type]); |
|
622 | 622 | } |
623 | 623 | } else { |
624 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
625 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
624 | + if (empty($object_name) && ! empty($object_type)) { |
|
625 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
626 | 626 | } |
627 | 627 | |
628 | - if ( true === $id && null !== $object_name ) { |
|
628 | + if (true === $id && null !== $object_name) { |
|
629 | 629 | // Remove all sections for an object type |
630 | - if ( isset( self::$sections[ $object_type ][ $object_name ] ) ) { |
|
631 | - unset( self::$sections[ $object_type ][ $object_name ] ); |
|
630 | + if (isset(self::$sections[$object_type][$object_name])) { |
|
631 | + unset(self::$sections[$object_type][$object_name]); |
|
632 | 632 | } |
633 | - } elseif ( isset( self::$sections[ $object_type ][ $object_name ][ $id ] ) ) { |
|
633 | + } elseif (isset(self::$sections[$object_type][$object_name][$id])) { |
|
634 | 634 | // Remove section from object type and name |
635 | - unset( self::$sections[ $object_type ][ $object_name ][ $id ] ); |
|
635 | + unset(self::$sections[$object_type][$object_name][$id]); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | * @param string $type Section type ID. |
649 | 649 | * @param string $section_class Name of a custom section which is a subclass of WP_Fields_API_Section. |
650 | 650 | */ |
651 | - public function register_section_type( $type, $section_class = null ) { |
|
651 | + public function register_section_type($type, $section_class = null) { |
|
652 | 652 | |
653 | - if ( null === $section_class ) { |
|
653 | + if (null === $section_class) { |
|
654 | 654 | $section_class = $type; |
655 | 655 | } |
656 | 656 | |
657 | - self::$registered_section_types[ $type ] = $section_class; |
|
657 | + self::$registered_section_types[$type] = $section_class; |
|
658 | 658 | |
659 | 659 | } |
660 | 660 | |
@@ -668,8 +668,8 @@ discard block |
||
668 | 668 | /** |
669 | 669 | * @var $section WP_Fields_API_Section |
670 | 670 | */ |
671 | - foreach ( self::$registered_control_types as $section_type => $section_class ) { |
|
672 | - $section = $this->setup_section( null, 'temp', null, array( 'type' => $section_type ) ); |
|
671 | + foreach (self::$registered_control_types as $section_type => $section_class) { |
|
672 | + $section = $this->setup_section(null, 'temp', null, array('type' => $section_type)); |
|
673 | 673 | |
674 | 674 | $section->print_template(); |
675 | 675 | } |
@@ -686,37 +686,37 @@ discard block |
||
686 | 686 | * |
687 | 687 | * @return WP_Fields_API_Field[] |
688 | 688 | */ |
689 | - public function get_fields( $object_type = null, $object_name = null ) { |
|
689 | + public function get_fields($object_type = null, $object_name = null) { |
|
690 | 690 | |
691 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
692 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
691 | + if (empty($object_name) && ! empty($object_type)) { |
|
692 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | $fields = array(); |
696 | 696 | |
697 | - if ( null === $object_type ) { |
|
697 | + if (null === $object_type) { |
|
698 | 698 | // Late init |
699 | - foreach ( self::$fields as $object_type => $object_names ) { |
|
700 | - foreach ( $object_names as $object_name => $fields ) { |
|
701 | - $this->get_fields( $object_type, $object_name ); |
|
699 | + foreach (self::$fields as $object_type => $object_names) { |
|
700 | + foreach ($object_names as $object_name => $fields) { |
|
701 | + $this->get_fields($object_type, $object_name); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
705 | 705 | $fields = self::$fields; |
706 | - } elseif ( isset( self::$fields[ $object_type ][ $object_name ] ) ) { |
|
706 | + } elseif (isset(self::$fields[$object_type][$object_name])) { |
|
707 | 707 | // Late init |
708 | - foreach ( self::$fields[ $object_type ][ $object_name ] as $id => $field ) { |
|
708 | + foreach (self::$fields[$object_type][$object_name] as $id => $field) { |
|
709 | 709 | // Late init |
710 | - self::$fields[ $object_type ][ $object_name ][ $id ] = $this->setup_field( $object_type, $id, $object_name, $field ); |
|
710 | + self::$fields[$object_type][$object_name][$id] = $this->setup_field($object_type, $id, $object_name, $field); |
|
711 | 711 | } |
712 | 712 | |
713 | - $fields = self::$fields[ $object_type ][ $object_name ]; |
|
714 | - } elseif ( true === $object_name ) { |
|
713 | + $fields = self::$fields[$object_type][$object_name]; |
|
714 | + } elseif (true === $object_name) { |
|
715 | 715 | // Get all fields |
716 | 716 | |
717 | 717 | // Late init |
718 | - foreach ( self::$fields[ $object_type ] as $object_name => $object_fields ) { |
|
719 | - $fields = array_merge( $fields, array_values( $this->get_fields( $object_type, $object_name ) ) ); |
|
718 | + foreach (self::$fields[$object_type] as $object_name => $object_fields) { |
|
719 | + $fields = array_merge($fields, array_values($this->get_fields($object_type, $object_name))); |
|
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
@@ -735,15 +735,15 @@ discard block |
||
735 | 735 | * @param array $args Field arguments; passed to WP_Fields_API_Field |
736 | 736 | * constructor. |
737 | 737 | */ |
738 | - public function add_field( $object_type, $id, $object_name = null, $args = array() ) { |
|
738 | + public function add_field($object_type, $id, $object_name = null, $args = array()) { |
|
739 | 739 | |
740 | - if ( empty( $id ) && empty( $args ) ) { |
|
740 | + if (empty($id) && empty($args)) { |
|
741 | 741 | return; |
742 | 742 | } |
743 | 743 | |
744 | 744 | $control = array(); |
745 | 745 | |
746 | - if ( is_a( $id, 'WP_Fields_API_Field' ) ) { |
|
746 | + if (is_a($id, 'WP_Fields_API_Field')) { |
|
747 | 747 | $field = $id; |
748 | 748 | |
749 | 749 | $id = $field->id; |
@@ -751,46 +751,46 @@ discard block |
||
751 | 751 | // Save for late init |
752 | 752 | $field = $args; |
753 | 753 | |
754 | - if ( isset( $field['control'] ) ) { |
|
754 | + if (isset($field['control'])) { |
|
755 | 755 | $control = $field['control']; |
756 | 756 | |
757 | 757 | // Remove from field args |
758 | - unset( $field['control'] ); |
|
758 | + unset($field['control']); |
|
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
763 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
762 | + if (empty($object_name) && ! empty($object_type)) { |
|
763 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
764 | 764 | } |
765 | 765 | |
766 | - if ( ! isset( self::$fields[ $object_type ] ) ) { |
|
767 | - self::$fields[ $object_type ] = array(); |
|
766 | + if ( ! isset(self::$fields[$object_type])) { |
|
767 | + self::$fields[$object_type] = array(); |
|
768 | 768 | } |
769 | 769 | |
770 | - if ( ! isset( self::$fields[ $object_type ][ $object_name ] ) ) { |
|
771 | - self::$fields[ $object_type ][ $object_name ] = array(); |
|
770 | + if ( ! isset(self::$fields[$object_type][$object_name])) { |
|
771 | + self::$fields[$object_type][$object_name] = array(); |
|
772 | 772 | } |
773 | 773 | |
774 | - self::$fields[ $object_type ][ $object_name ][ $id ] = $field; |
|
774 | + self::$fields[$object_type][$object_name][$id] = $field; |
|
775 | 775 | |
776 | 776 | // Control handling |
777 | - if ( ! empty( $control ) ) { |
|
777 | + if ( ! empty($control)) { |
|
778 | 778 | // Generate Control ID if not set |
779 | - if ( empty( $control['id'] ) ) { |
|
780 | - $control['id'] = 'control_' . sanitize_key( $object_type ) . '_' . sanitize_key( $object_name ) . '_' . sanitize_key( $id ); |
|
779 | + if (empty($control['id'])) { |
|
780 | + $control['id'] = 'control_'.sanitize_key($object_type).'_'.sanitize_key($object_name).'_'.sanitize_key($id); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | // Get Control ID |
784 | 784 | $control_id = $control['id']; |
785 | 785 | |
786 | 786 | // Remove ID from control args |
787 | - unset( $control['id'] ); |
|
787 | + unset($control['id']); |
|
788 | 788 | |
789 | 789 | // Add field |
790 | 790 | $control['fields'] = $id; |
791 | 791 | |
792 | 792 | // Add control for field |
793 | - $this->add_control( $object_type, $control_id, $object_name, $control ); |
|
793 | + $this->add_control($object_type, $control_id, $object_name, $control); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | } |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * |
807 | 807 | * @return WP_Fields_API_Field|null |
808 | 808 | */ |
809 | - public function get_field( $object_type, $id, $object_name = null ) { |
|
809 | + public function get_field($object_type, $id, $object_name = null) { |
|
810 | 810 | |
811 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
812 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
811 | + if (empty($object_name) && ! empty($object_type)) { |
|
812 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | $field = null; |
816 | 816 | |
817 | - if ( isset( self::$fields[ $object_type ][ $object_name ][ $id ] ) ) { |
|
817 | + if (isset(self::$fields[$object_type][$object_name][$id])) { |
|
818 | 818 | // Late init |
819 | - self::$fields[ $object_type ][ $object_name ][ $id ] = $this->setup_field( $object_type, $id, $object_name, self::$fields[ $object_type ][ $object_name ][ $id ] ); |
|
819 | + self::$fields[$object_type][$object_name][$id] = $this->setup_field($object_type, $id, $object_name, self::$fields[$object_type][$object_name][$id]); |
|
820 | 820 | |
821 | - $field = self::$fields[ $object_type ][ $object_name ][ $id ]; |
|
821 | + $field = self::$fields[$object_type][$object_name][$id]; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $field; |
@@ -837,26 +837,26 @@ discard block |
||
837 | 837 | * |
838 | 838 | * @return WP_Fields_API_Screen|null $field The field object. |
839 | 839 | */ |
840 | - public function setup_field( $object_type, $id, $object_name = null, $args = null ) { |
|
840 | + public function setup_field($object_type, $id, $object_name = null, $args = null) { |
|
841 | 841 | |
842 | 842 | $field = null; |
843 | 843 | |
844 | 844 | $field_class = 'WP_Fields_API_Field'; |
845 | 845 | |
846 | - if ( is_a( $args, $field_class ) ) { |
|
846 | + if (is_a($args, $field_class)) { |
|
847 | 847 | $field = $args; |
848 | - } elseif ( is_array( $args ) ) { |
|
848 | + } elseif (is_array($args)) { |
|
849 | 849 | $args['object_name'] = $object_name; |
850 | 850 | |
851 | - if ( ! empty( $args['type'] ) ) { |
|
852 | - if ( ! empty( self::$registered_field_types[ $args['type'] ] ) ) { |
|
853 | - $field_class = self::$registered_field_types[ $args['type'] ]; |
|
854 | - } elseif ( in_array( $args['type'], self::$registered_field_types ) ) { |
|
851 | + if ( ! empty($args['type'])) { |
|
852 | + if ( ! empty(self::$registered_field_types[$args['type']])) { |
|
853 | + $field_class = self::$registered_field_types[$args['type']]; |
|
854 | + } elseif (in_array($args['type'], self::$registered_field_types)) { |
|
855 | 855 | $field_class = $args['type']; |
856 | 856 | } |
857 | 857 | } |
858 | 858 | |
859 | - $field = new $field_class( $object_type, $id, $args ); |
|
859 | + $field = new $field_class($object_type, $id, $args); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | return $field; |
@@ -872,29 +872,29 @@ discard block |
||
872 | 872 | * @param string $id Field ID to remove, set true to remove all fields from an object. |
873 | 873 | * @param string $object_name Object name (for post types and taxonomies), set true to remove to all objects from an object type. |
874 | 874 | */ |
875 | - public function remove_field( $object_type, $id, $object_name = null ) { |
|
875 | + public function remove_field($object_type, $id, $object_name = null) { |
|
876 | 876 | |
877 | - if ( true === $object_type ) { |
|
877 | + if (true === $object_type) { |
|
878 | 878 | // Remove all fields |
879 | 879 | self::$fields = array(); |
880 | - } elseif ( true === $object_name ) { |
|
880 | + } elseif (true === $object_name) { |
|
881 | 881 | // Remove all fields for an object type |
882 | - if ( isset( self::$fields[ $object_type ] ) ) { |
|
883 | - unset( self::$fields[ $object_type ] ); |
|
882 | + if (isset(self::$fields[$object_type])) { |
|
883 | + unset(self::$fields[$object_type]); |
|
884 | 884 | } |
885 | 885 | } else { |
886 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
887 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
886 | + if (empty($object_name) && ! empty($object_type)) { |
|
887 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
888 | 888 | } |
889 | 889 | |
890 | - if ( true === $id && null !== $object_name ) { |
|
890 | + if (true === $id && null !== $object_name) { |
|
891 | 891 | // Remove all fields for an object type |
892 | - if ( isset( self::$fields[ $object_type ][ $object_name ] ) ) { |
|
893 | - unset( self::$fields[ $object_type ][ $object_name ] ); |
|
892 | + if (isset(self::$fields[$object_type][$object_name])) { |
|
893 | + unset(self::$fields[$object_type][$object_name]); |
|
894 | 894 | } |
895 | - } elseif ( isset( self::$fields[ $object_type ][ $object_name ][ $id ] ) ) { |
|
895 | + } elseif (isset(self::$fields[$object_type][$object_name][$id])) { |
|
896 | 896 | // Remove field from object type and name |
897 | - unset( self::$fields[ $object_type ][ $object_name ][ $id ] ); |
|
897 | + unset(self::$fields[$object_type][$object_name][$id]); |
|
898 | 898 | } |
899 | 899 | } |
900 | 900 | |
@@ -910,13 +910,13 @@ discard block |
||
910 | 910 | * @param string $type Field type ID. |
911 | 911 | * @param string $screen_class Name of a custom field type which is a subclass of WP_Fields_API_Field. |
912 | 912 | */ |
913 | - public function register_field_type( $type, $field_class = null ) { |
|
913 | + public function register_field_type($type, $field_class = null) { |
|
914 | 914 | |
915 | - if ( null === $field_class ) { |
|
915 | + if (null === $field_class) { |
|
916 | 916 | $field_class = $type; |
917 | 917 | } |
918 | 918 | |
919 | - self::$registered_field_types[ $type ] = $field_class; |
|
919 | + self::$registered_field_types[$type] = $field_class; |
|
920 | 920 | |
921 | 921 | } |
922 | 922 | |
@@ -931,41 +931,41 @@ discard block |
||
931 | 931 | * |
932 | 932 | * @return WP_Fields_API_Control[] |
933 | 933 | */ |
934 | - public function get_controls( $object_type = null, $object_name = null, $section = null ) { |
|
934 | + public function get_controls($object_type = null, $object_name = null, $section = null) { |
|
935 | 935 | |
936 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
937 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
936 | + if (empty($object_name) && ! empty($object_type)) { |
|
937 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | $controls = array(); |
941 | 941 | |
942 | - if ( null === $object_type ) { |
|
942 | + if (null === $object_type) { |
|
943 | 943 | // Late init |
944 | - foreach ( self::$controls as $object_type => $object_names ) { |
|
945 | - foreach ( $object_names as $object_name => $controls ) { |
|
946 | - $this->get_controls( $object_type, $object_name ); |
|
944 | + foreach (self::$controls as $object_type => $object_names) { |
|
945 | + foreach ($object_names as $object_name => $controls) { |
|
946 | + $this->get_controls($object_type, $object_name); |
|
947 | 947 | } |
948 | 948 | } |
949 | 949 | |
950 | 950 | $controls = self::$controls; |
951 | 951 | |
952 | 952 | // Get only controls for a specific section |
953 | - if ( null !== $section ) { |
|
953 | + if (null !== $section) { |
|
954 | 954 | $section_controls = array(); |
955 | 955 | |
956 | - foreach ( $controls as $object_type => $object_names ) { |
|
957 | - foreach ( $object_names as $object_name => $object_controls ) { |
|
958 | - foreach ( $object_controls as $id => $control ) { |
|
959 | - if ( $section == $control->section->id ) { |
|
960 | - if ( ! isset( $section_controls[ $object_type ] ) ) { |
|
961 | - $section_controls[ $object_type ] = array(); |
|
956 | + foreach ($controls as $object_type => $object_names) { |
|
957 | + foreach ($object_names as $object_name => $object_controls) { |
|
958 | + foreach ($object_controls as $id => $control) { |
|
959 | + if ($section == $control->section->id) { |
|
960 | + if ( ! isset($section_controls[$object_type])) { |
|
961 | + $section_controls[$object_type] = array(); |
|
962 | 962 | } |
963 | 963 | |
964 | - if ( ! isset( $section_controls[ $object_type ][ $object_name ] ) ) { |
|
965 | - $section_controls[ $object_type ][ $object_name ] = array(); |
|
964 | + if ( ! isset($section_controls[$object_type][$object_name])) { |
|
965 | + $section_controls[$object_type][$object_name] = array(); |
|
966 | 966 | } |
967 | 967 | |
968 | - $section_controls[ $object_type ][ $object_name ][ $id ] = $control; |
|
968 | + $section_controls[$object_type][$object_name][$id] = $control; |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | } |
@@ -973,34 +973,34 @@ discard block |
||
973 | 973 | |
974 | 974 | $controls = $section_controls; |
975 | 975 | } |
976 | - } elseif ( isset( self::$controls[ $object_type ][ $object_name ] ) ) { |
|
976 | + } elseif (isset(self::$controls[$object_type][$object_name])) { |
|
977 | 977 | // Late init |
978 | - foreach ( self::$controls[ $object_type ][ $object_name ] as $id => $control ) { |
|
978 | + foreach (self::$controls[$object_type][$object_name] as $id => $control) { |
|
979 | 979 | // Late init |
980 | - self::$controls[ $object_type ][ $object_name ][ $id ] = $this->setup_control( $object_type, $id, $object_name, $control ); |
|
980 | + self::$controls[$object_type][$object_name][$id] = $this->setup_control($object_type, $id, $object_name, $control); |
|
981 | 981 | } |
982 | 982 | |
983 | - $controls = self::$controls[ $object_type ][ $object_name ]; |
|
983 | + $controls = self::$controls[$object_type][$object_name]; |
|
984 | 984 | |
985 | 985 | // Get only controls for a specific section |
986 | - if ( null !== $section ) { |
|
986 | + if (null !== $section) { |
|
987 | 987 | $section_controls = array(); |
988 | 988 | |
989 | - foreach ( $controls as $id => $control ) { |
|
989 | + foreach ($controls as $id => $control) { |
|
990 | 990 | // $control->section is not an object, like $control->field is |
991 | - if ( $section == $control->section ) { |
|
992 | - $section_controls[ $id ] = $control; |
|
991 | + if ($section == $control->section) { |
|
992 | + $section_controls[$id] = $control; |
|
993 | 993 | } |
994 | 994 | } |
995 | 995 | |
996 | 996 | $controls = $section_controls; |
997 | 997 | } |
998 | - } elseif ( true === $object_name ) { |
|
998 | + } elseif (true === $object_name) { |
|
999 | 999 | // Get all fields |
1000 | 1000 | |
1001 | 1001 | // Late init |
1002 | - foreach ( self::$controls[ $object_type ] as $object_name => $object_controls ) { |
|
1003 | - $controls = array_merge( $controls, array_values( $this->get_controls( $object_type, $object_name, $section ) ) ); |
|
1002 | + foreach (self::$controls[$object_type] as $object_name => $object_controls) { |
|
1003 | + $controls = array_merge($controls, array_values($this->get_controls($object_type, $object_name, $section))); |
|
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1019,13 +1019,13 @@ discard block |
||
1019 | 1019 | * @param array $args Control arguments; passed to WP_Fields_API_Control |
1020 | 1020 | * constructor. |
1021 | 1021 | */ |
1022 | - public function add_control( $object_type, $id, $object_name = null, $args = array() ) { |
|
1022 | + public function add_control($object_type, $id, $object_name = null, $args = array()) { |
|
1023 | 1023 | |
1024 | - if ( empty( $id ) && empty( $args ) ) { |
|
1024 | + if (empty($id) && empty($args)) { |
|
1025 | 1025 | return; |
1026 | 1026 | } |
1027 | 1027 | |
1028 | - if ( is_a( $id, 'WP_Fields_API_Control' ) ) { |
|
1028 | + if (is_a($id, 'WP_Fields_API_Control')) { |
|
1029 | 1029 | $control = $id; |
1030 | 1030 | |
1031 | 1031 | $id = $control->id; |
@@ -1034,19 +1034,19 @@ discard block |
||
1034 | 1034 | $control = $args; |
1035 | 1035 | } |
1036 | 1036 | |
1037 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
1038 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
1037 | + if (empty($object_name) && ! empty($object_type)) { |
|
1038 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | - if ( ! isset( self::$controls[ $object_type ] ) ) { |
|
1042 | - self::$controls[ $object_type ] = array(); |
|
1041 | + if ( ! isset(self::$controls[$object_type])) { |
|
1042 | + self::$controls[$object_type] = array(); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | - if ( ! isset( self::$controls[ $object_type ][ $object_name ] ) ) { |
|
1046 | - self::$controls[ $object_type ][ $object_name ] = array(); |
|
1045 | + if ( ! isset(self::$controls[$object_type][$object_name])) { |
|
1046 | + self::$controls[$object_type][$object_name] = array(); |
|
1047 | 1047 | } |
1048 | 1048 | |
1049 | - self::$controls[ $object_type ][ $object_name ][ $id ] = $control; |
|
1049 | + self::$controls[$object_type][$object_name][$id] = $control; |
|
1050 | 1050 | |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1061,19 +1061,19 @@ discard block |
||
1061 | 1061 | * |
1062 | 1062 | * @return WP_Fields_API_Control|null $control The control object. |
1063 | 1063 | */ |
1064 | - public function get_control( $object_type, $id, $object_name = null ) { |
|
1064 | + public function get_control($object_type, $id, $object_name = null) { |
|
1065 | 1065 | |
1066 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
1067 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
1066 | + if (empty($object_name) && ! empty($object_type)) { |
|
1067 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | $control = null; |
1071 | 1071 | |
1072 | - if ( isset( self::$controls[ $object_type ][ $object_name ][ $id ] ) ) { |
|
1072 | + if (isset(self::$controls[$object_type][$object_name][$id])) { |
|
1073 | 1073 | // Late init |
1074 | - self::$controls[ $object_type ][ $object_name ][ $id ] = $this->setup_control( $object_type, $id, $object_name, self::$controls[ $object_type ][ $object_name ][ $id ] ); |
|
1074 | + self::$controls[$object_type][$object_name][$id] = $this->setup_control($object_type, $id, $object_name, self::$controls[$object_type][$object_name][$id]); |
|
1075 | 1075 | |
1076 | - $control = self::$controls[ $object_type ][ $object_name ][ $id ]; |
|
1076 | + $control = self::$controls[$object_type][$object_name][$id]; |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | return $control; |
@@ -1092,26 +1092,26 @@ discard block |
||
1092 | 1092 | * |
1093 | 1093 | * @return WP_Fields_API_Control|null $control The control object. |
1094 | 1094 | */ |
1095 | - public function setup_control( $object_type, $id, $object_name = null, $args = null ) { |
|
1095 | + public function setup_control($object_type, $id, $object_name = null, $args = null) { |
|
1096 | 1096 | |
1097 | 1097 | $control = null; |
1098 | 1098 | |
1099 | 1099 | $control_class = 'WP_Fields_API_Control'; |
1100 | 1100 | |
1101 | - if ( is_a( $args, $control_class ) ) { |
|
1101 | + if (is_a($args, $control_class)) { |
|
1102 | 1102 | $control = $args; |
1103 | - } elseif ( is_array( $args ) ) { |
|
1103 | + } elseif (is_array($args)) { |
|
1104 | 1104 | $args['object_name'] = $object_name; |
1105 | 1105 | |
1106 | - if ( ! empty( $args['type'] ) ) { |
|
1107 | - if ( ! empty( self::$registered_control_types[ $args['type'] ] ) ) { |
|
1108 | - $control_class = self::$registered_control_types[ $args['type'] ]; |
|
1109 | - } elseif ( in_array( $args['type'], self::$registered_control_types ) ) { |
|
1106 | + if ( ! empty($args['type'])) { |
|
1107 | + if ( ! empty(self::$registered_control_types[$args['type']])) { |
|
1108 | + $control_class = self::$registered_control_types[$args['type']]; |
|
1109 | + } elseif (in_array($args['type'], self::$registered_control_types)) { |
|
1110 | 1110 | $control_class = $args['type']; |
1111 | 1111 | } |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - $control = new $control_class( $object_type, $id, $args ); |
|
1114 | + $control = new $control_class($object_type, $id, $args); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | return $control; |
@@ -1127,29 +1127,29 @@ discard block |
||
1127 | 1127 | * @param string $id Control ID to remove, set true to remove all controls from an object. |
1128 | 1128 | * @param string $object_name Object name (for post types and taxonomies), set true to remove to all objects from an object type. |
1129 | 1129 | */ |
1130 | - public function remove_control( $object_type, $id, $object_name = null ) { |
|
1130 | + public function remove_control($object_type, $id, $object_name = null) { |
|
1131 | 1131 | |
1132 | - if ( true === $object_type ) { |
|
1132 | + if (true === $object_type) { |
|
1133 | 1133 | // Remove all controls |
1134 | 1134 | self::$controls = array(); |
1135 | - } elseif ( true === $object_name ) { |
|
1135 | + } elseif (true === $object_name) { |
|
1136 | 1136 | // Remove all controls for an object type |
1137 | - if ( isset( self::$controls[ $object_type ] ) ) { |
|
1138 | - unset( self::$controls[ $object_type ] ); |
|
1137 | + if (isset(self::$controls[$object_type])) { |
|
1138 | + unset(self::$controls[$object_type]); |
|
1139 | 1139 | } |
1140 | 1140 | } else { |
1141 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
1142 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
1141 | + if (empty($object_name) && ! empty($object_type)) { |
|
1142 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | - if ( true === $id && null !== $object_name ) { |
|
1145 | + if (true === $id && null !== $object_name) { |
|
1146 | 1146 | // Remove all controls for an object type |
1147 | - if ( isset( self::$controls[ $object_type ][ $object_name ] ) ) { |
|
1148 | - unset( self::$controls[ $object_type ][ $object_name ] ); |
|
1147 | + if (isset(self::$controls[$object_type][$object_name])) { |
|
1148 | + unset(self::$controls[$object_type][$object_name]); |
|
1149 | 1149 | } |
1150 | - } elseif ( isset( self::$controls[ $object_type ][ $object_name ][ $id ] ) ) { |
|
1150 | + } elseif (isset(self::$controls[$object_type][$object_name][$id])) { |
|
1151 | 1151 | // Remove control from object type and name |
1152 | - unset( self::$controls[ $object_type ][ $object_name ][ $id ] ); |
|
1152 | + unset(self::$controls[$object_type][$object_name][$id]); |
|
1153 | 1153 | } |
1154 | 1154 | } |
1155 | 1155 | |
@@ -1165,13 +1165,13 @@ discard block |
||
1165 | 1165 | * @param string $type Control type ID. |
1166 | 1166 | * @param string $control_class Name of a custom control which is a subclass of WP_Fields_API_Control. |
1167 | 1167 | */ |
1168 | - public function register_control_type( $type, $control_class = null ) { |
|
1168 | + public function register_control_type($type, $control_class = null) { |
|
1169 | 1169 | |
1170 | - if ( null === $control_class ) { |
|
1170 | + if (null === $control_class) { |
|
1171 | 1171 | $control_class = $type; |
1172 | 1172 | } |
1173 | 1173 | |
1174 | - self::$registered_control_types[ $type ] = $control_class; |
|
1174 | + self::$registered_control_types[$type] = $control_class; |
|
1175 | 1175 | |
1176 | 1176 | } |
1177 | 1177 | |
@@ -1185,8 +1185,8 @@ discard block |
||
1185 | 1185 | /** |
1186 | 1186 | * @var $control WP_Fields_API_Control |
1187 | 1187 | */ |
1188 | - foreach ( self::$registered_control_types as $control_type => $control_class ) { |
|
1189 | - $control = $this->setup_control( null, 'temp', null, array( 'type' => $control_type ) ); |
|
1188 | + foreach (self::$registered_control_types as $control_type => $control_class) { |
|
1189 | + $control = $this->setup_control(null, 'temp', null, array('type' => $control_type)); |
|
1190 | 1190 | |
1191 | 1191 | $control->print_template(); |
1192 | 1192 | } |
@@ -1203,13 +1203,13 @@ discard block |
||
1203 | 1203 | * |
1204 | 1204 | * @return int |
1205 | 1205 | */ |
1206 | - protected final function _cmp_priority( $a, $b ) { |
|
1206 | + protected final function _cmp_priority($a, $b) { |
|
1207 | 1207 | |
1208 | - if ( is_int( $a->priority ) && is_int( $b->priority ) ) { |
|
1208 | + if (is_int($a->priority) && is_int($b->priority)) { |
|
1209 | 1209 | // Priority integers |
1210 | 1210 | $compare = $a->priority - $b->priority; |
1211 | 1211 | |
1212 | - if ( $a->priority === $b->priority ) { |
|
1212 | + if ($a->priority === $b->priority) { |
|
1213 | 1213 | $compare = $a->instance_number - $a->instance_number; |
1214 | 1214 | } |
1215 | 1215 | } else { |
@@ -1232,13 +1232,13 @@ discard block |
||
1232 | 1232 | * |
1233 | 1233 | * @param string $object_type Object type. |
1234 | 1234 | */ |
1235 | - public function prepare_controls( $object_type = null ) { |
|
1235 | + public function prepare_controls($object_type = null) { |
|
1236 | 1236 | |
1237 | 1237 | // Prepare controls for all object types |
1238 | - foreach ( self::$fields as $object => $object_names ) { |
|
1239 | - if ( null === $object_type || $object === $object_type ) { |
|
1240 | - foreach ( $object_names as $object_name => $fields ) { |
|
1241 | - $this->prepare_object_controls( $object, $object_name ); |
|
1238 | + foreach (self::$fields as $object => $object_names) { |
|
1239 | + if (null === $object_type || $object === $object_type) { |
|
1240 | + foreach ($object_names as $object_name => $fields) { |
|
1241 | + $this->prepare_object_controls($object, $object_name); |
|
1242 | 1242 | } |
1243 | 1243 | } |
1244 | 1244 | } |
@@ -1257,10 +1257,10 @@ discard block |
||
1257 | 1257 | * @param string $object_type Object type. |
1258 | 1258 | * @param string $object_name Object name (for post types and taxonomies). |
1259 | 1259 | */ |
1260 | - public function prepare_object_controls( $object_type, $object_name = null ) { |
|
1260 | + public function prepare_object_controls($object_type, $object_name = null) { |
|
1261 | 1261 | |
1262 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
1263 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
1262 | + if (empty($object_name) && ! empty($object_type)) { |
|
1263 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | // Reset prepared IDs |
@@ -1274,69 +1274,69 @@ discard block |
||
1274 | 1274 | // Setup |
1275 | 1275 | |
1276 | 1276 | // Get controls |
1277 | - $controls = $this->get_controls( $object_type, $object_name ); |
|
1277 | + $controls = $this->get_controls($object_type, $object_name); |
|
1278 | 1278 | |
1279 | 1279 | // Get sections |
1280 | - $sections = $this->get_sections( $object_type, $object_name ); |
|
1280 | + $sections = $this->get_sections($object_type, $object_name); |
|
1281 | 1281 | |
1282 | 1282 | // Get screens |
1283 | - $screens = $this->get_screens( $object_type, $object_name ); |
|
1283 | + $screens = $this->get_screens($object_type, $object_name); |
|
1284 | 1284 | |
1285 | 1285 | // Controls |
1286 | 1286 | |
1287 | 1287 | // Sort controls by priority |
1288 | - uasort( $controls, array( $this, '_cmp_priority' ) ); |
|
1288 | + uasort($controls, array($this, '_cmp_priority')); |
|
1289 | 1289 | |
1290 | - foreach ( $controls as $id => $control ) { |
|
1290 | + foreach ($controls as $id => $control) { |
|
1291 | 1291 | // Check if section or screen exists |
1292 | - if ( $control->section && ! isset( $sections[ $control->section ] ) ) { |
|
1292 | + if ($control->section && ! isset($sections[$control->section])) { |
|
1293 | 1293 | continue; |
1294 | - } elseif ( $control->screen && ! isset( $screens[ $control->screen ] ) ) { |
|
1294 | + } elseif ($control->screen && ! isset($screens[$control->screen])) { |
|
1295 | 1295 | continue; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | 1298 | // Check if control can be used by user |
1299 | - if ( ! $control->check_capabilities() ) { |
|
1299 | + if ( ! $control->check_capabilities()) { |
|
1300 | 1300 | continue; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | // Add to prepared IDs |
1304 | 1304 | $prepared_ids['control'][] = $id; |
1305 | 1305 | |
1306 | - if ( $control->section ) { |
|
1306 | + if ($control->section) { |
|
1307 | 1307 | // Add control to section controls |
1308 | - $sections[ $control->section ]->controls[] = $control; |
|
1309 | - } elseif ( $control->screen ) { |
|
1308 | + $sections[$control->section]->controls[] = $control; |
|
1309 | + } elseif ($control->screen) { |
|
1310 | 1310 | // Add control to screen controls |
1311 | - $screens[ $control->screen ]->controls[] = $control; |
|
1311 | + $screens[$control->screen]->controls[] = $control; |
|
1312 | 1312 | } |
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | // Sections |
1316 | 1316 | |
1317 | 1317 | // Sort sections by priority |
1318 | - uasort( $sections, array( $this, '_cmp_priority' ) ); |
|
1318 | + uasort($sections, array($this, '_cmp_priority')); |
|
1319 | 1319 | |
1320 | - foreach ( $sections as $id => $section ) { |
|
1320 | + foreach ($sections as $id => $section) { |
|
1321 | 1321 | // Check if section can be seen by user |
1322 | - if ( ! $section->check_capabilities() ) { |
|
1322 | + if ( ! $section->check_capabilities()) { |
|
1323 | 1323 | continue; |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - if ( $section->controls ) { |
|
1326 | + if ($section->controls) { |
|
1327 | 1327 | // Sort section controls by priority |
1328 | - usort( $section->controls, array( $this, '_cmp_priority' ) ); |
|
1328 | + usort($section->controls, array($this, '_cmp_priority')); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | - if ( ! $section->screen ) { |
|
1331 | + if ( ! $section->screen) { |
|
1332 | 1332 | // Top-level section. |
1333 | 1333 | |
1334 | 1334 | // Add to prepared IDs |
1335 | 1335 | $prepared_ids['section'][] = $id; |
1336 | 1336 | $prepared_ids['container'][] = $id; |
1337 | - } elseif ( $section->screen && isset( $screens[ $section->screen ] ) ) { |
|
1337 | + } elseif ($section->screen && isset($screens[$section->screen])) { |
|
1338 | 1338 | // This section belongs to a screen. |
1339 | - $screens[ $section->screen ]->sections[ $id ] = $section; |
|
1339 | + $screens[$section->screen]->sections[$id] = $section; |
|
1340 | 1340 | |
1341 | 1341 | // Add to prepared IDs |
1342 | 1342 | $prepared_ids['section'][] = $id; |
@@ -1347,17 +1347,17 @@ discard block |
||
1347 | 1347 | // Screens |
1348 | 1348 | |
1349 | 1349 | // Sort screens by priority |
1350 | - uasort( $screens, array( $this, '_cmp_priority' ) ); |
|
1350 | + uasort($screens, array($this, '_cmp_priority')); |
|
1351 | 1351 | |
1352 | - foreach ( $screens as $id => $screen ) { |
|
1352 | + foreach ($screens as $id => $screen) { |
|
1353 | 1353 | // Check if screen has sections or can be seen by user |
1354 | - if ( ! $screen->check_capabilities() ) { |
|
1354 | + if ( ! $screen->check_capabilities()) { |
|
1355 | 1355 | continue; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - if ( $screen->sections ) { |
|
1358 | + if ($screen->sections) { |
|
1359 | 1359 | // Sort screen sections by priority |
1360 | - uasort( $screen->sections, array( $this, '_cmp_priority' ) ); |
|
1360 | + uasort($screen->sections, array($this, '_cmp_priority')); |
|
1361 | 1361 | } |
1362 | 1362 | |
1363 | 1363 | // Add to prepared IDs |
@@ -1366,67 +1366,67 @@ discard block |
||
1366 | 1366 | } |
1367 | 1367 | |
1368 | 1368 | // Merge screens and top-level sections together. |
1369 | - $containers = array_merge( $screens, $sections ); |
|
1369 | + $containers = array_merge($screens, $sections); |
|
1370 | 1370 | |
1371 | 1371 | // Sort containers by priority |
1372 | - uasort( $containers, array( $this, '_cmp_priority' ) ); |
|
1372 | + uasort($containers, array($this, '_cmp_priority')); |
|
1373 | 1373 | |
1374 | 1374 | // Saving |
1375 | 1375 | |
1376 | 1376 | // Save controls |
1377 | - if ( ! isset( self::$controls[ $object_type ] ) ) { |
|
1378 | - self::$controls[ $object_type ] = array(); |
|
1377 | + if ( ! isset(self::$controls[$object_type])) { |
|
1378 | + self::$controls[$object_type] = array(); |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | - if ( ! isset( self::$controls[ $object_type ][ $object_name ] ) ) { |
|
1382 | - self::$controls[ $object_type ][ $object_name ] = array(); |
|
1381 | + if ( ! isset(self::$controls[$object_type][$object_name])) { |
|
1382 | + self::$controls[$object_type][$object_name] = array(); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | - self::$controls[ $object_type ][ $object_name ] = $controls; |
|
1385 | + self::$controls[$object_type][$object_name] = $controls; |
|
1386 | 1386 | |
1387 | 1387 | // Save sections |
1388 | - if ( ! isset( self::$sections[ $object_type ] ) ) { |
|
1389 | - self::$sections[ $object_type ] = array(); |
|
1388 | + if ( ! isset(self::$sections[$object_type])) { |
|
1389 | + self::$sections[$object_type] = array(); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | - if ( ! isset( self::$sections[ $object_type ][ $object_name ] ) ) { |
|
1393 | - self::$sections[ $object_type ][ $object_name ] = array(); |
|
1392 | + if ( ! isset(self::$sections[$object_type][$object_name])) { |
|
1393 | + self::$sections[$object_type][$object_name] = array(); |
|
1394 | 1394 | } |
1395 | 1395 | |
1396 | - self::$sections[ $object_type ][ $object_name ] = $sections; |
|
1396 | + self::$sections[$object_type][$object_name] = $sections; |
|
1397 | 1397 | |
1398 | 1398 | // Save screens |
1399 | - if ( ! isset( self::$screens[ $object_type ] ) ) { |
|
1400 | - self::$screens[ $object_type ] = array(); |
|
1399 | + if ( ! isset(self::$screens[$object_type])) { |
|
1400 | + self::$screens[$object_type] = array(); |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | - if ( ! isset( self::$screens[ $object_type ][ $object_name ] ) ) { |
|
1404 | - self::$screens[ $object_type ][ $object_name ] = array(); |
|
1403 | + if ( ! isset(self::$screens[$object_type][$object_name])) { |
|
1404 | + self::$screens[$object_type][$object_name] = array(); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | - self::$screens[ $object_type ][ $object_name ] = $screens; |
|
1407 | + self::$screens[$object_type][$object_name] = $screens; |
|
1408 | 1408 | |
1409 | 1409 | // Save containers |
1410 | - if ( ! isset( self::$containers[ $object_type ] ) ) { |
|
1411 | - self::$containers[ $object_type ] = array(); |
|
1410 | + if ( ! isset(self::$containers[$object_type])) { |
|
1411 | + self::$containers[$object_type] = array(); |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | - if ( ! isset( self::$containers[ $object_type ][ $object_name ] ) ) { |
|
1415 | - self::$containers[ $object_type ][ $object_name ] = array(); |
|
1414 | + if ( ! isset(self::$containers[$object_type][$object_name])) { |
|
1415 | + self::$containers[$object_type][$object_name] = array(); |
|
1416 | 1416 | } |
1417 | 1417 | |
1418 | - self::$containers[ $object_type ][ $object_name ] = $containers; |
|
1418 | + self::$containers[$object_type][$object_name] = $containers; |
|
1419 | 1419 | |
1420 | 1420 | // Saved prepared IDs |
1421 | - if ( ! isset( self::$prepared_ids[ $object_type ] ) ) { |
|
1422 | - self::$prepared_ids[ $object_type ] = array(); |
|
1421 | + if ( ! isset(self::$prepared_ids[$object_type])) { |
|
1422 | + self::$prepared_ids[$object_type] = array(); |
|
1423 | 1423 | } |
1424 | 1424 | |
1425 | - if ( ! isset( self::$prepared_ids[ $object_type ][ $object_name ] ) ) { |
|
1426 | - self::$prepared_ids[ $object_type ][ $object_name ] = array(); |
|
1425 | + if ( ! isset(self::$prepared_ids[$object_type][$object_name])) { |
|
1426 | + self::$prepared_ids[$object_type][$object_name] = array(); |
|
1427 | 1427 | } |
1428 | 1428 | |
1429 | - self::$prepared_ids[ $object_type ][ $object_name ] = $prepared_ids; |
|
1429 | + self::$prepared_ids[$object_type][$object_name] = $prepared_ids; |
|
1430 | 1430 | |
1431 | 1431 | } |
1432 | 1432 | |
@@ -1438,23 +1438,23 @@ discard block |
||
1438 | 1438 | public function register_controls() { |
1439 | 1439 | |
1440 | 1440 | /* Control Types */ |
1441 | - $this->register_control_type( 'text', 'WP_Fields_API_Control' ); |
|
1442 | - $this->register_control_type( 'checkbox', 'WP_Fields_API_Checkbox_Control' ); |
|
1443 | - $this->register_control_type( 'multi-checkbox', 'WP_Fields_API_Multi_Checkbox_Control' ); |
|
1444 | - $this->register_control_type( 'radio', 'WP_Fields_API_Radio_Control' ); |
|
1445 | - $this->register_control_type( 'select', 'WP_Fields_API_Select_Control' ); |
|
1446 | - $this->register_control_type( 'dropdown-pages', 'WP_Fields_API_Dropdown_Pages_Control' ); |
|
1447 | - $this->register_control_type( 'color', 'WP_Fields_API_Color_Control' ); |
|
1448 | - $this->register_control_type( 'media', 'WP_Fields_API_Media_Control' ); |
|
1449 | - $this->register_control_type( 'upload', 'WP_Fields_API_Upload_Control' ); |
|
1450 | - $this->register_control_type( 'image', 'WP_Fields_API_Image_Control' ); |
|
1441 | + $this->register_control_type('text', 'WP_Fields_API_Control'); |
|
1442 | + $this->register_control_type('checkbox', 'WP_Fields_API_Checkbox_Control'); |
|
1443 | + $this->register_control_type('multi-checkbox', 'WP_Fields_API_Multi_Checkbox_Control'); |
|
1444 | + $this->register_control_type('radio', 'WP_Fields_API_Radio_Control'); |
|
1445 | + $this->register_control_type('select', 'WP_Fields_API_Select_Control'); |
|
1446 | + $this->register_control_type('dropdown-pages', 'WP_Fields_API_Dropdown_Pages_Control'); |
|
1447 | + $this->register_control_type('color', 'WP_Fields_API_Color_Control'); |
|
1448 | + $this->register_control_type('media', 'WP_Fields_API_Media_Control'); |
|
1449 | + $this->register_control_type('upload', 'WP_Fields_API_Upload_Control'); |
|
1450 | + $this->register_control_type('image', 'WP_Fields_API_Image_Control'); |
|
1451 | 1451 | |
1452 | 1452 | /** |
1453 | 1453 | * Fires once WordPress has loaded, allowing control types to be registered. |
1454 | 1454 | * |
1455 | 1455 | * @param WP_Fields_API $this WP_Fields_API instance. |
1456 | 1456 | */ |
1457 | - do_action( 'fields_register_controls', $this ); |
|
1457 | + do_action('fields_register_controls', $this); |
|
1458 | 1458 | |
1459 | 1459 | } |
1460 | 1460 | |
@@ -1470,15 +1470,15 @@ discard block |
||
1470 | 1470 | * |
1471 | 1471 | * @return boolean |
1472 | 1472 | */ |
1473 | - public function is_prepared( $object_type, $type, $id, $object_name = null ) { |
|
1473 | + public function is_prepared($object_type, $type, $id, $object_name = null) { |
|
1474 | 1474 | |
1475 | - if ( empty( $object_name ) && ! empty( $object_type ) ) { |
|
1476 | - $object_name = '_' . $object_type; // Default to _object_type for internal handling |
|
1475 | + if (empty($object_name) && ! empty($object_type)) { |
|
1476 | + $object_name = '_'.$object_type; // Default to _object_type for internal handling |
|
1477 | 1477 | } |
1478 | 1478 | |
1479 | 1479 | $found = false; |
1480 | 1480 | |
1481 | - if ( ! empty( self::$prepared_ids[ $object_type ][ $object_name ][ $type ] ) && in_array( $id, self::$prepared_ids[ $object_type ][ $object_name ][ $type ] ) ) { |
|
1481 | + if ( ! empty(self::$prepared_ids[$object_type][$object_name][$type]) && in_array($id, self::$prepared_ids[$object_type][$object_name][$type])) { |
|
1482 | 1482 | $found = true; |
1483 | 1483 | } |
1484 | 1484 |
@@ -124,7 +124,6 @@ |
||
124 | 124 | * Test WP_Fields_API::add_screen() |
125 | 125 | * |
126 | 126 | * @param string $object_type |
127 | - * @param string $object_name |
|
128 | 127 | */ |
129 | 128 | public function test_add_screen_invalid( $object_type = 'post' ) { |
130 | 129 |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class WP_Test_Fields_API_Testcase |
|
4 | - * |
|
5 | - * @uses PHPUnit_Framework_TestCase |
|
6 | - */ |
|
3 | + * Class WP_Test_Fields_API_Testcase |
|
4 | + * |
|
5 | + * @uses PHPUnit_Framework_TestCase |
|
6 | + */ |
|
7 | 7 | class WP_Test_Fields_API_Testcase extends WP_UnitTestCase { |
8 | 8 | |
9 | 9 | public function tearDown() { |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | global $wp_fields; |
18 | 18 | |
19 | 19 | // Reset WP Fields instance for testing purposes |
20 | - $wp_fields->remove_screen( true, true ); |
|
21 | - $wp_fields->remove_section( true, true ); |
|
22 | - $wp_fields->remove_field( true, true ); |
|
23 | - $wp_fields->remove_control( true, true ); |
|
20 | + $wp_fields->remove_screen(true, true); |
|
21 | + $wp_fields->remove_section(true, true); |
|
22 | + $wp_fields->remove_field(true, true); |
|
23 | + $wp_fields->remove_control(true, true); |
|
24 | 24 | |
25 | 25 | } |
26 | 26 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | global $wp_fields; |
38 | 38 | |
39 | - $this->assertTrue( is_a( $wp_fields, 'WP_Fields_API' ) ); |
|
39 | + $this->assertTrue(is_a($wp_fields, 'WP_Fields_API')); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -51,29 +51,29 @@ discard block |
||
51 | 51 | global $wp_fields; |
52 | 52 | |
53 | 53 | // Add a section / screen |
54 | - $this->test_add_section( 'post', 'my_custom_post_type' ); |
|
54 | + $this->test_add_section('post', 'my_custom_post_type'); |
|
55 | 55 | |
56 | 56 | // Get containers for object type / name |
57 | - $containers = $wp_fields->get_containers( 'post', 'my_custom_post_type' ); |
|
57 | + $containers = $wp_fields->get_containers('post', 'my_custom_post_type'); |
|
58 | 58 | |
59 | 59 | // There are two containers, the screen and the section |
60 | - $this->assertEquals( 2, count( $containers ) ); |
|
60 | + $this->assertEquals(2, count($containers)); |
|
61 | 61 | |
62 | - $this->assertArrayHasKey( 'my_test_screen', $containers ); |
|
63 | - $this->assertArrayHasKey( 'my_test_section', $containers ); |
|
62 | + $this->assertArrayHasKey('my_test_screen', $containers); |
|
63 | + $this->assertArrayHasKey('my_test_section', $containers); |
|
64 | 64 | |
65 | 65 | // Get a containers that doesn't exist |
66 | - $containers = $wp_fields->get_containers( 'post' ); |
|
66 | + $containers = $wp_fields->get_containers('post'); |
|
67 | 67 | |
68 | - $this->assertEquals( 0, count( $containers ) ); |
|
68 | + $this->assertEquals(0, count($containers)); |
|
69 | 69 | |
70 | 70 | // Get all containers for all object types |
71 | 71 | $containers = $wp_fields->get_containers(); |
72 | 72 | |
73 | 73 | // Each array item is an object type with an array of object names |
74 | - $this->assertEquals( 1, count( $containers ) ); |
|
74 | + $this->assertEquals(1, count($containers)); |
|
75 | 75 | |
76 | - $this->assertArrayHasKey( 'post', $containers ); |
|
76 | + $this->assertArrayHasKey('post', $containers); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | global $wp_fields; |
89 | 89 | |
90 | 90 | // Add a section / screen |
91 | - $this->test_add_section( 'post', 'my_custom_post_type' ); |
|
91 | + $this->test_add_section('post', 'my_custom_post_type'); |
|
92 | 92 | |
93 | 93 | // Get containers for object type / name |
94 | - $containers = $wp_fields->get_containers( 'post', true ); |
|
94 | + $containers = $wp_fields->get_containers('post', true); |
|
95 | 95 | |
96 | 96 | // There are two containers, the screen and the section |
97 | - $this->assertEquals( 2, count( $containers ) ); |
|
97 | + $this->assertEquals(2, count($containers)); |
|
98 | 98 | |
99 | - $container_ids = wp_list_pluck( $containers, 'id' ); |
|
99 | + $container_ids = wp_list_pluck($containers, 'id'); |
|
100 | 100 | |
101 | - $this->assertContains( 'my_test_screen', $container_ids ); |
|
102 | - $this->assertContains( 'my_test_section', $container_ids ); |
|
101 | + $this->assertContains('my_test_screen', $container_ids); |
|
102 | + $this->assertContains('my_test_section', $container_ids); |
|
103 | 103 | |
104 | 104 | } |
105 | 105 | |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | * @param string $object_type |
110 | 110 | * @param string $object_name |
111 | 111 | */ |
112 | - public function test_add_screen( $object_type = 'post', $object_name = null ) { |
|
112 | + public function test_add_screen($object_type = 'post', $object_name = null) { |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @var $wp_fields WP_Fields_API |
116 | 116 | */ |
117 | 117 | global $wp_fields; |
118 | 118 | |
119 | - $wp_fields->add_screen( $object_type, 'my_test_screen', $object_name ); |
|
119 | + $wp_fields->add_screen($object_type, 'my_test_screen', $object_name); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | * @param string $object_type |
127 | 127 | * @param string $object_name |
128 | 128 | */ |
129 | - public function test_add_screen_invalid( $object_type = 'post' ) { |
|
129 | + public function test_add_screen_invalid($object_type = 'post') { |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @var $wp_fields WP_Fields_API |
133 | 133 | */ |
134 | 134 | global $wp_fields; |
135 | 135 | |
136 | - $wp_fields->add_screen( $object_type, null, null, array() ); |
|
136 | + $wp_fields->add_screen($object_type, null, null, array()); |
|
137 | 137 | |
138 | 138 | } |
139 | 139 | |
@@ -148,37 +148,37 @@ discard block |
||
148 | 148 | global $wp_fields; |
149 | 149 | |
150 | 150 | // Add a screen |
151 | - $this->test_add_screen( 'post', 'my_custom_post_type' ); |
|
151 | + $this->test_add_screen('post', 'my_custom_post_type'); |
|
152 | 152 | |
153 | 153 | // Get screens for object type / name |
154 | - $screens = $wp_fields->get_screens( 'post', 'my_custom_post_type' ); |
|
154 | + $screens = $wp_fields->get_screens('post', 'my_custom_post_type'); |
|
155 | 155 | |
156 | - $this->assertEquals( 1, count( $screens ) ); |
|
156 | + $this->assertEquals(1, count($screens)); |
|
157 | 157 | |
158 | - $this->assertArrayHasKey( 'my_test_screen', $screens ); |
|
158 | + $this->assertArrayHasKey('my_test_screen', $screens); |
|
159 | 159 | |
160 | 160 | // Get a screen that doesn't exist |
161 | - $screens = $wp_fields->get_screens( 'post', 'some_other_post_type' ); |
|
161 | + $screens = $wp_fields->get_screens('post', 'some_other_post_type'); |
|
162 | 162 | |
163 | - $this->assertEquals( 0, count( $screens ) ); |
|
163 | + $this->assertEquals(0, count($screens)); |
|
164 | 164 | |
165 | 165 | // Get all screens for object type |
166 | - $screens = $wp_fields->get_screens( 'post', true ); |
|
166 | + $screens = $wp_fields->get_screens('post', true); |
|
167 | 167 | |
168 | - $this->assertEquals( 1, count( $screens ) ); |
|
168 | + $this->assertEquals(1, count($screens)); |
|
169 | 169 | |
170 | - $screen_ids = wp_list_pluck( $screens, 'id' ); |
|
170 | + $screen_ids = wp_list_pluck($screens, 'id'); |
|
171 | 171 | |
172 | - $this->assertContains( 'my_test_screen', $screen_ids ); |
|
172 | + $this->assertContains('my_test_screen', $screen_ids); |
|
173 | 173 | |
174 | 174 | // Get all screens for all object types |
175 | 175 | $screens = $wp_fields->get_screens(); |
176 | 176 | |
177 | 177 | // Each array item is an object type with an array of object names |
178 | - $this->assertEquals( 1, count( $screens ) ); |
|
178 | + $this->assertEquals(1, count($screens)); |
|
179 | 179 | |
180 | 180 | // Array keys are object types |
181 | - $this->assertArrayHasKey( 'post', $screens ); |
|
181 | + $this->assertArrayHasKey('post', $screens); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | global $wp_fields; |
194 | 194 | |
195 | 195 | // Add a screen |
196 | - $this->test_add_screen( 'post' ); |
|
196 | + $this->test_add_screen('post'); |
|
197 | 197 | |
198 | 198 | // Get screens for object type / name |
199 | - $screens = $wp_fields->get_screens( 'post' ); |
|
199 | + $screens = $wp_fields->get_screens('post'); |
|
200 | 200 | |
201 | - $this->assertEquals( 1, count( $screens ) ); |
|
201 | + $this->assertEquals(1, count($screens)); |
|
202 | 202 | |
203 | - $this->assertArrayHasKey( 'my_test_screen', $screens ); |
|
203 | + $this->assertArrayHasKey('my_test_screen', $screens); |
|
204 | 204 | |
205 | 205 | } |
206 | 206 | |
@@ -215,24 +215,24 @@ discard block |
||
215 | 215 | global $wp_fields; |
216 | 216 | |
217 | 217 | // Add a screen |
218 | - $this->test_add_screen( 'post', 'my_custom_post_type' ); |
|
218 | + $this->test_add_screen('post', 'my_custom_post_type'); |
|
219 | 219 | |
220 | 220 | // Screen exists for this object type / name |
221 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
221 | + $screen = $wp_fields->get_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
222 | 222 | |
223 | - $this->assertNotEmpty( $screen ); |
|
223 | + $this->assertNotEmpty($screen); |
|
224 | 224 | |
225 | - $this->assertEquals( 'my_test_screen', $screen->id ); |
|
225 | + $this->assertEquals('my_test_screen', $screen->id); |
|
226 | 226 | |
227 | 227 | // Screen doesn't exist for this object type / name |
228 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen1' ); |
|
228 | + $screen = $wp_fields->get_screen('post', 'my_test_screen1'); |
|
229 | 229 | |
230 | - $this->assertEmpty( $screen ); |
|
230 | + $this->assertEmpty($screen); |
|
231 | 231 | |
232 | 232 | // Screen doesn't exist for this object type / name |
233 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen2', 'my_custom_post_type' ); |
|
233 | + $screen = $wp_fields->get_screen('post', 'my_test_screen2', 'my_custom_post_type'); |
|
234 | 234 | |
235 | - $this->assertEmpty( $screen ); |
|
235 | + $this->assertEmpty($screen); |
|
236 | 236 | |
237 | 237 | } |
238 | 238 | |
@@ -247,22 +247,22 @@ discard block |
||
247 | 247 | global $wp_fields; |
248 | 248 | |
249 | 249 | // Add a screen |
250 | - $this->test_add_screen( 'post', 'my_custom_post_type' ); |
|
250 | + $this->test_add_screen('post', 'my_custom_post_type'); |
|
251 | 251 | |
252 | 252 | // Screen exists for this object type / name |
253 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
253 | + $screen = $wp_fields->get_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
254 | 254 | |
255 | - $this->assertNotEmpty( $screen ); |
|
255 | + $this->assertNotEmpty($screen); |
|
256 | 256 | |
257 | - $this->assertEquals( 'my_test_screen', $screen->id ); |
|
257 | + $this->assertEquals('my_test_screen', $screen->id); |
|
258 | 258 | |
259 | 259 | // Remove screen |
260 | - $wp_fields->remove_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
260 | + $wp_fields->remove_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
261 | 261 | |
262 | 262 | // Screen no longer exists for this object type / name |
263 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
263 | + $screen = $wp_fields->get_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
264 | 264 | |
265 | - $this->assertEmpty( $screen ); |
|
265 | + $this->assertEmpty($screen); |
|
266 | 266 | |
267 | 267 | } |
268 | 268 | |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | global $wp_fields; |
278 | 278 | |
279 | 279 | // Add a screen |
280 | - $this->test_add_screen( 'post', 'my_custom_post_type' ); |
|
280 | + $this->test_add_screen('post', 'my_custom_post_type'); |
|
281 | 281 | |
282 | 282 | // Remove screen |
283 | - $wp_fields->remove_screen( 'post', null, true ); |
|
283 | + $wp_fields->remove_screen('post', null, true); |
|
284 | 284 | |
285 | 285 | // Screen no longer exists for this object type / name |
286 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
286 | + $screen = $wp_fields->get_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
287 | 287 | |
288 | - $this->assertEmpty( $screen ); |
|
288 | + $this->assertEmpty($screen); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | global $wp_fields; |
301 | 301 | |
302 | 302 | // Add a screen |
303 | - $this->test_add_screen( 'post' ); |
|
303 | + $this->test_add_screen('post'); |
|
304 | 304 | |
305 | 305 | // Remove screen |
306 | - $wp_fields->remove_screen( 'post', 'my_test_screen' ); |
|
306 | + $wp_fields->remove_screen('post', 'my_test_screen'); |
|
307 | 307 | |
308 | 308 | // Screen no longer exists for this object type / name |
309 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen' ); |
|
309 | + $screen = $wp_fields->get_screen('post', 'my_test_screen'); |
|
310 | 310 | |
311 | - $this->assertEmpty( $screen ); |
|
311 | + $this->assertEmpty($screen); |
|
312 | 312 | |
313 | 313 | } |
314 | 314 | |
@@ -323,15 +323,15 @@ discard block |
||
323 | 323 | global $wp_fields; |
324 | 324 | |
325 | 325 | // Add a screen |
326 | - $this->test_add_screen( 'post', 'my_custom_post_type' ); |
|
326 | + $this->test_add_screen('post', 'my_custom_post_type'); |
|
327 | 327 | |
328 | 328 | // Remove screen |
329 | - $wp_fields->remove_screen( 'post', true, 'my_custom_post_type' ); |
|
329 | + $wp_fields->remove_screen('post', true, 'my_custom_post_type'); |
|
330 | 330 | |
331 | 331 | // Screen no longer exists for this object type / name |
332 | - $screen = $wp_fields->get_screen( 'post', 'my_test_screen', 'my_custom_post_type' ); |
|
332 | + $screen = $wp_fields->get_screen('post', 'my_test_screen', 'my_custom_post_type'); |
|
333 | 333 | |
334 | - $this->assertEmpty( $screen ); |
|
334 | + $this->assertEmpty($screen); |
|
335 | 335 | |
336 | 336 | } |
337 | 337 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @param string $object_type |
342 | 342 | * @param string $object_name |
343 | 343 | */ |
344 | - public function test_add_section( $object_type = 'post', $object_name = null ) { |
|
344 | + public function test_add_section($object_type = 'post', $object_name = null) { |
|
345 | 345 | |
346 | 346 | /** |
347 | 347 | * @var $wp_fields WP_Fields_API |
@@ -349,11 +349,11 @@ discard block |
||
349 | 349 | global $wp_fields; |
350 | 350 | |
351 | 351 | // Add a screen |
352 | - $this->test_add_screen( $object_type, $object_name ); |
|
352 | + $this->test_add_screen($object_type, $object_name); |
|
353 | 353 | |
354 | - $wp_fields->add_section( $object_type, 'my_test_section', $object_name, array( |
|
354 | + $wp_fields->add_section($object_type, 'my_test_section', $object_name, array( |
|
355 | 355 | 'screen' => 'my_test_screen', |
356 | - ) ); |
|
356 | + )); |
|
357 | 357 | |
358 | 358 | } |
359 | 359 | |
@@ -368,43 +368,43 @@ discard block |
||
368 | 368 | global $wp_fields; |
369 | 369 | |
370 | 370 | // Add a screen |
371 | - $this->test_add_section( 'post', 'my_custom_post_type' ); |
|
371 | + $this->test_add_section('post', 'my_custom_post_type'); |
|
372 | 372 | |
373 | 373 | // Get sections for object type / name |
374 | - $sections = $wp_fields->get_sections( 'post', 'my_custom_post_type' ); |
|
374 | + $sections = $wp_fields->get_sections('post', 'my_custom_post_type'); |
|
375 | 375 | |
376 | - $this->assertEquals( 1, count( $sections ) ); |
|
376 | + $this->assertEquals(1, count($sections)); |
|
377 | 377 | |
378 | - $this->assertArrayHasKey( 'my_test_section', $sections ); |
|
378 | + $this->assertArrayHasKey('my_test_section', $sections); |
|
379 | 379 | |
380 | 380 | // Get a section that doesn't exist |
381 | - $sections = $wp_fields->get_sections( 'post', 'some_other_post_type' ); |
|
381 | + $sections = $wp_fields->get_sections('post', 'some_other_post_type'); |
|
382 | 382 | |
383 | - $this->assertEquals( 0, count( $sections ) ); |
|
383 | + $this->assertEquals(0, count($sections)); |
|
384 | 384 | |
385 | 385 | // Get sections by screen |
386 | - $sections = $wp_fields->get_sections( 'post', 'my_custom_post_type', 'my_test_screen' ); |
|
386 | + $sections = $wp_fields->get_sections('post', 'my_custom_post_type', 'my_test_screen'); |
|
387 | 387 | |
388 | - $this->assertEquals( 1, count( $sections ) ); |
|
388 | + $this->assertEquals(1, count($sections)); |
|
389 | 389 | |
390 | - $this->assertArrayHasKey( 'my_test_section', $sections ); |
|
390 | + $this->assertArrayHasKey('my_test_section', $sections); |
|
391 | 391 | |
392 | 392 | // Get all sections for object type |
393 | - $sections = $wp_fields->get_sections( 'post', true ); |
|
393 | + $sections = $wp_fields->get_sections('post', true); |
|
394 | 394 | |
395 | - $this->assertEquals( 1, count( $sections ) ); |
|
395 | + $this->assertEquals(1, count($sections)); |
|
396 | 396 | |
397 | - $section_ids = wp_list_pluck( $sections, 'id' ); |
|
397 | + $section_ids = wp_list_pluck($sections, 'id'); |
|
398 | 398 | |
399 | - $this->assertContains( 'my_test_section', $section_ids ); |
|
399 | + $this->assertContains('my_test_section', $section_ids); |
|
400 | 400 | |
401 | 401 | // Get all sections for all object types |
402 | 402 | $sections = $wp_fields->get_sections(); |
403 | 403 | |
404 | 404 | // Each array item is an object type with an array of object names |
405 | - $this->assertEquals( 1, count( $sections ) ); |
|
405 | + $this->assertEquals(1, count($sections)); |
|
406 | 406 | |
407 | - $this->assertArrayHasKey( 'post', $sections ); |
|
407 | + $this->assertArrayHasKey('post', $sections); |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
@@ -419,24 +419,24 @@ discard block |
||
419 | 419 | global $wp_fields; |
420 | 420 | |
421 | 421 | // Add a screen |
422 | - $this->test_add_section( 'post', 'my_custom_post_type' ); |
|
422 | + $this->test_add_section('post', 'my_custom_post_type'); |
|
423 | 423 | |
424 | 424 | // Section exists for this object type / name |
425 | - $section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' ); |
|
425 | + $section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type'); |
|
426 | 426 | |
427 | - $this->assertNotEmpty( $section ); |
|
427 | + $this->assertNotEmpty($section); |
|
428 | 428 | |
429 | - $this->assertEquals( 'my_test_section', $section->id ); |
|
429 | + $this->assertEquals('my_test_section', $section->id); |
|
430 | 430 | |
431 | 431 | // Section doesn't exist for this object type / name |
432 | - $section = $wp_fields->get_section( 'post', 'my_test_section', 'some_other_post_type' ); |
|
432 | + $section = $wp_fields->get_section('post', 'my_test_section', 'some_other_post_type'); |
|
433 | 433 | |
434 | - $this->assertEmpty( $section ); |
|
434 | + $this->assertEmpty($section); |
|
435 | 435 | |
436 | 436 | // Section doesn't exist for this object type / name |
437 | - $section = $wp_fields->get_section( 'post', 'my_test_section2', 'my_custom_post_type' ); |
|
437 | + $section = $wp_fields->get_section('post', 'my_test_section2', 'my_custom_post_type'); |
|
438 | 438 | |
439 | - $this->assertEmpty( $section ); |
|
439 | + $this->assertEmpty($section); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -451,22 +451,22 @@ discard block |
||
451 | 451 | global $wp_fields; |
452 | 452 | |
453 | 453 | // Add a screen |
454 | - $this->test_add_section( 'post', 'my_custom_post_type' ); |
|
454 | + $this->test_add_section('post', 'my_custom_post_type'); |
|
455 | 455 | |
456 | 456 | // Section exists for this object type / name |
457 | - $section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' ); |
|
457 | + $section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type'); |
|
458 | 458 | |
459 | - $this->assertNotEmpty( $section ); |
|
459 | + $this->assertNotEmpty($section); |
|
460 | 460 | |
461 | - $this->assertEquals( 'my_test_section', $section->id ); |
|
461 | + $this->assertEquals('my_test_section', $section->id); |
|
462 | 462 | |
463 | 463 | // Remove section |
464 | - $wp_fields->remove_section( 'post', 'my_test_section', 'my_custom_post_type' ); |
|
464 | + $wp_fields->remove_section('post', 'my_test_section', 'my_custom_post_type'); |
|
465 | 465 | |
466 | 466 | // Section no longer exists for this object type / name |
467 | - $section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' ); |
|
467 | + $section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type'); |
|
468 | 468 | |
469 | - $this->assertEmpty( $section ); |
|
469 | + $this->assertEmpty($section); |
|
470 | 470 | |
471 | 471 | } |
472 | 472 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @param string $object_type |
477 | 477 | * @param string $object_name |
478 | 478 | */ |
479 | - public function test_add_field( $object_type = 'post', $object_name = null ) { |
|
479 | + public function test_add_field($object_type = 'post', $object_name = null) { |
|
480 | 480 | |
481 | 481 | /** |
482 | 482 | * @var $wp_fields WP_Fields_API |
@@ -484,16 +484,16 @@ discard block |
||
484 | 484 | global $wp_fields; |
485 | 485 | |
486 | 486 | // Add a section for the control |
487 | - $this->test_add_section( $object_type, $object_name ); |
|
487 | + $this->test_add_section($object_type, $object_name); |
|
488 | 488 | |
489 | - $wp_fields->add_field( $object_type, 'my_test_field', $object_name, array( |
|
489 | + $wp_fields->add_field($object_type, 'my_test_field', $object_name, array( |
|
490 | 490 | 'control' => array( |
491 | 491 | 'id' => 'my_test_field_control', |
492 | 492 | 'label' => 'My Test Field', |
493 | 493 | 'type' => 'text', |
494 | 494 | 'section' => 'my_test_section', |
495 | 495 | ), |
496 | - ) ); |
|
496 | + )); |
|
497 | 497 | |
498 | 498 | } |
499 | 499 | |
@@ -508,26 +508,26 @@ discard block |
||
508 | 508 | global $wp_fields; |
509 | 509 | |
510 | 510 | // Add a field |
511 | - $this->test_add_field( 'post', 'my_custom_post_type' ); |
|
511 | + $this->test_add_field('post', 'my_custom_post_type'); |
|
512 | 512 | |
513 | 513 | // Get fields for object type / name |
514 | - $fields = $wp_fields->get_fields( 'post', 'my_custom_post_type' ); |
|
514 | + $fields = $wp_fields->get_fields('post', 'my_custom_post_type'); |
|
515 | 515 | |
516 | - $this->assertEquals( 1, count( $fields ) ); |
|
516 | + $this->assertEquals(1, count($fields)); |
|
517 | 517 | |
518 | - $this->assertArrayHasKey( 'my_test_field', $fields ); |
|
518 | + $this->assertArrayHasKey('my_test_field', $fields); |
|
519 | 519 | |
520 | 520 | // Get a field that doesn't exist |
521 | - $fields = $wp_fields->get_fields( 'post', 'some_other_post_type' ); |
|
521 | + $fields = $wp_fields->get_fields('post', 'some_other_post_type'); |
|
522 | 522 | |
523 | - $this->assertEquals( 0, count( $fields ) ); |
|
523 | + $this->assertEquals(0, count($fields)); |
|
524 | 524 | |
525 | 525 | // Get fields by section |
526 | - $fields = $wp_fields->get_fields( 'post', 'my_custom_post_type', 'my_test_section' ); |
|
526 | + $fields = $wp_fields->get_fields('post', 'my_custom_post_type', 'my_test_section'); |
|
527 | 527 | |
528 | - $this->assertEquals( 1, count( $fields ) ); |
|
528 | + $this->assertEquals(1, count($fields)); |
|
529 | 529 | |
530 | - $this->assertArrayHasKey( 'my_test_field', $fields ); |
|
530 | + $this->assertArrayHasKey('my_test_field', $fields); |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | |
@@ -542,24 +542,24 @@ discard block |
||
542 | 542 | global $wp_fields; |
543 | 543 | |
544 | 544 | // Add a field |
545 | - $this->test_add_field( 'post', 'my_custom_post_type' ); |
|
545 | + $this->test_add_field('post', 'my_custom_post_type'); |
|
546 | 546 | |
547 | 547 | // Field exists for this object type / name |
548 | - $field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' ); |
|
548 | + $field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type'); |
|
549 | 549 | |
550 | - $this->assertNotEmpty( $field ); |
|
550 | + $this->assertNotEmpty($field); |
|
551 | 551 | |
552 | - $this->assertEquals( 'my_test_field', $field->id ); |
|
552 | + $this->assertEquals('my_test_field', $field->id); |
|
553 | 553 | |
554 | 554 | // Field doesn't exist for this object type / name |
555 | - $field = $wp_fields->get_field( 'post', 'my_test_field', 'some_other_post_type' ); |
|
555 | + $field = $wp_fields->get_field('post', 'my_test_field', 'some_other_post_type'); |
|
556 | 556 | |
557 | - $this->assertEmpty( $field ); |
|
557 | + $this->assertEmpty($field); |
|
558 | 558 | |
559 | 559 | // Field doesn't exist for this object type / name |
560 | - $field = $wp_fields->get_field( 'post', 'my_test_field2', 'my_custom_post_type' ); |
|
560 | + $field = $wp_fields->get_field('post', 'my_test_field2', 'my_custom_post_type'); |
|
561 | 561 | |
562 | - $this->assertEmpty( $field ); |
|
562 | + $this->assertEmpty($field); |
|
563 | 563 | |
564 | 564 | } |
565 | 565 | |
@@ -574,22 +574,22 @@ discard block |
||
574 | 574 | global $wp_fields; |
575 | 575 | |
576 | 576 | // Add a field |
577 | - $this->test_add_field( 'post', 'my_custom_post_type' ); |
|
577 | + $this->test_add_field('post', 'my_custom_post_type'); |
|
578 | 578 | |
579 | 579 | // Field exists for this object type / name |
580 | - $field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' ); |
|
580 | + $field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type'); |
|
581 | 581 | |
582 | - $this->assertNotEmpty( $field ); |
|
582 | + $this->assertNotEmpty($field); |
|
583 | 583 | |
584 | - $this->assertEquals( 'my_test_field', $field->id ); |
|
584 | + $this->assertEquals('my_test_field', $field->id); |
|
585 | 585 | |
586 | 586 | // Remove field |
587 | - $wp_fields->remove_field( 'post', 'my_test_field', 'my_custom_post_type' ); |
|
587 | + $wp_fields->remove_field('post', 'my_test_field', 'my_custom_post_type'); |
|
588 | 588 | |
589 | 589 | // Field no longer exists for this object type / name |
590 | - $field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' ); |
|
590 | + $field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type'); |
|
591 | 591 | |
592 | - $this->assertEmpty( $field ); |
|
592 | + $this->assertEmpty($field); |
|
593 | 593 | |
594 | 594 | } |
595 | 595 | |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | * @param string $object_type |
600 | 600 | * @param string $object_name |
601 | 601 | */ |
602 | - public function test_add_control( $object_type = 'post', $object_name = null ) { |
|
602 | + public function test_add_control($object_type = 'post', $object_name = null) { |
|
603 | 603 | |
604 | 604 | /** |
605 | 605 | * @var $wp_fields WP_Fields_API |
@@ -607,14 +607,14 @@ discard block |
||
607 | 607 | global $wp_fields; |
608 | 608 | |
609 | 609 | // Add a field for the control |
610 | - $this->test_add_field( $object_type, $object_name ); |
|
610 | + $this->test_add_field($object_type, $object_name); |
|
611 | 611 | |
612 | - $wp_fields->add_control( $object_type, 'my_test_control', $object_name, array( |
|
612 | + $wp_fields->add_control($object_type, 'my_test_control', $object_name, array( |
|
613 | 613 | 'section' => 'my_test_section', |
614 | 614 | 'fields' => 'my_test_field', |
615 | 615 | 'label' => 'My Test Control Field', |
616 | 616 | 'type' => 'text', |
617 | - ) ); |
|
617 | + )); |
|
618 | 618 | |
619 | 619 | } |
620 | 620 | |
@@ -629,33 +629,33 @@ discard block |
||
629 | 629 | global $wp_fields; |
630 | 630 | |
631 | 631 | // Add a control / field / section |
632 | - $this->test_add_control( 'post', 'my_custom_post_type' ); |
|
632 | + $this->test_add_control('post', 'my_custom_post_type'); |
|
633 | 633 | |
634 | 634 | // Get controls for object type / name |
635 | - $controls = $wp_fields->get_controls( 'post', 'my_custom_post_type' ); |
|
635 | + $controls = $wp_fields->get_controls('post', 'my_custom_post_type'); |
|
636 | 636 | |
637 | 637 | // There are two controls, the default one with the main field and this control |
638 | - $this->assertEquals( 2, count( $controls ) ); |
|
638 | + $this->assertEquals(2, count($controls)); |
|
639 | 639 | |
640 | - $this->assertArrayHasKey( 'my_test_control', $controls ); |
|
641 | - $this->assertArrayHasKey( 'my_test_field_control', $controls ); |
|
640 | + $this->assertArrayHasKey('my_test_control', $controls); |
|
641 | + $this->assertArrayHasKey('my_test_field_control', $controls); |
|
642 | 642 | |
643 | - $this->assertEquals( 'my_test_section', $controls['my_test_control']->section ); |
|
643 | + $this->assertEquals('my_test_section', $controls['my_test_control']->section); |
|
644 | 644 | |
645 | 645 | // Get a control that doesn't exist |
646 | - $controls = $wp_fields->get_controls( 'post', 'some_other_post_type' ); |
|
646 | + $controls = $wp_fields->get_controls('post', 'some_other_post_type'); |
|
647 | 647 | |
648 | - $this->assertEquals( 0, count( $controls ) ); |
|
648 | + $this->assertEquals(0, count($controls)); |
|
649 | 649 | |
650 | 650 | // Get controls by section |
651 | - $controls = $wp_fields->get_controls( 'post', 'my_custom_post_type', 'my_test_section' ); |
|
651 | + $controls = $wp_fields->get_controls('post', 'my_custom_post_type', 'my_test_section'); |
|
652 | 652 | |
653 | - $this->assertEquals( 2, count( $controls ) ); |
|
653 | + $this->assertEquals(2, count($controls)); |
|
654 | 654 | |
655 | - $this->assertArrayHasKey( 'my_test_control', $controls ); |
|
656 | - $this->assertArrayHasKey( 'my_test_field_control', $controls ); |
|
655 | + $this->assertArrayHasKey('my_test_control', $controls); |
|
656 | + $this->assertArrayHasKey('my_test_field_control', $controls); |
|
657 | 657 | |
658 | - $this->assertEquals( 'my_test_section', $controls['my_test_control']->section ); |
|
658 | + $this->assertEquals('my_test_section', $controls['my_test_control']->section); |
|
659 | 659 | |
660 | 660 | } |
661 | 661 | |
@@ -670,37 +670,37 @@ discard block |
||
670 | 670 | global $wp_fields; |
671 | 671 | |
672 | 672 | // Add a control / field / section |
673 | - $this->test_add_control( 'post', 'my_custom_post_type' ); |
|
673 | + $this->test_add_control('post', 'my_custom_post_type'); |
|
674 | 674 | |
675 | 675 | // Control exists for this object type / name |
676 | - $control = $wp_fields->get_control( 'post', 'my_test_field_control', 'my_custom_post_type' ); |
|
676 | + $control = $wp_fields->get_control('post', 'my_test_field_control', 'my_custom_post_type'); |
|
677 | 677 | |
678 | - $this->assertNotEmpty( $control ); |
|
678 | + $this->assertNotEmpty($control); |
|
679 | 679 | |
680 | - $this->assertEquals( 'my_test_field_control', $control->id ); |
|
681 | - $this->assertNotEmpty( $control->field ); |
|
682 | - $this->assertEquals( 'my_test_field', $control->field->id ); |
|
683 | - $this->assertEquals( 'my_test_section', $control->section ); |
|
680 | + $this->assertEquals('my_test_field_control', $control->id); |
|
681 | + $this->assertNotEmpty($control->field); |
|
682 | + $this->assertEquals('my_test_field', $control->field->id); |
|
683 | + $this->assertEquals('my_test_section', $control->section); |
|
684 | 684 | |
685 | 685 | // Control exists for this object type / name |
686 | - $control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' ); |
|
686 | + $control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type'); |
|
687 | 687 | |
688 | - $this->assertNotEmpty( $control ); |
|
688 | + $this->assertNotEmpty($control); |
|
689 | 689 | |
690 | - $this->assertEquals( 'my_test_control', $control->id ); |
|
691 | - $this->assertNotEmpty( $control->field ); |
|
692 | - $this->assertEquals( 'my_test_field', $control->field->id ); |
|
693 | - $this->assertEquals( 'my_test_section', $control->section ); |
|
690 | + $this->assertEquals('my_test_control', $control->id); |
|
691 | + $this->assertNotEmpty($control->field); |
|
692 | + $this->assertEquals('my_test_field', $control->field->id); |
|
693 | + $this->assertEquals('my_test_section', $control->section); |
|
694 | 694 | |
695 | 695 | // Control doesn't exist for this object type / name |
696 | - $control = $wp_fields->get_control( 'post', 'my_test_control', 'some_other_post_type' ); |
|
696 | + $control = $wp_fields->get_control('post', 'my_test_control', 'some_other_post_type'); |
|
697 | 697 | |
698 | - $this->assertEmpty( $control ); |
|
698 | + $this->assertEmpty($control); |
|
699 | 699 | |
700 | 700 | // Control doesn't exist for this object type / name |
701 | - $control = $wp_fields->get_control( 'post', 'my_test_control2', 'my_custom_post_type' ); |
|
701 | + $control = $wp_fields->get_control('post', 'my_test_control2', 'my_custom_post_type'); |
|
702 | 702 | |
703 | - $this->assertEmpty( $control ); |
|
703 | + $this->assertEmpty($control); |
|
704 | 704 | |
705 | 705 | } |
706 | 706 | |
@@ -715,32 +715,32 @@ discard block |
||
715 | 715 | global $wp_fields; |
716 | 716 | |
717 | 717 | // Add a control / field / section |
718 | - $this->test_add_control( 'post', 'my_custom_post_type' ); |
|
718 | + $this->test_add_control('post', 'my_custom_post_type'); |
|
719 | 719 | |
720 | 720 | // Control exists for this object type / name |
721 | - $control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' ); |
|
721 | + $control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type'); |
|
722 | 722 | |
723 | - $this->assertNotEmpty( $control ); |
|
723 | + $this->assertNotEmpty($control); |
|
724 | 724 | |
725 | - $this->assertEquals( 'my_test_control', $control->id ); |
|
726 | - $this->assertEquals( 'my_test_field', $control->field->id ); |
|
727 | - $this->assertEquals( 'my_test_section', $control->section ); |
|
725 | + $this->assertEquals('my_test_control', $control->id); |
|
726 | + $this->assertEquals('my_test_field', $control->field->id); |
|
727 | + $this->assertEquals('my_test_section', $control->section); |
|
728 | 728 | |
729 | 729 | // Remove control |
730 | - $wp_fields->remove_control( 'post', 'my_test_control', 'my_custom_post_type' ); |
|
730 | + $wp_fields->remove_control('post', 'my_test_control', 'my_custom_post_type'); |
|
731 | 731 | |
732 | 732 | // Control no longer exists for this object type / name |
733 | - $control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' ); |
|
733 | + $control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type'); |
|
734 | 734 | |
735 | - $this->assertEmpty( $control ); |
|
735 | + $this->assertEmpty($control); |
|
736 | 736 | |
737 | 737 | // Remove field's control |
738 | - $wp_fields->remove_control( 'post', 'my_test_field_control', 'my_custom_post_type' ); |
|
738 | + $wp_fields->remove_control('post', 'my_test_field_control', 'my_custom_post_type'); |
|
739 | 739 | |
740 | 740 | // Control no longer exists for this object type / name |
741 | - $control = $wp_fields->get_control( 'post', 'my_test_field_control', 'my_custom_post_type' ); |
|
741 | + $control = $wp_fields->get_control('post', 'my_test_field_control', 'my_custom_post_type'); |
|
742 | 742 | |
743 | - $this->assertEmpty( $control ); |
|
743 | + $this->assertEmpty($control); |
|
744 | 744 | |
745 | 745 | } |
746 | 746 |
@@ -22,56 +22,56 @@ |
||
22 | 22 | /** |
23 | 23 | * The absolute server path to the fields API directory. |
24 | 24 | */ |
25 | -define( 'WP_FIELDS_API_DIR', plugin_dir_path( __FILE__ ) ); |
|
25 | +define('WP_FIELDS_API_DIR', plugin_dir_path(__FILE__)); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * On `plugins_loaded`, create an instance of the Fields API manager class. |
29 | 29 | */ |
30 | 30 | function _wp_fields_api_include() { |
31 | 31 | |
32 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api.php' ); |
|
32 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api.php'); |
|
33 | 33 | |
34 | 34 | // Init Customize class |
35 | 35 | $GLOBALS['wp_fields'] = new WP_Fields_API; |
36 | 36 | |
37 | 37 | } |
38 | 38 | |
39 | -add_action( 'plugins_loaded', '_wp_fields_api_include', 8 ); |
|
39 | +add_action('plugins_loaded', '_wp_fields_api_include', 8); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implement Fields API Customizer instead of WP Core Customizer. |
43 | 43 | */ |
44 | 44 | function _wp_fields_api_customize_include() { |
45 | 45 | |
46 | - if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) ) ) { |
|
46 | + if ( ! ((isset($_REQUEST['wp_customize']) && 'on' == $_REQUEST['wp_customize']) || (is_admin() && 'customize.php' == basename($_SERVER['PHP_SELF'])))) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
50 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
51 | 51 | |
52 | 52 | // Init Customize class |
53 | 53 | $GLOBALS['wp_customize'] = new WP_Customize_Manager; |
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | -remove_action( 'plugins_loaded', '_wp_customize_include' ); |
|
58 | -add_action( 'plugins_loaded', '_wp_fields_api_customize_include', 9 ); |
|
57 | +remove_action('plugins_loaded', '_wp_customize_include'); |
|
58 | +add_action('plugins_loaded', '_wp_fields_api_customize_include', 9); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Implement Fields API User edit to override WP Core. |
62 | 62 | */ |
63 | 63 | function _wp_fields_api_user_edit_include() { |
64 | 64 | |
65 | - require_once( WP_FIELDS_API_DIR . 'implementation/user-profile.php' ); |
|
65 | + require_once(WP_FIELDS_API_DIR.'implementation/user-profile.php'); |
|
66 | 66 | |
67 | 67 | return; |
68 | 68 | |
69 | 69 | // Load our overrides |
70 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/includes/user.php' ); |
|
71 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/user-edit.php' ); |
|
70 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/includes/user.php'); |
|
71 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/user-edit.php'); |
|
72 | 72 | |
73 | 73 | // Bail on original core file, don't run the rest |
74 | 74 | exit; |
75 | 75 | |
76 | 76 | } |
77 | -add_action( 'load-user-edit.php', '_wp_fields_api_user_edit_include' ); |
|
78 | 77 | \ No newline at end of file |
78 | +add_action('load-user-edit.php', '_wp_fields_api_user_edit_include'); |
|
79 | 79 | \ No newline at end of file |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $args = func_get_args(); |
145 | 145 | |
146 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
146 | + call_user_func_array(array($this, 'init'), $args); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param string $id A specific ID of the section. |
155 | 155 | * @param array $args Section arguments. |
156 | 156 | */ |
157 | - public function init( $object_type, $id, $args = array() ) { |
|
157 | + public function init($object_type, $id, $args = array()) { |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @var $wp_fields WP_Fields_API |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | $this->object_type = $object_type; |
165 | 165 | |
166 | - if ( is_array( $id ) ) { |
|
166 | + if (is_array($id)) { |
|
167 | 167 | $args = $id; |
168 | 168 | |
169 | 169 | $id = ''; |
@@ -171,19 +171,19 @@ discard block |
||
171 | 171 | $this->id = $id; |
172 | 172 | } |
173 | 173 | |
174 | - $keys = array_keys( get_object_vars( $this ) ); |
|
174 | + $keys = array_keys(get_object_vars($this)); |
|
175 | 175 | |
176 | - foreach ( $keys as $key ) { |
|
177 | - if ( isset( $args[ $key ] ) ) { |
|
178 | - $this->$key = $args[ $key ]; |
|
176 | + foreach ($keys as $key) { |
|
177 | + if (isset($args[$key])) { |
|
178 | + $this->$key = $args[$key]; |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | self::$instance_count += 1; |
183 | 183 | $this->instance_number = self::$instance_count; |
184 | 184 | |
185 | - if ( empty( $this->active_callback ) ) { |
|
186 | - $this->active_callback = array( $this, 'active_callback' ); |
|
185 | + if (empty($this->active_callback)) { |
|
186 | + $this->active_callback = array($this, 'active_callback'); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /*if ( $this->screen ) { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | final public function active() { |
210 | 210 | |
211 | 211 | $section = $this; |
212 | - $active = call_user_func( $this->active_callback, $this ); |
|
212 | + $active = call_user_func($this->active_callback, $this); |
|
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Filter response of {@see WP_Fields_API_Section::active()}. |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param bool $active Whether the Fields API section is active. |
218 | 218 | * @param WP_Fields_API_Section $section {@see WP_Fields_API_Section} instance. |
219 | 219 | */ |
220 | - $active = apply_filters( 'fields_api_section_active_' . $this->object_type, $active, $section ); |
|
220 | + $active = apply_filters('fields_api_section_active_'.$this->object_type, $active, $section); |
|
221 | 221 | |
222 | 222 | return $active; |
223 | 223 | |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function json() { |
249 | 249 | |
250 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'screen', 'type' ) ); |
|
251 | - $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); |
|
250 | + $array = wp_array_slice_assoc((array) $this, array('id', 'description', 'priority', 'screen', 'type')); |
|
251 | + $array['title'] = html_entity_decode($this->title, ENT_QUOTES, get_bloginfo('charset')); |
|
252 | 252 | $array['content'] = $this->get_content(); |
253 | 253 | $array['active'] = $this->active(); |
254 | 254 | $array['instanceNumber'] = $this->instance_number; |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function check_capabilities() { |
267 | 267 | |
268 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
268 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
272 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | |
289 | 289 | $this->maybe_render(); |
290 | 290 | |
291 | - $template = trim( ob_get_contents() ); |
|
291 | + $template = trim(ob_get_contents()); |
|
292 | 292 | |
293 | 293 | ob_end_clean(); |
294 | 294 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | */ |
302 | 302 | final public function maybe_render() { |
303 | 303 | |
304 | - if ( ! $this->check_capabilities() ) { |
|
304 | + if ( ! $this->check_capabilities()) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param WP_Fields_API_Section $this WP_Fields API_Section instance. |
315 | 315 | */ |
316 | - do_action( "fields_api_render_section_{$this->object_type}", $this ); |
|
316 | + do_action("fields_api_render_section_{$this->object_type}", $this); |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Fires before rendering a specific Fields API section. |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * of the specific Fields API section to be rendered. |
326 | 326 | * |
327 | 327 | */ |
328 | - do_action( "fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
328 | + do_action("fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
329 | 329 | |
330 | 330 | $this->render(); |
331 | 331 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * // @todo Merge render_template / print_template() from Customizer |
338 | 338 | */ |
339 | 339 | protected function render() { |
340 | - echo esc_html( $this->title ); |
|
340 | + echo esc_html($this->title); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | $args = func_get_args(); |
138 | 138 | |
139 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
139 | + call_user_func_array(array($this, 'init'), $args); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @param string $id A specific ID of the screen. |
148 | 148 | * @param array $args Screen arguments. |
149 | 149 | */ |
150 | - public function init( $object_type, $id, $args = array() ) { |
|
150 | + public function init($object_type, $id, $args = array()) { |
|
151 | 151 | |
152 | 152 | $this->object_type = $object_type; |
153 | 153 | |
154 | - if ( is_array( $id ) ) { |
|
154 | + if (is_array($id)) { |
|
155 | 155 | $args = $id; |
156 | 156 | |
157 | 157 | $id = ''; |
@@ -159,19 +159,19 @@ discard block |
||
159 | 159 | $this->id = $id; |
160 | 160 | } |
161 | 161 | |
162 | - $keys = array_keys( get_object_vars( $this ) ); |
|
162 | + $keys = array_keys(get_object_vars($this)); |
|
163 | 163 | |
164 | - foreach ( $keys as $key ) { |
|
165 | - if ( isset( $args[ $key ] ) ) { |
|
166 | - $this->$key = $args[ $key ]; |
|
164 | + foreach ($keys as $key) { |
|
165 | + if (isset($args[$key])) { |
|
166 | + $this->$key = $args[$key]; |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
170 | 170 | self::$instance_count += 1; |
171 | 171 | $this->instance_number = self::$instance_count; |
172 | 172 | |
173 | - if ( empty( $this->active_callback ) ) { |
|
174 | - $this->active_callback = array( $this, 'active_callback' ); |
|
173 | + if (empty($this->active_callback)) { |
|
174 | + $this->active_callback = array($this, 'active_callback'); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | $this->sections = array(); // Users cannot customize the $sections array. |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | final public function active() { |
189 | 189 | |
190 | 190 | $screen = $this; |
191 | - $active = call_user_func( $this->active_callback, $this ); |
|
191 | + $active = call_user_func($this->active_callback, $this); |
|
192 | 192 | |
193 | 193 | /** |
194 | 194 | * Filter response of WP_Fields_API_Screen::active(). |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param bool $active Whether the Fields API screen is active. |
198 | 198 | * @param WP_Fields_API_Screen $screen {@see WP_Fields_API_Screen} instance. |
199 | 199 | */ |
200 | - $active = apply_filters( 'fields_api_screen_active_' . $this->object_type, $active, $screen ); |
|
200 | + $active = apply_filters('fields_api_screen_active_'.$this->object_type, $active, $screen); |
|
201 | 201 | |
202 | 202 | return $active; |
203 | 203 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function json() { |
228 | 228 | |
229 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) ); |
|
229 | + $array = wp_array_slice_assoc((array) $this, array('id', 'title', 'description', 'priority', 'type')); |
|
230 | 230 | |
231 | 231 | $array['content'] = $this->get_content(); |
232 | 232 | $array['active'] = $this->active(); |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function check_capabilities() { |
246 | 246 | |
247 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
247 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
251 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | $this->maybe_render(); |
269 | 269 | |
270 | - $template = trim( ob_get_contents() ); |
|
270 | + $template = trim(ob_get_contents()); |
|
271 | 271 | |
272 | 272 | ob_end_clean(); |
273 | 273 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | final public function maybe_render() { |
283 | 283 | |
284 | - if ( ! $this->check_capabilities() ) { |
|
284 | + if ( ! $this->check_capabilities()) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @param WP_Fields_API_Screen $this WP_Fields_API_Screen instance. |
292 | 292 | */ |
293 | - do_action( "fields_api_render_screen_{$this->object_type}", $this ); |
|
293 | + do_action("fields_api_render_screen_{$this->object_type}", $this); |
|
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Fires before rendering a specific Fields API screen. |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * The dynamic portion of the hook name, `$this->id`, refers to |
299 | 299 | * the ID of the specific Fields API screen to be rendered. |
300 | 300 | */ |
301 | - do_action( "fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
301 | + do_action("fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
302 | 302 | |
303 | 303 | $this->render(); |
304 | 304 | |
@@ -310,12 +310,12 @@ discard block |
||
310 | 310 | * @access protected |
311 | 311 | */ |
312 | 312 | protected function render() { |
313 | - $classes = 'accordion-section control-section control-screen control-screen-' . $this->type; |
|
313 | + $classes = 'accordion-section control-section control-screen control-screen-'.$this->type; |
|
314 | 314 | ?> |
315 | - <li id="accordion-screen-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> |
|
315 | + <li id="accordion-screen-<?php echo esc_attr($this->id); ?>" class="<?php echo esc_attr($classes); ?>"> |
|
316 | 316 | <h3 class="accordion-section-title" tabindex="0"> |
317 | - <?php echo esc_html( $this->title ); ?> |
|
318 | - <span class="screen-reader-text"><?php _e( 'Press return or enter to open this screen' ); ?></span> |
|
317 | + <?php echo esc_html($this->title); ?> |
|
318 | + <span class="screen-reader-text"><?php _e('Press return or enter to open this screen'); ?></span> |
|
319 | 319 | </h3> |
320 | 320 | <ul class="accordion-sub-container control-screen-content"> |
321 | 321 | <?php $this->render_content(); ?> |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | */ |
379 | 379 | protected function render_content() { |
380 | 380 | ?> |
381 | - <li class="screen-meta accordion-section control-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>"> |
|
381 | + <li class="screen-meta accordion-section control-section<?php if (empty($this->description)) { echo ' cannot-expand'; } ?>"> |
|
382 | 382 | <div class="accordion-section-title" tabindex="0"> |
383 | 383 | <span class="preview-notice"><?php |
384 | 384 | /* translators: %s is the site/screen title in the Fields API */ |
385 | - printf( __( 'You are editing %s' ), '<strong class="screen-title">' . esc_html( $this->title ) . '</strong>' ); |
|
385 | + printf(__('You are editing %s'), '<strong class="screen-title">'.esc_html($this->title).'</strong>'); |
|
386 | 386 | ?></span> |
387 | 387 | </div> |
388 | - <?php if ( ! empty( $this->description ) ) : ?> |
|
388 | + <?php if ( ! empty($this->description)) : ?> |
|
389 | 389 | <div class="accordion-section-content description"> |
390 | 390 | <?php echo $this->description; ?> |
391 | 391 | </div> |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Fields API Text Control class. |
|
4 | - * |
|
5 | - * @see WP_Fields_API_Control |
|
6 | - */ |
|
3 | + * Fields API Text Control class. |
|
4 | + * |
|
5 | + * @see WP_Fields_API_Control |
|
6 | + */ |
|
7 | 7 | class WP_Fields_API_Text_Control extends WP_Fields_API_Control { |
8 | 8 | |
9 | 9 | /** |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | |
14 | 14 | ?> |
15 | 15 | <label> |
16 | - <?php if ( ! empty( $this->label ) ) : ?> |
|
17 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
16 | + <?php if ( ! empty($this->label)) : ?> |
|
17 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
18 | 18 | <?php endif; |
19 | - if ( ! empty( $this->description ) ) : ?> |
|
19 | + if ( ! empty($this->description)) : ?> |
|
20 | 20 | <span class="description fields-control-description"><?php echo $this->description; ?></span> |
21 | 21 | <?php endif; ?> |
22 | - <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> /> |
|
22 | + <input type="<?php echo esc_attr($this->type); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr($this->value()); ?>" <?php $this->link(); ?> /> |
|
23 | 23 | </label> |
24 | 24 | <?php |
25 | 25 | |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | |
42 | 42 | ?> |
43 | 43 | <label> |
44 | - <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> /> |
|
45 | - <?php echo esc_html( $this->label ); ?> |
|
46 | - <?php if ( ! empty( $this->description ) ) : ?> |
|
44 | + <input type="checkbox" value="<?php echo esc_attr($this->value()); ?>" <?php $this->link(); checked($this->value()); ?> /> |
|
45 | + <?php echo esc_html($this->label); ?> |
|
46 | + <?php if ( ! empty($this->description)) : ?> |
|
47 | 47 | <span class="description fields-control-description"><?php echo $this->description; ?></span> |
48 | 48 | <?php endif; ?> |
49 | 49 | </label> |
@@ -65,24 +65,24 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function render_content() { |
67 | 67 | |
68 | - if ( empty( $this->choices ) ) { |
|
68 | + if (empty($this->choices)) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | - $name = '_fields-checkbox-' . $this->id; |
|
72 | + $name = '_fields-checkbox-'.$this->id; |
|
73 | 73 | |
74 | - if ( ! empty( $this->label ) ) : ?> |
|
75 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
74 | + if ( ! empty($this->label)) : ?> |
|
75 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
76 | 76 | <?php endif; |
77 | - if ( ! empty( $this->description ) ) : ?> |
|
78 | - <span class="description fields-control-description"><?php echo $this->description ; ?></span> |
|
77 | + if ( ! empty($this->description)) : ?> |
|
78 | + <span class="description fields-control-description"><?php echo $this->description; ?></span> |
|
79 | 79 | <?php endif; |
80 | 80 | |
81 | - foreach ( $this->choices as $value => $label ) : |
|
81 | + foreach ($this->choices as $value => $label) : |
|
82 | 82 | ?> |
83 | 83 | <label> |
84 | - <input type="checkbox" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> /> |
|
85 | - <?php echo esc_html( $label ); ?><br/> |
|
84 | + <input type="checkbox" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($name); ?>" <?php $this->link(); checked($this->value(), $value); ?> /> |
|
85 | + <?php echo esc_html($label); ?><br/> |
|
86 | 86 | </label> |
87 | 87 | <?php |
88 | 88 | endforeach; |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function render_content() { |
105 | 105 | |
106 | - if ( empty( $this->choices ) ) { |
|
106 | + if (empty($this->choices)) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | - $name = '_fields-radio-' . $this->id; |
|
110 | + $name = '_fields-radio-'.$this->id; |
|
111 | 111 | |
112 | - if ( ! empty( $this->label ) ) : ?> |
|
113 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
112 | + if ( ! empty($this->label)) : ?> |
|
113 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
114 | 114 | <?php endif; |
115 | - if ( ! empty( $this->description ) ) : ?> |
|
116 | - <span class="description fields-control-description"><?php echo $this->description ; ?></span> |
|
115 | + if ( ! empty($this->description)) : ?> |
|
116 | + <span class="description fields-control-description"><?php echo $this->description; ?></span> |
|
117 | 117 | <?php endif; |
118 | 118 | |
119 | - foreach ( $this->choices as $value => $label ) : |
|
119 | + foreach ($this->choices as $value => $label) : |
|
120 | 120 | ?> |
121 | 121 | <label> |
122 | - <input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> /> |
|
123 | - <?php echo esc_html( $label ); ?><br/> |
|
122 | + <input type="radio" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($name); ?>" <?php $this->link(); checked($this->value(), $value); ?> /> |
|
123 | + <?php echo esc_html($label); ?><br/> |
|
124 | 124 | </label> |
125 | 125 | <?php |
126 | 126 | endforeach; |
@@ -141,22 +141,22 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function render_content() { |
143 | 143 | |
144 | - if ( empty( $this->choices ) ) { |
|
144 | + if (empty($this->choices)) { |
|
145 | 145 | return; |
146 | 146 | } |
147 | 147 | ?> |
148 | 148 | <label> |
149 | - <?php if ( ! empty( $this->label ) ) : ?> |
|
150 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
149 | + <?php if ( ! empty($this->label)) : ?> |
|
150 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
151 | 151 | <?php endif; |
152 | - if ( ! empty( $this->description ) ) : ?> |
|
152 | + if ( ! empty($this->description)) : ?> |
|
153 | 153 | <span class="description fields-control-description"><?php echo $this->description; ?></span> |
154 | 154 | <?php endif; ?> |
155 | 155 | |
156 | 156 | <select <?php $this->link(); ?>> |
157 | 157 | <?php |
158 | - foreach ( $this->choices as $value => $label ) |
|
159 | - echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>'; |
|
158 | + foreach ($this->choices as $value => $label) |
|
159 | + echo '<option value="'.esc_attr($value).'"'.selected($this->value(), $value, false).'>'.$label.'</option>'; |
|
160 | 160 | ?> |
161 | 161 | </select> |
162 | 162 | </label> |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | public function choices() { |
182 | 182 | |
183 | 183 | $choices = array( |
184 | - '0' => __( '— Select —' ), |
|
184 | + '0' => __('— Select —'), |
|
185 | 185 | ); |
186 | 186 | |
187 | 187 | $pages = get_pages(); |
188 | 188 | |
189 | - $choices = $this->get_page_choices_recurse( $choices, $pages ); |
|
189 | + $choices = $this->get_page_choices_recurse($choices, $pages); |
|
190 | 190 | |
191 | 191 | return $choices; |
192 | 192 | |
@@ -202,17 +202,17 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function get_page_choices_recurse( $choices, $pages, $depth = 0, $parent = 0 ) { |
|
205 | + public function get_page_choices_recurse($choices, $pages, $depth = 0, $parent = 0) { |
|
206 | 206 | |
207 | - $pad = str_repeat( ' ', $depth * 3 ); |
|
207 | + $pad = str_repeat(' ', $depth * 3); |
|
208 | 208 | |
209 | - foreach ( $pages as $page ) { |
|
210 | - if ( $parent == $page->post_parent ) { |
|
209 | + foreach ($pages as $page) { |
|
210 | + if ($parent == $page->post_parent) { |
|
211 | 211 | $title = $page->post_title; |
212 | 212 | |
213 | - if ( '' === $title ) { |
|
213 | + if ('' === $title) { |
|
214 | 214 | /* translators: %d: ID of a post */ |
215 | - $title = sprintf( __( '#%d (no title)' ), $page->ID ); |
|
215 | + $title = sprintf(__('#%d (no title)'), $page->ID); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | * @param string $title Page title. |
224 | 224 | * @param object $page Page data object. |
225 | 225 | */ |
226 | - $title = apply_filters( 'list_pages', $title, $page ); |
|
226 | + $title = apply_filters('list_pages', $title, $page); |
|
227 | 227 | |
228 | - $choices[ $page->ID ] = $pad . $title; |
|
228 | + $choices[$page->ID] = $pad.$title; |
|
229 | 229 | |
230 | - $choices = $this->get_page_choices_recurse( $choices, $pages, $depth + 1, $page->ID ); |
|
230 | + $choices = $this->get_page_choices_recurse($choices, $pages, $depth + 1, $page->ID); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | * @param string $id Control ID. |
267 | 267 | * @param array $args Optional. Arguments to override class property defaults. |
268 | 268 | */ |
269 | - public function __construct( $manager, $id, $args = array() ) { |
|
269 | + public function __construct($manager, $id, $args = array()) { |
|
270 | 270 | |
271 | 271 | $this->statuses = array( |
272 | - '' => __( 'Default' ), |
|
272 | + '' => __('Default'), |
|
273 | 273 | ); |
274 | 274 | |
275 | - parent::__construct( $manager, $id, $args ); |
|
275 | + parent::__construct($manager, $id, $args); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @since 3.4.0 |
283 | 283 | */ |
284 | 284 | public function enqueue() { |
285 | - wp_enqueue_script( 'wp-color-picker' ); |
|
286 | - wp_enqueue_style( 'wp-color-picker' ); |
|
285 | + wp_enqueue_script('wp-color-picker'); |
|
286 | + wp_enqueue_style('wp-color-picker'); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | <span class="description customize-control-description">{{{ data.description }}}</span> |
336 | 336 | <# } #> |
337 | 337 | <div class="customize-control-content"> |
338 | - <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} /> |
|
338 | + <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e('Hex Value'); ?>" {{ defaultValue }} /> |
|
339 | 339 | </div> |
340 | 340 | </label> |
341 | 341 | <?php |
@@ -387,17 +387,17 @@ discard block |
||
387 | 387 | * @param string $id Control ID. |
388 | 388 | * @param array $args Optional. Arguments to override class property defaults. |
389 | 389 | */ |
390 | - public function __construct( $manager, $id, $args = array() ) { |
|
391 | - parent::__construct( $manager, $id, $args ); |
|
390 | + public function __construct($manager, $id, $args = array()) { |
|
391 | + parent::__construct($manager, $id, $args); |
|
392 | 392 | |
393 | 393 | $this->button_labels = array( |
394 | - 'select' => __( 'Select File' ), |
|
395 | - 'change' => __( 'Change File' ), |
|
396 | - 'default' => __( 'Default' ), |
|
397 | - 'remove' => __( 'Remove' ), |
|
398 | - 'placeholder' => __( 'No file selected' ), |
|
399 | - 'frame_title' => __( 'Select File' ), |
|
400 | - 'frame_button' => __( 'Choose File' ), |
|
394 | + 'select' => __('Select File'), |
|
395 | + 'change' => __('Change File'), |
|
396 | + 'default' => __('Default'), |
|
397 | + 'remove' => __('Remove'), |
|
398 | + 'placeholder' => __('No file selected'), |
|
399 | + 'frame_title' => __('Select File'), |
|
400 | + 'frame_button' => __('Choose File'), |
|
401 | 401 | ); |
402 | 402 | } |
403 | 403 | |
@@ -421,40 +421,40 @@ discard block |
||
421 | 421 | */ |
422 | 422 | public function to_json() { |
423 | 423 | parent::to_json(); |
424 | - $this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) ); |
|
424 | + $this->json['label'] = html_entity_decode($this->label, ENT_QUOTES, get_bloginfo('charset')); |
|
425 | 425 | $this->json['mime_type'] = $this->mime_type; |
426 | 426 | $this->json['button_labels'] = $this->button_labels; |
427 | - $this->json['canUpload'] = current_user_can( 'upload_files' ); |
|
427 | + $this->json['canUpload'] = current_user_can('upload_files'); |
|
428 | 428 | |
429 | 429 | $value = $this->value(); |
430 | 430 | |
431 | - if ( is_object( $this->setting ) ) { |
|
432 | - if ( $this->setting->default ) { |
|
431 | + if (is_object($this->setting)) { |
|
432 | + if ($this->setting->default) { |
|
433 | 433 | // Fake an attachment model - needs all fields used by template. |
434 | 434 | // Note that the default value must be a URL, NOT an attachment ID. |
435 | - $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document'; |
|
435 | + $type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document'; |
|
436 | 436 | $default_attachment = array( |
437 | 437 | 'id' => 1, |
438 | 438 | 'url' => $this->setting->default, |
439 | 439 | 'type' => $type, |
440 | - 'icon' => wp_mime_type_icon( $type ), |
|
441 | - 'title' => basename( $this->setting->default ), |
|
440 | + 'icon' => wp_mime_type_icon($type), |
|
441 | + 'title' => basename($this->setting->default), |
|
442 | 442 | ); |
443 | 443 | |
444 | - if ( 'image' === $type ) { |
|
444 | + if ('image' === $type) { |
|
445 | 445 | $default_attachment['sizes'] = array( |
446 | - 'full' => array( 'url' => $this->setting->default ), |
|
446 | + 'full' => array('url' => $this->setting->default), |
|
447 | 447 | ); |
448 | 448 | } |
449 | 449 | |
450 | 450 | $this->json['defaultAttachment'] = $default_attachment; |
451 | 451 | } |
452 | 452 | |
453 | - if ( $value && $this->setting->default && $value === $this->setting->default ) { |
|
453 | + if ($value && $this->setting->default && $value === $this->setting->default) { |
|
454 | 454 | // Set the default as the attachment. |
455 | 455 | $this->json['attachment'] = $this->json['defaultAttachment']; |
456 | - } elseif ( $value ) { |
|
457 | - $this->json['attachment'] = wp_prepare_attachment_for_js( $value ); |
|
456 | + } elseif ($value) { |
|
457 | + $this->json['attachment'] = wp_prepare_attachment_for_js($value); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | } |
@@ -585,11 +585,11 @@ discard block |
||
585 | 585 | parent::to_json(); |
586 | 586 | |
587 | 587 | $value = $this->value(); |
588 | - if ( $value ) { |
|
588 | + if ($value) { |
|
589 | 589 | // Get the attachment model for the existing file. |
590 | - $attachment_id = attachment_url_to_postid( $value ); |
|
591 | - if ( $attachment_id ) { |
|
592 | - $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id ); |
|
590 | + $attachment_id = attachment_url_to_postid($value); |
|
591 | + if ($attachment_id) { |
|
592 | + $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id); |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | } |
@@ -616,17 +616,17 @@ discard block |
||
616 | 616 | * @param string $id Control ID. |
617 | 617 | * @param array $args Optional. Arguments to override class property defaults. |
618 | 618 | */ |
619 | - public function __construct( $manager, $id, $args = array() ) { |
|
620 | - parent::__construct( $manager, $id, $args ); |
|
619 | + public function __construct($manager, $id, $args = array()) { |
|
620 | + parent::__construct($manager, $id, $args); |
|
621 | 621 | |
622 | 622 | $this->button_labels = array( |
623 | - 'select' => __( 'Select Image' ), |
|
624 | - 'change' => __( 'Change Image' ), |
|
625 | - 'remove' => __( 'Remove' ), |
|
626 | - 'default' => __( 'Default' ), |
|
627 | - 'placeholder' => __( 'No image selected' ), |
|
628 | - 'frame_title' => __( 'Select Image' ), |
|
629 | - 'frame_button' => __( 'Choose Image' ), |
|
623 | + 'select' => __('Select Image'), |
|
624 | + 'change' => __('Change Image'), |
|
625 | + 'remove' => __('Remove'), |
|
626 | + 'default' => __('Default'), |
|
627 | + 'placeholder' => __('No image selected'), |
|
628 | + 'frame_title' => __('Select Image'), |
|
629 | + 'frame_button' => __('Choose Image'), |
|
630 | 630 | ); |
631 | 631 | } |
632 | 632 | |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * @param string $label |
645 | 645 | * @param mixed $callback |
646 | 646 | */ |
647 | - public function add_tab( $id, $label, $callback ) {} |
|
647 | + public function add_tab($id, $label, $callback) {} |
|
648 | 648 | |
649 | 649 | /** |
650 | 650 | * @since 3.4.0 |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | * |
653 | 653 | * @param string $id |
654 | 654 | */ |
655 | - public function remove_tab( $id ) {} |
|
655 | + public function remove_tab($id) {} |
|
656 | 656 | |
657 | 657 | /** |
658 | 658 | * @since 3.4.0 |
@@ -661,5 +661,5 @@ discard block |
||
661 | 661 | * @param string $url |
662 | 662 | * @param string $thumbnail_url |
663 | 663 | */ |
664 | - public function print_tab_image( $url, $thumbnail_url = null ) {} |
|
664 | + public function print_tab_image($url, $thumbnail_url = null) {} |
|
665 | 665 | } |
666 | 666 | \ No newline at end of file |
@@ -155,8 +155,9 @@ |
||
155 | 155 | |
156 | 156 | <select <?php $this->link(); ?>> |
157 | 157 | <?php |
158 | - foreach ( $this->choices as $value => $label ) |
|
159 | - echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>'; |
|
158 | + foreach ( $this->choices as $value => $label ) { |
|
159 | + echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>'; |
|
160 | + } |
|
160 | 161 | ?> |
161 | 162 | </select> |
162 | 163 | </label> |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Fields API Control Class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Fields_API |
|
7 | - * |
|
8 | - * @property array $choices Key/Values used by Multiple choice control types |
|
9 | - */ |
|
3 | + * Fields API Control Class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Fields_API |
|
7 | + * |
|
8 | + * @property array $choices Key/Values used by Multiple choice control types |
|
9 | + */ |
|
10 | 10 | class WP_Fields_API_Control { |
11 | 11 | |
12 | 12 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | $args = func_get_args(); |
138 | 138 | |
139 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
139 | + call_user_func_array(array($this, 'init'), $args); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param string $id A specific ID of the control. |
148 | 148 | * @param array $args Control arguments. |
149 | 149 | */ |
150 | - public function init( $object_type, $id, $args = array() ) { |
|
150 | + public function init($object_type, $id, $args = array()) { |
|
151 | 151 | |
152 | 152 | /** |
153 | 153 | * @var $wp_fields WP_Fields_API |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $this->object_type = $object_type; |
158 | 158 | |
159 | - if ( is_array( $id ) ) { |
|
159 | + if (is_array($id)) { |
|
160 | 160 | $args = $id; |
161 | 161 | |
162 | 162 | $id = ''; |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | $this->id = $id; |
165 | 165 | } |
166 | 166 | |
167 | - $keys = array_keys( get_object_vars( $this ) ); |
|
167 | + $keys = array_keys(get_object_vars($this)); |
|
168 | 168 | |
169 | - foreach ( $keys as $key ) { |
|
170 | - if ( isset( $args[ $key ] ) ) { |
|
171 | - $this->$key = $args[ $key ]; |
|
169 | + foreach ($keys as $key) { |
|
170 | + if (isset($args[$key])) { |
|
171 | + $this->$key = $args[$key]; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -176,24 +176,24 @@ discard block |
||
176 | 176 | $this->instance_number = self::$instance_count; |
177 | 177 | |
178 | 178 | // Process fields. |
179 | - if ( empty( $this->fields ) ) { |
|
179 | + if (empty($this->fields)) { |
|
180 | 180 | $this->fields = $id; |
181 | 181 | } |
182 | 182 | |
183 | 183 | $fields = array(); |
184 | 184 | |
185 | - if ( is_array( $this->fields ) ) { |
|
186 | - foreach ( $this->fields as $key => $field ) { |
|
187 | - $field_obj = $wp_fields->get_field( $this->object_type, $field, $this->object_name ); |
|
185 | + if (is_array($this->fields)) { |
|
186 | + foreach ($this->fields as $key => $field) { |
|
187 | + $field_obj = $wp_fields->get_field($this->object_type, $field, $this->object_name); |
|
188 | 188 | |
189 | - if ( $field_obj ) { |
|
190 | - $fields[ $key ] = $field_obj; |
|
189 | + if ($field_obj) { |
|
190 | + $fields[$key] = $field_obj; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | } else { |
194 | - $field_obj = $wp_fields->get_field( $this->object_type, $this->fields, $this->object_name ); |
|
194 | + $field_obj = $wp_fields->get_field($this->object_type, $this->fields, $this->object_name); |
|
195 | 195 | |
196 | - if ( $field_obj ) { |
|
196 | + if ($field_obj) { |
|
197 | 197 | $this->field = $field_obj; |
198 | 198 | $fields['default'] = $field_obj; |
199 | 199 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function setup_choices() { |
210 | 210 | |
211 | - if ( ! isset( $this->choices ) ) { |
|
211 | + if ( ! isset($this->choices)) { |
|
212 | 212 | $choices = $this->choices(); |
213 | 213 | |
214 | 214 | $this->choices = $choices; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | final public function active() { |
241 | 241 | |
242 | 242 | $control = $this; |
243 | - $active = call_user_func( $this->active_callback, $this ); |
|
243 | + $active = call_user_func($this->active_callback, $this); |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Filter response of WP_Fields_API_Control::active(). |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @param bool $active Whether the Field control is active. |
249 | 249 | * @param WP_Fields_API_Control $control WP_Fields_API_Control instance. |
250 | 250 | */ |
251 | - $active = apply_filters( 'fields_control_active_' . $this->object_type, $active, $control ); |
|
251 | + $active = apply_filters('fields_control_active_'.$this->object_type, $active, $control); |
|
252 | 252 | |
253 | 253 | return $active; |
254 | 254 | |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | * @param string $field_key |
278 | 278 | * @return mixed The requested field's value, if the field exists. |
279 | 279 | */ |
280 | - final public function value( $field_key = 'default' ) { |
|
280 | + final public function value($field_key = 'default') { |
|
281 | 281 | |
282 | - if ( isset( $this->fields[ $field_key ] ) ) { |
|
282 | + if (isset($this->fields[$field_key])) { |
|
283 | 283 | /** |
284 | 284 | * @var $field WP_Fields_API_Field |
285 | 285 | */ |
286 | - $field = $this->fields[ $field_key ]; |
|
286 | + $field = $this->fields[$field_key]; |
|
287 | 287 | |
288 | 288 | return $field->value(); |
289 | 289 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | $array = array(); |
303 | 303 | |
304 | - $array['fields'] = wp_list_pluck( $this->fields, 'id' ); |
|
304 | + $array['fields'] = wp_list_pluck($this->fields, 'id'); |
|
305 | 305 | $array['type'] = $this->type; |
306 | 306 | $array['priority'] = $this->priority; |
307 | 307 | $array['active'] = $this->active(); |
@@ -330,15 +330,15 @@ discard block |
||
330 | 330 | /** |
331 | 331 | * @var $field WP_Fields_API_Field |
332 | 332 | */ |
333 | - foreach ( $this->fields as $field ) { |
|
334 | - if ( ! $field || ! $field->check_capabilities() ) { |
|
333 | + foreach ($this->fields as $field) { |
|
334 | + if ( ! $field || ! $field->check_capabilities()) { |
|
335 | 335 | return false; |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - $section = $wp_fields->get_section( $this->object_type, $this->section, $this->object_name ); |
|
339 | + $section = $wp_fields->get_section($this->object_type, $this->section, $this->object_name); |
|
340 | 340 | |
341 | - if ( isset( $section ) && ! $section->check_capabilities() ) { |
|
341 | + if (isset($section) && ! $section->check_capabilities()) { |
|
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | $this->maybe_render(); |
359 | 359 | |
360 | - $template = trim( ob_get_clean() ); |
|
360 | + $template = trim(ob_get_clean()); |
|
361 | 361 | |
362 | 362 | return $template; |
363 | 363 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | */ |
371 | 371 | final public function maybe_render() { |
372 | 372 | |
373 | - if ( ! $this->check_capabilities() ) { |
|
373 | + if ( ! $this->check_capabilities()) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @param WP_Fields_API_Control $this WP_Fields_API_Control instance. |
381 | 381 | */ |
382 | - do_action( 'fields_render_control_' . $this->object_type, $this ); |
|
382 | + do_action('fields_render_control_'.$this->object_type, $this); |
|
383 | 383 | |
384 | 384 | /** |
385 | 385 | * Fires just before a specific control is rendered. |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * |
390 | 390 | * @param WP_Fields_API_Control $this {@see WP_Fields_API_Control} instance. |
391 | 391 | */ |
392 | - do_action( 'fields_render_control_' . $this->object_type . '_' . $this->object_name . '_' . $this->id, $this ); |
|
392 | + do_action('fields_render_control_'.$this->object_type.'_'.$this->object_name.'_'.$this->id, $this); |
|
393 | 393 | |
394 | 394 | $this->render(); |
395 | 395 | |
@@ -401,10 +401,10 @@ discard block |
||
401 | 401 | */ |
402 | 402 | protected function render() { |
403 | 403 | |
404 | - $id = 'fields-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) ); |
|
405 | - $class = 'fields-control fields-control-' . $this->type; |
|
404 | + $id = 'fields-control-'.str_replace('[', '-', str_replace(']', '', $this->id)); |
|
405 | + $class = 'fields-control fields-control-'.$this->type; |
|
406 | 406 | |
407 | - ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
|
407 | + ?><li id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($class); ?>"> |
|
408 | 408 | <?php $this->render_content(); ?> |
409 | 409 | </li><?php |
410 | 410 | |
@@ -417,13 +417,13 @@ discard block |
||
417 | 417 | * @param string $field_key |
418 | 418 | * @return string Data link parameter, if $field_key is a valid field, empty string otherwise. |
419 | 419 | */ |
420 | - public function get_link( $field_key = 'default' ) { |
|
420 | + public function get_link($field_key = 'default') { |
|
421 | 421 | |
422 | - if ( ! isset( $this->fields[ $field_key ] ) ) { |
|
422 | + if ( ! isset($this->fields[$field_key])) { |
|
423 | 423 | return ''; |
424 | 424 | } |
425 | 425 | |
426 | - return 'data-fields-field-link="' . esc_attr( $this->fields[ $field_key ]->id ) . '"'; |
|
426 | + return 'data-fields-field-link="'.esc_attr($this->fields[$field_key]->id).'"'; |
|
427 | 427 | |
428 | 428 | } |
429 | 429 | |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @param string $field_key |
436 | 436 | */ |
437 | - public function link( $field_key = 'default' ) { |
|
437 | + public function link($field_key = 'default') { |
|
438 | 438 | |
439 | - echo $this->get_link( $field_key ); |
|
439 | + echo $this->get_link($field_key); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | */ |
448 | 448 | public function input_attrs() { |
449 | 449 | |
450 | - foreach ( $this->input_attrs as $attr => $value ) { |
|
451 | - echo $attr . '="' . esc_attr( $value ) . '" '; |
|
450 | + foreach ($this->input_attrs as $attr => $value) { |
|
451 | + echo $attr.'="'.esc_attr($value).'" '; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | } |
@@ -467,13 +467,13 @@ discard block |
||
467 | 467 | |
468 | 468 | ?> |
469 | 469 | <label> |
470 | - <?php if ( ! empty( $this->label ) ) : ?> |
|
471 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
470 | + <?php if ( ! empty($this->label)) : ?> |
|
471 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
472 | 472 | <?php endif; |
473 | - if ( ! empty( $this->description ) ) : ?> |
|
473 | + if ( ! empty($this->description)) : ?> |
|
474 | 474 | <span class="description fields-control-description"><?php echo $this->description; ?></span> |
475 | 475 | <?php endif; ?> |
476 | - <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> /> |
|
476 | + <input type="<?php echo esc_attr($this->type); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr($this->value()); ?>" <?php $this->link(); ?> /> |
|
477 | 477 | </label> |
478 | 478 | <?php |
479 | 479 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | public function print_template() { |
492 | 492 | |
493 | 493 | ?> |
494 | - <script type="text/html" id="tmpl-fields-<?php echo esc_attr( $this->object_type ); ?>-control-<?php echo esc_attr( $this->type ); ?>-content"> |
|
494 | + <script type="text/html" id="tmpl-fields-<?php echo esc_attr($this->object_type); ?>-control-<?php echo esc_attr($this->type); ?>-content"> |
|
495 | 495 | <?php $this->content_template(); ?> |
496 | 496 | </script> |
497 | 497 | <?php |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return mixed |
521 | 521 | */ |
522 | - public function &__get( $name ) { |
|
522 | + public function &__get($name) { |
|
523 | 523 | |
524 | 524 | // Map $this->choices to $this->choices() for dynamic choice handling |
525 | - if ( 'choices' == $name ) { |
|
525 | + if ('choices' == $name) { |
|
526 | 526 | $this->setup_choices(); |
527 | 527 | |
528 | 528 | return $this->choices; |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function setUp() { |
22 | 22 | parent::setUp(); |
23 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
23 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
24 | 24 | //require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
25 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
25 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
26 | 26 | |
27 | 27 | global $wp_customize; |
28 | 28 | $this->wp_customize = new WP_Customize_Manager(); |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @param object $menu_item Menu item. |
45 | 45 | * @return object |
46 | 46 | */ |
47 | - function filter_type_label( $menu_item ) { |
|
48 | - if ( 'custom_type' === $menu_item->type ) { |
|
47 | + function filter_type_label($menu_item) { |
|
48 | + if ('custom_type' === $menu_item->type) { |
|
49 | 49 | $menu_item->type_label = 'Custom Label'; |
50 | 50 | } |
51 | 51 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * Test constants and statics. |
57 | 57 | */ |
58 | 58 | function test_constants() { |
59 | - do_action( 'customize_register', $this->wp_customize ); |
|
60 | - $this->assertTrue( post_type_exists( WP_Customize_Nav_Menu_Item_Setting::POST_TYPE ) ); |
|
59 | + do_action('customize_register', $this->wp_customize); |
|
60 | + $this->assertTrue(post_type_exists(WP_Customize_Nav_Menu_Item_Setting::POST_TYPE)); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | * @see WP_Customize_Nav_Menu_Item_Setting::__construct() |
67 | 67 | */ |
68 | 68 | function test_construct() { |
69 | - do_action( 'customize_register', $this->wp_customize ); |
|
69 | + do_action('customize_register', $this->wp_customize); |
|
70 | 70 | |
71 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[123]' ); |
|
72 | - $this->assertEquals( 'nav_menu_item', $setting->type ); |
|
73 | - $this->assertEquals( 'postMessage', $setting->transport ); |
|
74 | - $this->assertEquals( 123, $setting->post_id ); |
|
75 | - $this->assertNull( $setting->previous_post_id ); |
|
76 | - $this->assertNull( $setting->update_status ); |
|
77 | - $this->assertNull( $setting->update_error ); |
|
78 | - $this->assertInternalType( 'array', $setting->default ); |
|
71 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[123]'); |
|
72 | + $this->assertEquals('nav_menu_item', $setting->type); |
|
73 | + $this->assertEquals('postMessage', $setting->transport); |
|
74 | + $this->assertEquals(123, $setting->post_id); |
|
75 | + $this->assertNull($setting->previous_post_id); |
|
76 | + $this->assertNull($setting->update_status); |
|
77 | + $this->assertNull($setting->update_error); |
|
78 | + $this->assertInternalType('array', $setting->default); |
|
79 | 79 | |
80 | 80 | $default = array( |
81 | 81 | 'object_id' => 0, |
@@ -94,34 +94,34 @@ discard block |
||
94 | 94 | 'original_title' => '', |
95 | 95 | 'nav_menu_term_id' => 0, |
96 | 96 | ); |
97 | - $this->assertEquals( $default, $setting->default ); |
|
97 | + $this->assertEquals($default, $setting->default); |
|
98 | 98 | |
99 | 99 | $exception = null; |
100 | 100 | try { |
101 | - $bad_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'foo_bar_baz' ); |
|
102 | - unset( $bad_setting ); |
|
103 | - } catch ( Exception $e ) { |
|
101 | + $bad_setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'foo_bar_baz'); |
|
102 | + unset($bad_setting); |
|
103 | + } catch (Exception $e) { |
|
104 | 104 | $exception = $e; |
105 | 105 | } |
106 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
106 | + $this->assertInstanceOf('Exception', $exception); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Test empty constructor. |
111 | 111 | */ |
112 | 112 | function test_construct_empty_menus() { |
113 | - do_action( 'customize_register', $this->wp_customize ); |
|
113 | + do_action('customize_register', $this->wp_customize); |
|
114 | 114 | $_wp_customize = $this->wp_customize; |
115 | 115 | unset($_wp_customize->nav_menus); |
116 | 116 | |
117 | 117 | $exception = null; |
118 | 118 | try { |
119 | - $bad_setting = new WP_Customize_Nav_Menu_Item_Setting( $_wp_customize, 'nav_menu_item[123]' ); |
|
120 | - unset( $bad_setting ); |
|
121 | - } catch ( Exception $e ) { |
|
119 | + $bad_setting = new WP_Customize_Nav_Menu_Item_Setting($_wp_customize, 'nav_menu_item[123]'); |
|
120 | + unset($bad_setting); |
|
121 | + } catch (Exception $e) { |
|
122 | 122 | $exception = $e; |
123 | 123 | } |
124 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
124 | + $this->assertInstanceOf('Exception', $exception); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,16 +130,16 @@ discard block |
||
130 | 130 | * @see WP_Customize_Nav_Menu_Item_Setting::__construct() |
131 | 131 | */ |
132 | 132 | function test_construct_placeholder() { |
133 | - do_action( 'customize_register', $this->wp_customize ); |
|
133 | + do_action('customize_register', $this->wp_customize); |
|
134 | 134 | $default = array( |
135 | 135 | 'title' => 'Lorem', |
136 | 136 | 'description' => 'ipsum', |
137 | 137 | 'menu_item_parent' => 123, |
138 | 138 | ); |
139 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[-5]', compact( 'default' ) ); |
|
139 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[-5]', compact('default')); |
|
140 | 140 | $this->assertEquals( -5, $setting->post_id ); |
141 | - $this->assertNull( $setting->previous_post_id ); |
|
142 | - $this->assertEquals( $default, $setting->default ); |
|
141 | + $this->assertNull($setting->previous_post_id); |
|
142 | + $this->assertEquals($default, $setting->default); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,41 +148,41 @@ discard block |
||
148 | 148 | * @see WP_Customize_Nav_Menu_Item_Setting::value() |
149 | 149 | */ |
150 | 150 | function test_value_type_post_type() { |
151 | - do_action( 'customize_register', $this->wp_customize ); |
|
151 | + do_action('customize_register', $this->wp_customize); |
|
152 | 152 | |
153 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
153 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
154 | 154 | |
155 | - $menu_id = wp_create_nav_menu( 'Menu' ); |
|
155 | + $menu_id = wp_create_nav_menu('Menu'); |
|
156 | 156 | $item_title = 'Greetings'; |
157 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
157 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
158 | 158 | 'menu-item-type' => 'post_type', |
159 | 159 | 'menu-item-object' => 'post', |
160 | 160 | 'menu-item-object-id' => $post_id, |
161 | 161 | 'menu-item-title' => $item_title, |
162 | 162 | 'menu-item-status' => 'publish', |
163 | - ) ); |
|
163 | + )); |
|
164 | 164 | |
165 | - $post = get_post( $item_id ); |
|
166 | - $menu_item = wp_setup_nav_menu_item( $post ); |
|
167 | - $this->assertEquals( $item_title, $menu_item->title ); |
|
165 | + $post = get_post($item_id); |
|
166 | + $menu_item = wp_setup_nav_menu_item($post); |
|
167 | + $this->assertEquals($item_title, $menu_item->title); |
|
168 | 168 | |
169 | 169 | $setting_id = "nav_menu_item[$item_id]"; |
170 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
170 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
171 | 171 | |
172 | 172 | $value = $setting->value(); |
173 | - $this->assertEquals( $menu_item->title, $value['title'] ); |
|
174 | - $this->assertEquals( $menu_item->type, $value['type'] ); |
|
175 | - $this->assertEquals( $menu_item->object_id, $value['object_id'] ); |
|
176 | - $this->assertEquals( $menu_id, $value['nav_menu_term_id'] ); |
|
177 | - $this->assertEquals( 'Hello World', $value['original_title'] ); |
|
178 | - |
|
179 | - $other_menu_id = wp_create_nav_menu( 'Menu2' ); |
|
180 | - wp_update_nav_menu_item( $other_menu_id, $item_id, array( |
|
173 | + $this->assertEquals($menu_item->title, $value['title']); |
|
174 | + $this->assertEquals($menu_item->type, $value['type']); |
|
175 | + $this->assertEquals($menu_item->object_id, $value['object_id']); |
|
176 | + $this->assertEquals($menu_id, $value['nav_menu_term_id']); |
|
177 | + $this->assertEquals('Hello World', $value['original_title']); |
|
178 | + |
|
179 | + $other_menu_id = wp_create_nav_menu('Menu2'); |
|
180 | + wp_update_nav_menu_item($other_menu_id, $item_id, array( |
|
181 | 181 | 'menu-item-title' => 'Hola', |
182 | - ) ); |
|
182 | + )); |
|
183 | 183 | $value = $setting->value(); |
184 | - $this->assertEquals( 'Hola', $value['title'] ); |
|
185 | - $this->assertEquals( $other_menu_id, $value['nav_menu_term_id'] ); |
|
184 | + $this->assertEquals('Hola', $value['title']); |
|
185 | + $this->assertEquals($other_menu_id, $value['nav_menu_term_id']); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,33 +191,33 @@ discard block |
||
191 | 191 | * @see WP_Customize_Nav_Menu_Item_Setting::value() |
192 | 192 | */ |
193 | 193 | function test_value_type_taxonomy() { |
194 | - do_action( 'customize_register', $this->wp_customize ); |
|
194 | + do_action('customize_register', $this->wp_customize); |
|
195 | 195 | |
196 | - $tax_id = $this->factory->category->create( array( 'name' => 'Salutations' ) ); |
|
196 | + $tax_id = $this->factory->category->create(array('name' => 'Salutations')); |
|
197 | 197 | |
198 | - $menu_id = wp_create_nav_menu( 'Menu' ); |
|
198 | + $menu_id = wp_create_nav_menu('Menu'); |
|
199 | 199 | $item_title = 'Greetings'; |
200 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
200 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
201 | 201 | 'menu-item-type' => 'taxonomy', |
202 | 202 | 'menu-item-object' => 'category', |
203 | 203 | 'menu-item-object-id' => $tax_id, |
204 | 204 | 'menu-item-title' => $item_title, |
205 | 205 | 'menu-item-status' => 'publish', |
206 | - ) ); |
|
206 | + )); |
|
207 | 207 | |
208 | - $post = get_post( $item_id ); |
|
209 | - $menu_item = wp_setup_nav_menu_item( $post ); |
|
210 | - $this->assertEquals( $item_title, $menu_item->title ); |
|
208 | + $post = get_post($item_id); |
|
209 | + $menu_item = wp_setup_nav_menu_item($post); |
|
210 | + $this->assertEquals($item_title, $menu_item->title); |
|
211 | 211 | |
212 | 212 | $setting_id = "nav_menu_item[$item_id]"; |
213 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
213 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
214 | 214 | |
215 | 215 | $value = $setting->value(); |
216 | - $this->assertEquals( $menu_item->title, $value['title'] ); |
|
217 | - $this->assertEquals( $menu_item->type, $value['type'] ); |
|
218 | - $this->assertEquals( $menu_item->object_id, $value['object_id'] ); |
|
219 | - $this->assertEquals( $menu_id, $value['nav_menu_term_id'] ); |
|
220 | - $this->assertEquals( 'Salutations', $value['original_title'] ); |
|
216 | + $this->assertEquals($menu_item->title, $value['title']); |
|
217 | + $this->assertEquals($menu_item->type, $value['type']); |
|
218 | + $this->assertEquals($menu_item->object_id, $value['object_id']); |
|
219 | + $this->assertEquals($menu_id, $value['nav_menu_term_id']); |
|
220 | + $this->assertEquals('Salutations', $value['original_title']); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -226,26 +226,26 @@ discard block |
||
226 | 226 | * @see WP_Customize_Nav_Menu_Item_Setting::value() |
227 | 227 | */ |
228 | 228 | function test_custom_type_label() { |
229 | - do_action( 'customize_register', $this->wp_customize ); |
|
230 | - add_filter( 'wp_setup_nav_menu_item', array( $this, 'filter_type_label' ) ); |
|
229 | + do_action('customize_register', $this->wp_customize); |
|
230 | + add_filter('wp_setup_nav_menu_item', array($this, 'filter_type_label')); |
|
231 | 231 | |
232 | - $menu_id = wp_create_nav_menu( 'Menu' ); |
|
233 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
232 | + $menu_id = wp_create_nav_menu('Menu'); |
|
233 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
234 | 234 | 'menu-item-type' => 'custom_type', |
235 | 235 | 'menu-item-object' => 'custom_object', |
236 | 236 | 'menu-item-title' => 'Cool beans', |
237 | 237 | 'menu-item-status' => 'publish', |
238 | - ) ); |
|
238 | + )); |
|
239 | 239 | |
240 | - $post = get_post( $item_id ); |
|
241 | - $menu_item = wp_setup_nav_menu_item( $post ); |
|
240 | + $post = get_post($item_id); |
|
241 | + $menu_item = wp_setup_nav_menu_item($post); |
|
242 | 242 | |
243 | 243 | $setting_id = "nav_menu_item[$item_id]"; |
244 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
244 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
245 | 245 | |
246 | 246 | $value = $setting->value(); |
247 | - $this->assertEquals( $menu_item->type_label, 'Custom Label' ); |
|
248 | - $this->assertEquals( $menu_item->type_label, $value['type_label'] ); |
|
247 | + $this->assertEquals($menu_item->type_label, 'Custom Label'); |
|
248 | + $this->assertEquals($menu_item->type_label, $value['type_label']); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @see WP_Customize_Nav_Menu_Item_Setting::value() |
255 | 255 | */ |
256 | 256 | function test_value_nav_menu_term_id_returns_zero() { |
257 | - do_action( 'customize_register', $this->wp_customize ); |
|
257 | + do_action('customize_register', $this->wp_customize); |
|
258 | 258 | |
259 | 259 | $menu_id = -123; |
260 | 260 | $post_value = array( |
@@ -264,29 +264,29 @@ discard block |
||
264 | 264 | 'auto_add' => false, |
265 | 265 | ); |
266 | 266 | $setting_id = "nav_menu[$menu_id]"; |
267 | - $menu = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
267 | + $menu = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
268 | 268 | |
269 | - $this->wp_customize->set_post_value( $menu->id, $post_value ); |
|
269 | + $this->wp_customize->set_post_value($menu->id, $post_value); |
|
270 | 270 | $menu->preview(); |
271 | 271 | $value = $menu->value(); |
272 | - $this->assertEquals( $post_value, $value ); |
|
272 | + $this->assertEquals($post_value, $value); |
|
273 | 273 | |
274 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
275 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
274 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
275 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
276 | 276 | 'menu-item-type' => 'post_type', |
277 | 277 | 'menu-item-object' => 'post', |
278 | 278 | 'menu-item-object-id' => $post_id, |
279 | 279 | 'menu-item-title' => 'Hello World', |
280 | 280 | 'menu-item-status' => 'publish', |
281 | - ) ); |
|
281 | + )); |
|
282 | 282 | |
283 | - $post = get_post( $item_id ); |
|
284 | - $menu_item = wp_setup_nav_menu_item( $post ); |
|
283 | + $post = get_post($item_id); |
|
284 | + $menu_item = wp_setup_nav_menu_item($post); |
|
285 | 285 | |
286 | 286 | $setting_id = "nav_menu_item[$item_id]"; |
287 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
287 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
288 | 288 | $value = $setting->value(); |
289 | - $this->assertEquals( 0, $value['nav_menu_term_id'] ); |
|
289 | + $this->assertEquals(0, $value['nav_menu_term_id']); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,22 +295,22 @@ discard block |
||
295 | 295 | * @see WP_Customize_Nav_Menu_Item_Setting::preview() |
296 | 296 | */ |
297 | 297 | function test_preview_updated() { |
298 | - do_action( 'customize_register', $this->wp_customize ); |
|
298 | + do_action('customize_register', $this->wp_customize); |
|
299 | 299 | |
300 | - $first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
301 | - $second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) ); |
|
300 | + $first_post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
301 | + $second_post_id = $this->factory->post->create(array('post_title' => 'Hola Muno')); |
|
302 | 302 | |
303 | - $primary_menu_id = wp_create_nav_menu( 'Primary' ); |
|
304 | - $secondary_menu_id = wp_create_nav_menu( 'Secondary' ); |
|
303 | + $primary_menu_id = wp_create_nav_menu('Primary'); |
|
304 | + $secondary_menu_id = wp_create_nav_menu('Secondary'); |
|
305 | 305 | $item_title = 'Greetings'; |
306 | - $item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array( |
|
306 | + $item_id = wp_update_nav_menu_item($primary_menu_id, 0, array( |
|
307 | 307 | 'menu-item-type' => 'post_type', |
308 | 308 | 'menu-item-object' => 'post', |
309 | 309 | 'menu-item-object-id' => $first_post_id, |
310 | 310 | 'menu-item-title' => $item_title, |
311 | 311 | 'menu-item-status' => 'publish', |
312 | - ) ); |
|
313 | - $this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) ); |
|
312 | + )); |
|
313 | + $this->assertNotEmpty(wp_get_nav_menu_items($primary_menu_id, array('post_status' => 'publish,draft'))); |
|
314 | 314 | |
315 | 315 | $post_value = array( |
316 | 316 | 'type' => 'post_type', |
@@ -321,22 +321,22 @@ discard block |
||
321 | 321 | 'nav_menu_term_id' => $secondary_menu_id, |
322 | 322 | ); |
323 | 323 | $setting_id = "nav_menu_item[$item_id]"; |
324 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
325 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
326 | - unset( $post_value['nav_menu_term_id'] ); |
|
324 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
325 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
326 | + unset($post_value['nav_menu_term_id']); |
|
327 | 327 | $setting->preview(); |
328 | 328 | |
329 | 329 | // Make sure the menu item appears in the new menu. |
330 | - $this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) ); |
|
331 | - $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); |
|
332 | - $db_ids = wp_list_pluck( $menu_items, 'db_id' ); |
|
333 | - $this->assertContains( $item_id, $db_ids ); |
|
334 | - $i = array_search( $item_id, $db_ids ); |
|
335 | - $updated_item = $menu_items[ $i ]; |
|
330 | + $this->assertNotContains($item_id, wp_list_pluck(wp_get_nav_menu_items($primary_menu_id), 'db_id')); |
|
331 | + $menu_items = wp_get_nav_menu_items($secondary_menu_id); |
|
332 | + $db_ids = wp_list_pluck($menu_items, 'db_id'); |
|
333 | + $this->assertContains($item_id, $db_ids); |
|
334 | + $i = array_search($item_id, $db_ids); |
|
335 | + $updated_item = $menu_items[$i]; |
|
336 | 336 | $post_value['post_status'] = $post_value['status']; |
337 | - unset( $post_value['status'] ); |
|
338 | - foreach ( $post_value as $key => $value ) { |
|
339 | - $this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" ); |
|
337 | + unset($post_value['status']); |
|
338 | + foreach ($post_value as $key => $value) { |
|
339 | + $this->assertEquals($value, $updated_item->$key, "Key $key mismatch"); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -346,20 +346,20 @@ discard block |
||
346 | 346 | * @see WP_Customize_Nav_Menu_Item_Setting::preview() |
347 | 347 | */ |
348 | 348 | function test_preview_inserted() { |
349 | - do_action( 'customize_register', $this->wp_customize ); |
|
349 | + do_action('customize_register', $this->wp_customize); |
|
350 | 350 | |
351 | - $menu_id = wp_create_nav_menu( 'Primary' ); |
|
352 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
351 | + $menu_id = wp_create_nav_menu('Primary'); |
|
352 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
353 | 353 | $item_ids = array(); |
354 | - for ( $i = 0; $i < 5; $i += 1 ) { |
|
355 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
354 | + for ($i = 0; $i < 5; $i += 1) { |
|
355 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
356 | 356 | 'menu-item-type' => 'post_type', |
357 | 357 | 'menu-item-object' => 'post', |
358 | 358 | 'menu-item-object-id' => $post_id, |
359 | 359 | 'menu-item-title' => "Item $i", |
360 | 360 | 'menu-item-status' => 'publish', |
361 | 361 | 'menu-item-position' => $i + 1, |
362 | - ) ); |
|
362 | + )); |
|
363 | 363 | $item_ids[] = $item_id; |
364 | 364 | } |
365 | 365 | |
@@ -370,28 +370,28 @@ discard block |
||
370 | 370 | 'title' => 'Inserted item', |
371 | 371 | 'status' => 'publish', |
372 | 372 | 'nav_menu_term_id' => $menu_id, |
373 | - 'position' => count( $item_ids ) + 1, |
|
373 | + 'position' => count($item_ids) + 1, |
|
374 | 374 | ); |
375 | 375 | |
376 | 376 | $new_item_id = -10; |
377 | 377 | $setting_id = "nav_menu_item[$new_item_id]"; |
378 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
379 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
380 | - unset( $post_value['nav_menu_term_id'] ); |
|
378 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
379 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
380 | + unset($post_value['nav_menu_term_id']); |
|
381 | 381 | |
382 | - $current_items = wp_get_nav_menu_items( $menu_id ); |
|
382 | + $current_items = wp_get_nav_menu_items($menu_id); |
|
383 | 383 | $setting->preview(); |
384 | - $preview_items = wp_get_nav_menu_items( $menu_id ); |
|
385 | - $this->assertNotEquals( count( $current_items ), count( $preview_items ) ); |
|
384 | + $preview_items = wp_get_nav_menu_items($menu_id); |
|
385 | + $this->assertNotEquals(count($current_items), count($preview_items)); |
|
386 | 386 | |
387 | - $last_item = array_pop( $preview_items ); |
|
388 | - $this->assertEquals( $new_item_id, $last_item->db_id ); |
|
387 | + $last_item = array_pop($preview_items); |
|
388 | + $this->assertEquals($new_item_id, $last_item->db_id); |
|
389 | 389 | $post_value['post_status'] = $post_value['status']; |
390 | - unset( $post_value['status'] ); |
|
390 | + unset($post_value['status']); |
|
391 | 391 | $post_value['menu_order'] = $post_value['position']; |
392 | - unset( $post_value['position'] ); |
|
393 | - foreach ( $post_value as $key => $value ) { |
|
394 | - $this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." ); |
|
392 | + unset($post_value['position']); |
|
393 | + foreach ($post_value as $key => $value) { |
|
394 | + $this->assertEquals($value, $last_item->$key, "Mismatch for $key property."); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
@@ -401,34 +401,34 @@ discard block |
||
401 | 401 | * @see WP_Customize_Nav_Menu_Item_Setting::preview() |
402 | 402 | */ |
403 | 403 | function test_preview_deleted() { |
404 | - do_action( 'customize_register', $this->wp_customize ); |
|
404 | + do_action('customize_register', $this->wp_customize); |
|
405 | 405 | |
406 | - $menu_id = wp_create_nav_menu( 'Primary' ); |
|
407 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
406 | + $menu_id = wp_create_nav_menu('Primary'); |
|
407 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
408 | 408 | $item_ids = array(); |
409 | - for ( $i = 0; $i < 5; $i += 1 ) { |
|
410 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
409 | + for ($i = 0; $i < 5; $i += 1) { |
|
410 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
411 | 411 | 'menu-item-type' => 'post_type', |
412 | 412 | 'menu-item-object' => 'post', |
413 | 413 | 'menu-item-object-id' => $post_id, |
414 | 414 | 'menu-item-title' => "Item $i", |
415 | 415 | 'menu-item-status' => 'publish', |
416 | 416 | 'menu-item-position' => $i + 1, |
417 | - ) ); |
|
417 | + )); |
|
418 | 418 | $item_ids[] = $item_id; |
419 | 419 | } |
420 | 420 | |
421 | 421 | $delete_item_id = $item_ids[2]; |
422 | 422 | $setting_id = "nav_menu_item[$delete_item_id]"; |
423 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
424 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
423 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
424 | + $this->wp_customize->set_post_value($setting_id, false); |
|
425 | 425 | |
426 | - $current_items = wp_get_nav_menu_items( $menu_id ); |
|
427 | - $this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) ); |
|
426 | + $current_items = wp_get_nav_menu_items($menu_id); |
|
427 | + $this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id')); |
|
428 | 428 | $setting->preview(); |
429 | - $preview_items = wp_get_nav_menu_items( $menu_id ); |
|
430 | - $this->assertNotEquals( count( $current_items ), count( $preview_items ) ); |
|
431 | - $this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) ); |
|
429 | + $preview_items = wp_get_nav_menu_items($menu_id); |
|
430 | + $this->assertNotEquals(count($current_items), count($preview_items)); |
|
431 | + $this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id')); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | * @see WP_Customize_Nav_Menu_Item_Setting::sanitize() |
438 | 438 | */ |
439 | 439 | function test_sanitize() { |
440 | - do_action( 'customize_register', $this->wp_customize ); |
|
441 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[123]' ); |
|
440 | + do_action('customize_register', $this->wp_customize); |
|
441 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[123]'); |
|
442 | 442 | |
443 | - $this->assertNull( $setting->sanitize( 'not an array' ) ); |
|
444 | - $this->assertNull( $setting->sanitize( 123 ) ); |
|
443 | + $this->assertNull($setting->sanitize('not an array')); |
|
444 | + $this->assertNull($setting->sanitize(123)); |
|
445 | 445 | |
446 | 446 | $unsanitized = array( |
447 | 447 | 'object_id' => 'bad', |
@@ -461,24 +461,24 @@ discard block |
||
461 | 461 | 'nav_menu_term_id' => 'heilo', |
462 | 462 | ); |
463 | 463 | |
464 | - $sanitized = $setting->sanitize( $unsanitized ); |
|
465 | - $this->assertEqualSets( array_keys( $unsanitized ), array_keys( $sanitized ) ); |
|
466 | - |
|
467 | - $this->assertEquals( 0, $sanitized['object_id'] ); |
|
468 | - $this->assertEquals( 'bhellob', $sanitized['object'] ); |
|
469 | - $this->assertEquals( 0, $sanitized['menu_item_parent'] ); |
|
470 | - $this->assertEquals( 0, $sanitized['position'] ); |
|
471 | - $this->assertEquals( 'customb', $sanitized['type'] ); |
|
472 | - $this->assertEquals( 'Hi', $sanitized['title'] ); |
|
473 | - $this->assertEquals( '', $sanitized['url'] ); |
|
474 | - $this->assertEquals( 'onclick', $sanitized['target'] ); |
|
475 | - $this->assertEquals( 'evil', $sanitized['attr_title'] ); |
|
476 | - $this->assertEquals( 'Hello world', $sanitized['description'] ); |
|
477 | - $this->assertEquals( 'hello inject', $sanitized['classes'] ); |
|
478 | - $this->assertEquals( 'hello inject', $sanitized['xfn'] ); |
|
479 | - $this->assertEquals( 'publish', $sanitized['status'] ); |
|
480 | - $this->assertEquals( 'Hi', $sanitized['original_title'] ); |
|
481 | - $this->assertEquals( 0, $sanitized['nav_menu_term_id'] ); |
|
464 | + $sanitized = $setting->sanitize($unsanitized); |
|
465 | + $this->assertEqualSets(array_keys($unsanitized), array_keys($sanitized)); |
|
466 | + |
|
467 | + $this->assertEquals(0, $sanitized['object_id']); |
|
468 | + $this->assertEquals('bhellob', $sanitized['object']); |
|
469 | + $this->assertEquals(0, $sanitized['menu_item_parent']); |
|
470 | + $this->assertEquals(0, $sanitized['position']); |
|
471 | + $this->assertEquals('customb', $sanitized['type']); |
|
472 | + $this->assertEquals('Hi', $sanitized['title']); |
|
473 | + $this->assertEquals('', $sanitized['url']); |
|
474 | + $this->assertEquals('onclick', $sanitized['target']); |
|
475 | + $this->assertEquals('evil', $sanitized['attr_title']); |
|
476 | + $this->assertEquals('Hello world', $sanitized['description']); |
|
477 | + $this->assertEquals('hello inject', $sanitized['classes']); |
|
478 | + $this->assertEquals('hello inject', $sanitized['xfn']); |
|
479 | + $this->assertEquals('publish', $sanitized['status']); |
|
480 | + $this->assertEquals('Hi', $sanitized['original_title']); |
|
481 | + $this->assertEquals(0, $sanitized['nav_menu_term_id']); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
@@ -487,22 +487,22 @@ discard block |
||
487 | 487 | * @see WP_Customize_Nav_Menu_Item_Setting::update() |
488 | 488 | */ |
489 | 489 | function test_save_updated() { |
490 | - do_action( 'customize_register', $this->wp_customize ); |
|
490 | + do_action('customize_register', $this->wp_customize); |
|
491 | 491 | |
492 | - $first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
493 | - $second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) ); |
|
492 | + $first_post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
493 | + $second_post_id = $this->factory->post->create(array('post_title' => 'Hola Muno')); |
|
494 | 494 | |
495 | - $primary_menu_id = wp_create_nav_menu( 'Primary' ); |
|
496 | - $secondary_menu_id = wp_create_nav_menu( 'Secondary' ); |
|
495 | + $primary_menu_id = wp_create_nav_menu('Primary'); |
|
496 | + $secondary_menu_id = wp_create_nav_menu('Secondary'); |
|
497 | 497 | $item_title = 'Greetings'; |
498 | - $item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array( |
|
498 | + $item_id = wp_update_nav_menu_item($primary_menu_id, 0, array( |
|
499 | 499 | 'menu-item-type' => 'post_type', |
500 | 500 | 'menu-item-object' => 'post', |
501 | 501 | 'menu-item-object-id' => $first_post_id, |
502 | 502 | 'menu-item-title' => $item_title, |
503 | 503 | 'menu-item-status' => 'publish', |
504 | - ) ); |
|
505 | - $this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) ); |
|
504 | + )); |
|
505 | + $this->assertNotEmpty(wp_get_nav_menu_items($primary_menu_id, array('post_status' => 'publish,draft'))); |
|
506 | 506 | |
507 | 507 | $post_value = array( |
508 | 508 | 'type' => 'post_type', |
@@ -513,37 +513,37 @@ discard block |
||
513 | 513 | 'nav_menu_term_id' => $secondary_menu_id, |
514 | 514 | ); |
515 | 515 | $setting_id = "nav_menu_item[$item_id]"; |
516 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
517 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
518 | - unset( $post_value['nav_menu_term_id'] ); |
|
516 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
517 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
518 | + unset($post_value['nav_menu_term_id']); |
|
519 | 519 | $setting->save(); |
520 | 520 | |
521 | 521 | // Make sure the menu item appears in the new menu. |
522 | - $this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) ); |
|
523 | - $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); |
|
524 | - $db_ids = wp_list_pluck( $menu_items, 'db_id' ); |
|
525 | - $this->assertContains( $item_id, $db_ids ); |
|
526 | - $i = array_search( $item_id, $db_ids ); |
|
527 | - $updated_item = $menu_items[ $i ]; |
|
522 | + $this->assertNotContains($item_id, wp_list_pluck(wp_get_nav_menu_items($primary_menu_id), 'db_id')); |
|
523 | + $menu_items = wp_get_nav_menu_items($secondary_menu_id); |
|
524 | + $db_ids = wp_list_pluck($menu_items, 'db_id'); |
|
525 | + $this->assertContains($item_id, $db_ids); |
|
526 | + $i = array_search($item_id, $db_ids); |
|
527 | + $updated_item = $menu_items[$i]; |
|
528 | 528 | $post_value['post_status'] = $post_value['status']; |
529 | - unset( $post_value['status'] ); |
|
530 | - foreach ( $post_value as $key => $value ) { |
|
531 | - $this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" ); |
|
529 | + unset($post_value['status']); |
|
530 | + foreach ($post_value as $key => $value) { |
|
531 | + $this->assertEquals($value, $updated_item->$key, "Key $key mismatch"); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | // Verify the Ajax responses is being amended. |
535 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
536 | - $this->assertArrayHasKey( 'nav_menu_item_updates', $save_response ); |
|
537 | - $update_result = array_shift( $save_response['nav_menu_item_updates'] ); |
|
538 | - $this->assertArrayHasKey( 'post_id', $update_result ); |
|
539 | - $this->assertArrayHasKey( 'previous_post_id', $update_result ); |
|
540 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
541 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
542 | - |
|
543 | - $this->assertEquals( $item_id, $update_result['post_id'] ); |
|
544 | - $this->assertNull( $update_result['previous_post_id'] ); |
|
545 | - $this->assertNull( $update_result['error'] ); |
|
546 | - $this->assertEquals( 'updated', $update_result['status'] ); |
|
535 | + $save_response = apply_filters('customize_save_response', array()); |
|
536 | + $this->assertArrayHasKey('nav_menu_item_updates', $save_response); |
|
537 | + $update_result = array_shift($save_response['nav_menu_item_updates']); |
|
538 | + $this->assertArrayHasKey('post_id', $update_result); |
|
539 | + $this->assertArrayHasKey('previous_post_id', $update_result); |
|
540 | + $this->assertArrayHasKey('error', $update_result); |
|
541 | + $this->assertArrayHasKey('status', $update_result); |
|
542 | + |
|
543 | + $this->assertEquals($item_id, $update_result['post_id']); |
|
544 | + $this->assertNull($update_result['previous_post_id']); |
|
545 | + $this->assertNull($update_result['error']); |
|
546 | + $this->assertEquals('updated', $update_result['status']); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -552,20 +552,20 @@ discard block |
||
552 | 552 | * @see WP_Customize_Nav_Menu_Item_Setting::update() |
553 | 553 | */ |
554 | 554 | function test_save_inserted() { |
555 | - do_action( 'customize_register', $this->wp_customize ); |
|
555 | + do_action('customize_register', $this->wp_customize); |
|
556 | 556 | |
557 | - $menu_id = wp_create_nav_menu( 'Primary' ); |
|
558 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
557 | + $menu_id = wp_create_nav_menu('Primary'); |
|
558 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
559 | 559 | $item_ids = array(); |
560 | - for ( $i = 0; $i < 5; $i += 1 ) { |
|
561 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
560 | + for ($i = 0; $i < 5; $i += 1) { |
|
561 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
562 | 562 | 'menu-item-type' => 'post_type', |
563 | 563 | 'menu-item-object' => 'post', |
564 | 564 | 'menu-item-object-id' => $post_id, |
565 | 565 | 'menu-item-title' => "Item $i", |
566 | 566 | 'menu-item-status' => 'publish', |
567 | 567 | 'menu-item-position' => $i + 1, |
568 | - ) ); |
|
568 | + )); |
|
569 | 569 | $item_ids[] = $item_id; |
570 | 570 | } |
571 | 571 | |
@@ -576,43 +576,43 @@ discard block |
||
576 | 576 | 'title' => 'Inserted item', |
577 | 577 | 'status' => 'publish', |
578 | 578 | 'nav_menu_term_id' => $menu_id, |
579 | - 'position' => count( $item_ids ) + 1, |
|
579 | + 'position' => count($item_ids) + 1, |
|
580 | 580 | ); |
581 | 581 | |
582 | 582 | $new_item_id = -10; |
583 | 583 | $setting_id = "nav_menu_item[$new_item_id]"; |
584 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
585 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
586 | - unset( $post_value['nav_menu_term_id'] ); |
|
584 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
585 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
586 | + unset($post_value['nav_menu_term_id']); |
|
587 | 587 | |
588 | - $current_items = wp_get_nav_menu_items( $menu_id ); |
|
588 | + $current_items = wp_get_nav_menu_items($menu_id); |
|
589 | 589 | $setting->save(); |
590 | - $preview_items = wp_get_nav_menu_items( $menu_id ); |
|
591 | - $this->assertNotEquals( count( $current_items ), count( $preview_items ) ); |
|
590 | + $preview_items = wp_get_nav_menu_items($menu_id); |
|
591 | + $this->assertNotEquals(count($current_items), count($preview_items)); |
|
592 | 592 | |
593 | - $last_item = array_pop( $preview_items ); |
|
594 | - $this->assertEquals( $setting->post_id, $last_item->db_id ); |
|
593 | + $last_item = array_pop($preview_items); |
|
594 | + $this->assertEquals($setting->post_id, $last_item->db_id); |
|
595 | 595 | $post_value['post_status'] = $post_value['status']; |
596 | - unset( $post_value['status'] ); |
|
596 | + unset($post_value['status']); |
|
597 | 597 | $post_value['menu_order'] = $post_value['position']; |
598 | - unset( $post_value['position'] ); |
|
599 | - foreach ( $post_value as $key => $value ) { |
|
600 | - $this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." ); |
|
598 | + unset($post_value['position']); |
|
599 | + foreach ($post_value as $key => $value) { |
|
600 | + $this->assertEquals($value, $last_item->$key, "Mismatch for $key property."); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | // Verify the Ajax responses is being amended. |
604 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
605 | - $this->assertArrayHasKey( 'nav_menu_item_updates', $save_response ); |
|
606 | - $update_result = array_shift( $save_response['nav_menu_item_updates'] ); |
|
607 | - $this->assertArrayHasKey( 'post_id', $update_result ); |
|
608 | - $this->assertArrayHasKey( 'previous_post_id', $update_result ); |
|
609 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
610 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
611 | - |
|
612 | - $this->assertEquals( $setting->post_id, $update_result['post_id'] ); |
|
613 | - $this->assertEquals( $new_item_id, $update_result['previous_post_id'] ); |
|
614 | - $this->assertNull( $update_result['error'] ); |
|
615 | - $this->assertEquals( 'inserted', $update_result['status'] ); |
|
604 | + $save_response = apply_filters('customize_save_response', array()); |
|
605 | + $this->assertArrayHasKey('nav_menu_item_updates', $save_response); |
|
606 | + $update_result = array_shift($save_response['nav_menu_item_updates']); |
|
607 | + $this->assertArrayHasKey('post_id', $update_result); |
|
608 | + $this->assertArrayHasKey('previous_post_id', $update_result); |
|
609 | + $this->assertArrayHasKey('error', $update_result); |
|
610 | + $this->assertArrayHasKey('status', $update_result); |
|
611 | + |
|
612 | + $this->assertEquals($setting->post_id, $update_result['post_id']); |
|
613 | + $this->assertEquals($new_item_id, $update_result['previous_post_id']); |
|
614 | + $this->assertNull($update_result['error']); |
|
615 | + $this->assertEquals('inserted', $update_result['status']); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -621,48 +621,48 @@ discard block |
||
621 | 621 | * @see WP_Customize_Nav_Menu_Item_Setting::update() |
622 | 622 | */ |
623 | 623 | function test_save_deleted() { |
624 | - do_action( 'customize_register', $this->wp_customize ); |
|
624 | + do_action('customize_register', $this->wp_customize); |
|
625 | 625 | |
626 | - $menu_id = wp_create_nav_menu( 'Primary' ); |
|
627 | - $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
|
626 | + $menu_id = wp_create_nav_menu('Primary'); |
|
627 | + $post_id = $this->factory->post->create(array('post_title' => 'Hello World')); |
|
628 | 628 | $item_ids = array(); |
629 | - for ( $i = 0; $i < 5; $i += 1 ) { |
|
630 | - $item_id = wp_update_nav_menu_item( $menu_id, 0, array( |
|
629 | + for ($i = 0; $i < 5; $i += 1) { |
|
630 | + $item_id = wp_update_nav_menu_item($menu_id, 0, array( |
|
631 | 631 | 'menu-item-type' => 'post_type', |
632 | 632 | 'menu-item-object' => 'post', |
633 | 633 | 'menu-item-object-id' => $post_id, |
634 | 634 | 'menu-item-title' => "Item $i", |
635 | 635 | 'menu-item-status' => 'publish', |
636 | 636 | 'menu-item-position' => $i + 1, |
637 | - ) ); |
|
637 | + )); |
|
638 | 638 | $item_ids[] = $item_id; |
639 | 639 | } |
640 | 640 | |
641 | 641 | $delete_item_id = $item_ids[2]; |
642 | 642 | $setting_id = "nav_menu_item[$delete_item_id]"; |
643 | - $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); |
|
644 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
643 | + $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); |
|
644 | + $this->wp_customize->set_post_value($setting_id, false); |
|
645 | 645 | |
646 | - $current_items = wp_get_nav_menu_items( $menu_id ); |
|
647 | - $this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) ); |
|
646 | + $current_items = wp_get_nav_menu_items($menu_id); |
|
647 | + $this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id')); |
|
648 | 648 | $setting->save(); |
649 | - $preview_items = wp_get_nav_menu_items( $menu_id ); |
|
650 | - $this->assertNotEquals( count( $current_items ), count( $preview_items ) ); |
|
651 | - $this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) ); |
|
649 | + $preview_items = wp_get_nav_menu_items($menu_id); |
|
650 | + $this->assertNotEquals(count($current_items), count($preview_items)); |
|
651 | + $this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id')); |
|
652 | 652 | |
653 | 653 | // Verify the Ajax responses is being amended. |
654 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
655 | - $this->assertArrayHasKey( 'nav_menu_item_updates', $save_response ); |
|
656 | - $update_result = array_shift( $save_response['nav_menu_item_updates'] ); |
|
657 | - $this->assertArrayHasKey( 'post_id', $update_result ); |
|
658 | - $this->assertArrayHasKey( 'previous_post_id', $update_result ); |
|
659 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
660 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
661 | - |
|
662 | - $this->assertEquals( $delete_item_id, $update_result['post_id'] ); |
|
663 | - $this->assertNull( $update_result['previous_post_id'] ); |
|
664 | - $this->assertNull( $update_result['error'] ); |
|
665 | - $this->assertEquals( 'deleted', $update_result['status'] ); |
|
654 | + $save_response = apply_filters('customize_save_response', array()); |
|
655 | + $this->assertArrayHasKey('nav_menu_item_updates', $save_response); |
|
656 | + $update_result = array_shift($save_response['nav_menu_item_updates']); |
|
657 | + $this->assertArrayHasKey('post_id', $update_result); |
|
658 | + $this->assertArrayHasKey('previous_post_id', $update_result); |
|
659 | + $this->assertArrayHasKey('error', $update_result); |
|
660 | + $this->assertArrayHasKey('status', $update_result); |
|
661 | + |
|
662 | + $this->assertEquals($delete_item_id, $update_result['post_id']); |
|
663 | + $this->assertNull($update_result['previous_post_id']); |
|
664 | + $this->assertNull($update_result['error']); |
|
665 | + $this->assertEquals('deleted', $update_result['status']); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | } |