@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @since 4.4.0 |
480 | 480 | * @access public |
481 | 481 | * |
482 | - * @param array $params Parameter map of key to value. |
|
482 | + * @param string[] $params Parameter map of key to value. |
|
483 | 483 | */ |
484 | 484 | public function set_url_params( $params ) { |
485 | 485 | $this->params['URL'] = $params; |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * @since 4.4.0 |
782 | 782 | * @access public |
783 | 783 | * |
784 | - * @return true|null True if there are no parameters to sanitize, null otherwise. |
|
784 | + * @return boolean|null True if there are no parameters to sanitize, null otherwise. |
|
785 | 785 | */ |
786 | 786 | public function sanitize_params() { |
787 | 787 |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * REST API: WP_REST_Request class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage REST_API |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * REST API: WP_REST_Request class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage REST_API |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement a REST request object. |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string $route Optional. Request route. Default empty. |
120 | 120 | * @param array $attributes Optional. Request attributes. Default empty array. |
121 | 121 | */ |
122 | - public function __construct( $method = '', $route = '', $attributes = array() ) { |
|
122 | + public function __construct($method = '', $route = '', $attributes = array()) { |
|
123 | 123 | $this->params = array( |
124 | 124 | 'URL' => array(), |
125 | 125 | 'GET' => array(), |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | 'defaults' => array(), |
133 | 133 | ); |
134 | 134 | |
135 | - $this->set_method( $method ); |
|
136 | - $this->set_route( $route ); |
|
137 | - $this->set_attributes( $attributes ); |
|
135 | + $this->set_method($method); |
|
136 | + $this->set_route($route); |
|
137 | + $this->set_attributes($attributes); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param string $method HTTP method. |
159 | 159 | */ |
160 | - public function set_method( $method ) { |
|
161 | - $this->method = strtoupper( $method ); |
|
160 | + public function set_method($method) { |
|
161 | + $this->method = strtoupper($method); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | * @param string $key Header name. |
194 | 194 | * @return string Canonicalized name. |
195 | 195 | */ |
196 | - public static function canonicalize_header_name( $key ) { |
|
197 | - $key = strtolower( $key ); |
|
198 | - $key = str_replace( '-', '_', $key ); |
|
196 | + public static function canonicalize_header_name($key) { |
|
197 | + $key = strtolower($key); |
|
198 | + $key = str_replace('-', '_', $key); |
|
199 | 199 | |
200 | 200 | return $key; |
201 | 201 | } |
@@ -213,14 +213,14 @@ discard block |
||
213 | 213 | * @param string $key Header name, will be canonicalized to lowercase. |
214 | 214 | * @return string|null String value if set, null otherwise. |
215 | 215 | */ |
216 | - public function get_header( $key ) { |
|
217 | - $key = $this->canonicalize_header_name( $key ); |
|
216 | + public function get_header($key) { |
|
217 | + $key = $this->canonicalize_header_name($key); |
|
218 | 218 | |
219 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
219 | + if ( ! isset($this->headers[$key])) { |
|
220 | 220 | return null; |
221 | 221 | } |
222 | 222 | |
223 | - return implode( ',', $this->headers[ $key ] ); |
|
223 | + return implode(',', $this->headers[$key]); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | * @param string $key Header name, will be canonicalized to lowercase. |
233 | 233 | * @return array|null List of string values if set, null otherwise. |
234 | 234 | */ |
235 | - public function get_header_as_array( $key ) { |
|
236 | - $key = $this->canonicalize_header_name( $key ); |
|
235 | + public function get_header_as_array($key) { |
|
236 | + $key = $this->canonicalize_header_name($key); |
|
237 | 237 | |
238 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
238 | + if ( ! isset($this->headers[$key])) { |
|
239 | 239 | return null; |
240 | 240 | } |
241 | 241 | |
242 | - return $this->headers[ $key ]; |
|
242 | + return $this->headers[$key]; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | * @param string $key Header name. |
252 | 252 | * @param string $value Header value, or list of values. |
253 | 253 | */ |
254 | - public function set_header( $key, $value ) { |
|
255 | - $key = $this->canonicalize_header_name( $key ); |
|
254 | + public function set_header($key, $value) { |
|
255 | + $key = $this->canonicalize_header_name($key); |
|
256 | 256 | $value = (array) $value; |
257 | 257 | |
258 | - $this->headers[ $key ] = $value; |
|
258 | + $this->headers[$key] = $value; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | * @param string $key Header name. |
268 | 268 | * @param string $value Header value, or list of values. |
269 | 269 | */ |
270 | - public function add_header( $key, $value ) { |
|
271 | - $key = $this->canonicalize_header_name( $key ); |
|
270 | + public function add_header($key, $value) { |
|
271 | + $key = $this->canonicalize_header_name($key); |
|
272 | 272 | $value = (array) $value; |
273 | 273 | |
274 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
275 | - $this->headers[ $key ] = array(); |
|
274 | + if ( ! isset($this->headers[$key])) { |
|
275 | + $this->headers[$key] = array(); |
|
276 | 276 | } |
277 | 277 | |
278 | - $this->headers[ $key ] = array_merge( $this->headers[ $key ], $value ); |
|
278 | + $this->headers[$key] = array_merge($this->headers[$key], $value); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @param string $key Header name. |
288 | 288 | */ |
289 | - public function remove_header( $key ) { |
|
290 | - unset( $this->headers[ $key ] ); |
|
289 | + public function remove_header($key) { |
|
290 | + unset($this->headers[$key]); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | * @param array $headers Map of header name to value. |
300 | 300 | * @param bool $override If true, replace the request's headers. Otherwise, merge with existing. |
301 | 301 | */ |
302 | - public function set_headers( $headers, $override = true ) { |
|
303 | - if ( true === $override ) { |
|
302 | + public function set_headers($headers, $override = true) { |
|
303 | + if (true === $override) { |
|
304 | 304 | $this->headers = array(); |
305 | 305 | } |
306 | 306 | |
307 | - foreach ( $headers as $key => $value ) { |
|
308 | - $this->set_header( $key, $value ); |
|
307 | + foreach ($headers as $key => $value) { |
|
308 | + $this->set_header($key, $value); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
@@ -318,26 +318,26 @@ discard block |
||
318 | 318 | * @return array Map containing 'value' and 'parameters' keys. |
319 | 319 | */ |
320 | 320 | public function get_content_type() { |
321 | - $value = $this->get_header( 'content-type' ); |
|
322 | - if ( empty( $value ) ) { |
|
321 | + $value = $this->get_header('content-type'); |
|
322 | + if (empty($value)) { |
|
323 | 323 | return null; |
324 | 324 | } |
325 | 325 | |
326 | 326 | $parameters = ''; |
327 | - if ( strpos( $value, ';' ) ) { |
|
328 | - list( $value, $parameters ) = explode( ';', $value, 2 ); |
|
327 | + if (strpos($value, ';')) { |
|
328 | + list($value, $parameters) = explode(';', $value, 2); |
|
329 | 329 | } |
330 | 330 | |
331 | - $value = strtolower( $value ); |
|
332 | - if ( strpos( $value, '/' ) === false ) { |
|
331 | + $value = strtolower($value); |
|
332 | + if (strpos($value, '/') === false) { |
|
333 | 333 | return null; |
334 | 334 | } |
335 | 335 | |
336 | 336 | // Parse type and subtype out. |
337 | - list( $type, $subtype ) = explode( '/', $value, 2 ); |
|
337 | + list($type, $subtype) = explode('/', $value, 2); |
|
338 | 338 | |
339 | - $data = compact( 'value', 'type', 'subtype', 'parameters' ); |
|
340 | - $data = array_map( 'trim', $data ); |
|
339 | + $data = compact('value', 'type', 'subtype', 'parameters'); |
|
340 | + $data = array_map('trim', $data); |
|
341 | 341 | |
342 | 342 | return $data; |
343 | 343 | } |
@@ -360,12 +360,12 @@ discard block |
||
360 | 360 | |
361 | 361 | // Ensure we parse the body data. |
362 | 362 | $body = $this->get_body(); |
363 | - if ( $this->method !== 'POST' && ! empty( $body ) ) { |
|
363 | + if ($this->method !== 'POST' && ! empty($body)) { |
|
364 | 364 | $this->parse_body_params(); |
365 | 365 | } |
366 | 366 | |
367 | - $accepts_body_data = array( 'POST', 'PUT', 'PATCH' ); |
|
368 | - if ( in_array( $this->method, $accepts_body_data ) ) { |
|
367 | + $accepts_body_data = array('POST', 'PUT', 'PATCH'); |
|
368 | + if (in_array($this->method, $accepts_body_data)) { |
|
369 | 369 | $order[] = 'POST'; |
370 | 370 | } |
371 | 371 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * } |
389 | 389 | * @param WP_REST_Request $this The request object. |
390 | 390 | */ |
391 | - return apply_filters( 'rest_request_parameter_order', $order, $this ); |
|
391 | + return apply_filters('rest_request_parameter_order', $order, $this); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | * @param string $key Parameter name. |
401 | 401 | * @return mixed|null Value if set, null otherwise. |
402 | 402 | */ |
403 | - public function get_param( $key ) { |
|
403 | + public function get_param($key) { |
|
404 | 404 | $order = $this->get_parameter_order(); |
405 | 405 | |
406 | - foreach ( $order as $type ) { |
|
406 | + foreach ($order as $type) { |
|
407 | 407 | // Determine if we have the parameter for this type. |
408 | - if ( isset( $this->params[ $type ][ $key ] ) ) { |
|
409 | - return $this->params[ $type ][ $key ]; |
|
408 | + if (isset($this->params[$type][$key])) { |
|
409 | + return $this->params[$type][$key]; |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -422,14 +422,14 @@ discard block |
||
422 | 422 | * @param string $key Parameter name. |
423 | 423 | * @param mixed $value Parameter value. |
424 | 424 | */ |
425 | - public function set_param( $key, $value ) { |
|
426 | - switch ( $this->method ) { |
|
425 | + public function set_param($key, $value) { |
|
426 | + switch ($this->method) { |
|
427 | 427 | case 'POST': |
428 | - $this->params['POST'][ $key ] = $value; |
|
428 | + $this->params['POST'][$key] = $value; |
|
429 | 429 | break; |
430 | 430 | |
431 | 431 | default: |
432 | - $this->params['GET'][ $key ] = $value; |
|
432 | + $this->params['GET'][$key] = $value; |
|
433 | 433 | break; |
434 | 434 | } |
435 | 435 | } |
@@ -447,11 +447,11 @@ discard block |
||
447 | 447 | */ |
448 | 448 | public function get_params() { |
449 | 449 | $order = $this->get_parameter_order(); |
450 | - $order = array_reverse( $order, true ); |
|
450 | + $order = array_reverse($order, true); |
|
451 | 451 | |
452 | 452 | $params = array(); |
453 | - foreach ( $order as $type ) { |
|
454 | - $params = array_merge( $params, (array) $this->params[ $type ] ); |
|
453 | + foreach ($order as $type) { |
|
454 | + $params = array_merge($params, (array) $this->params[$type]); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | return $params; |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @param array $params Parameter map of key to value. |
483 | 483 | */ |
484 | - public function set_url_params( $params ) { |
|
484 | + public function set_url_params($params) { |
|
485 | 485 | $this->params['URL'] = $params; |
486 | 486 | } |
487 | 487 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * |
510 | 510 | * @param array $params Parameter map of key to value. |
511 | 511 | */ |
512 | - public function set_query_params( $params ) { |
|
512 | + public function set_query_params($params) { |
|
513 | 513 | $this->params['GET'] = $params; |
514 | 514 | } |
515 | 515 | |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * |
538 | 538 | * @param array $params Parameter map of key to value. |
539 | 539 | */ |
540 | - public function set_body_params( $params ) { |
|
540 | + public function set_body_params($params) { |
|
541 | 541 | $this->params['POST'] = $params; |
542 | 542 | } |
543 | 543 | |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * |
566 | 566 | * @param array $params Parameter map of key to value. |
567 | 567 | */ |
568 | - public function set_file_params( $params ) { |
|
568 | + public function set_file_params($params) { |
|
569 | 569 | $this->params['FILES'] = $params; |
570 | 570 | } |
571 | 571 | |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * |
594 | 594 | * @param array $params Parameter map of key to value. |
595 | 595 | */ |
596 | - public function set_default_params( $params ) { |
|
596 | + public function set_default_params($params) { |
|
597 | 597 | $this->params['defaults'] = $params; |
598 | 598 | } |
599 | 599 | |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * |
618 | 618 | * @param string $data Binary data from the request body. |
619 | 619 | */ |
620 | - public function set_body( $data ) { |
|
620 | + public function set_body($data) { |
|
621 | 621 | $this->body = $data; |
622 | 622 | |
623 | 623 | // Enable lazy parsing. |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @access protected |
651 | 651 | */ |
652 | 652 | protected function parse_json_params() { |
653 | - if ( $this->parsed_json ) { |
|
653 | + if ($this->parsed_json) { |
|
654 | 654 | return; |
655 | 655 | } |
656 | 656 | |
@@ -659,11 +659,11 @@ discard block |
||
659 | 659 | // Check that we actually got JSON. |
660 | 660 | $content_type = $this->get_content_type(); |
661 | 661 | |
662 | - if ( empty( $content_type ) || 'application/json' !== $content_type['value'] ) { |
|
662 | + if (empty($content_type) || 'application/json' !== $content_type['value']) { |
|
663 | 663 | return; |
664 | 664 | } |
665 | 665 | |
666 | - $params = json_decode( $this->get_body(), true ); |
|
666 | + $params = json_decode($this->get_body(), true); |
|
667 | 667 | |
668 | 668 | /* |
669 | 669 | * Check for a parsing error. |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | * Note that due to WP's JSON compatibility functions, json_last_error |
672 | 672 | * might not be defined: https://core.trac.wordpress.org/ticket/27799 |
673 | 673 | */ |
674 | - if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error() ) ) { |
|
674 | + if (null === $params && ( ! function_exists('json_last_error') || JSON_ERROR_NONE !== json_last_error())) { |
|
675 | 675 | return; |
676 | 676 | } |
677 | 677 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * @access protected |
689 | 689 | */ |
690 | 690 | protected function parse_body_params() { |
691 | - if ( $this->parsed_body ) { |
|
691 | + if ($this->parsed_body) { |
|
692 | 692 | return; |
693 | 693 | } |
694 | 694 | |
@@ -700,26 +700,26 @@ discard block |
||
700 | 700 | */ |
701 | 701 | $content_type = $this->get_content_type(); |
702 | 702 | |
703 | - if ( ! empty( $content_type ) && 'application/x-www-form-urlencoded' !== $content_type['value'] ) { |
|
703 | + if ( ! empty($content_type) && 'application/x-www-form-urlencoded' !== $content_type['value']) { |
|
704 | 704 | return; |
705 | 705 | } |
706 | 706 | |
707 | - parse_str( $this->get_body(), $params ); |
|
707 | + parse_str($this->get_body(), $params); |
|
708 | 708 | |
709 | 709 | /* |
710 | 710 | * Amazingly, parse_str follows magic quote rules. Sigh. |
711 | 711 | * |
712 | 712 | * NOTE: Do not refactor to use `wp_unslash`. |
713 | 713 | */ |
714 | - if ( get_magic_quotes_gpc() ) { |
|
715 | - $params = stripslashes_deep( $params ); |
|
714 | + if (get_magic_quotes_gpc()) { |
|
715 | + $params = stripslashes_deep($params); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /* |
719 | 719 | * Add to the POST parameters stored internally. If a user has already |
720 | 720 | * set these manually (via `set_body_params`), don't override them. |
721 | 721 | */ |
722 | - $this->params['POST'] = array_merge( $params, $this->params['POST'] ); |
|
722 | + $this->params['POST'] = array_merge($params, $this->params['POST']); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | * |
743 | 743 | * @param string $route Route matching regex. |
744 | 744 | */ |
745 | - public function set_route( $route ) { |
|
745 | + public function set_route($route) { |
|
746 | 746 | $this->route = $route; |
747 | 747 | } |
748 | 748 | |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * |
769 | 769 | * @param array $attributes Attributes for the request. |
770 | 770 | */ |
771 | - public function set_attributes( $attributes ) { |
|
771 | + public function set_attributes($attributes) { |
|
772 | 772 | $this->attributes = $attributes; |
773 | 773 | } |
774 | 774 | |
@@ -788,20 +788,20 @@ discard block |
||
788 | 788 | $attributes = $this->get_attributes(); |
789 | 789 | |
790 | 790 | // No arguments set, skip sanitizing. |
791 | - if ( empty( $attributes['args'] ) ) { |
|
791 | + if (empty($attributes['args'])) { |
|
792 | 792 | return true; |
793 | 793 | } |
794 | 794 | |
795 | 795 | $order = $this->get_parameter_order(); |
796 | 796 | |
797 | - foreach ( $order as $type ) { |
|
798 | - if ( empty( $this->params[ $type ] ) ) { |
|
797 | + foreach ($order as $type) { |
|
798 | + if (empty($this->params[$type])) { |
|
799 | 799 | continue; |
800 | 800 | } |
801 | - foreach ( $this->params[ $type ] as $key => $value ) { |
|
801 | + foreach ($this->params[$type] as $key => $value) { |
|
802 | 802 | // Check if this param has a sanitize_callback added. |
803 | - if ( isset( $attributes['args'][ $key ] ) && ! empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) { |
|
804 | - $this->params[ $type ][ $key ] = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key ); |
|
803 | + if (isset($attributes['args'][$key]) && ! empty($attributes['args'][$key]['sanitize_callback'])) { |
|
804 | + $this->params[$type][$key] = call_user_func($attributes['args'][$key]['sanitize_callback'], $value, $this, $key); |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | } |
@@ -823,20 +823,20 @@ discard block |
||
823 | 823 | $required = array(); |
824 | 824 | |
825 | 825 | // No arguments set, skip validation. |
826 | - if ( empty( $attributes['args'] ) ) { |
|
826 | + if (empty($attributes['args'])) { |
|
827 | 827 | return true; |
828 | 828 | } |
829 | 829 | |
830 | - foreach ( $attributes['args'] as $key => $arg ) { |
|
830 | + foreach ($attributes['args'] as $key => $arg) { |
|
831 | 831 | |
832 | - $param = $this->get_param( $key ); |
|
833 | - if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) { |
|
832 | + $param = $this->get_param($key); |
|
833 | + if (isset($arg['required']) && true === $arg['required'] && null === $param) { |
|
834 | 834 | $required[] = $key; |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | - if ( ! empty( $required ) ) { |
|
839 | - return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
|
838 | + if ( ! empty($required)) { |
|
839 | + return new WP_Error('rest_missing_callback_param', sprintf(__('Missing parameter(s): %s'), implode(', ', $required)), array('status' => 400, 'params' => $required)); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /* |
@@ -846,25 +846,25 @@ discard block |
||
846 | 846 | */ |
847 | 847 | $invalid_params = array(); |
848 | 848 | |
849 | - foreach ( $attributes['args'] as $key => $arg ) { |
|
849 | + foreach ($attributes['args'] as $key => $arg) { |
|
850 | 850 | |
851 | - $param = $this->get_param( $key ); |
|
851 | + $param = $this->get_param($key); |
|
852 | 852 | |
853 | - if ( null !== $param && ! empty( $arg['validate_callback'] ) ) { |
|
854 | - $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
|
853 | + if (null !== $param && ! empty($arg['validate_callback'])) { |
|
854 | + $valid_check = call_user_func($arg['validate_callback'], $param, $this, $key); |
|
855 | 855 | |
856 | - if ( false === $valid_check ) { |
|
857 | - $invalid_params[ $key ] = __( 'Invalid parameter.' ); |
|
856 | + if (false === $valid_check) { |
|
857 | + $invalid_params[$key] = __('Invalid parameter.'); |
|
858 | 858 | } |
859 | 859 | |
860 | - if ( is_wp_error( $valid_check ) ) { |
|
861 | - $invalid_params[ $key ] = $valid_check->get_error_message(); |
|
860 | + if (is_wp_error($valid_check)) { |
|
861 | + $invalid_params[$key] = $valid_check->get_error_message(); |
|
862 | 862 | } |
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
866 | - if ( $invalid_params ) { |
|
867 | - return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
|
866 | + if ($invalid_params) { |
|
867 | + return new WP_Error('rest_invalid_param', sprintf(__('Invalid parameter(s): %s'), implode(', ', array_keys($invalid_params))), array('status' => 400, 'params' => $invalid_params)); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | return true; |
@@ -880,11 +880,11 @@ discard block |
||
880 | 880 | * @param string $offset Parameter name. |
881 | 881 | * @return bool Whether the parameter is set. |
882 | 882 | */ |
883 | - public function offsetExists( $offset ) { |
|
883 | + public function offsetExists($offset) { |
|
884 | 884 | $order = $this->get_parameter_order(); |
885 | 885 | |
886 | - foreach ( $order as $type ) { |
|
887 | - if ( isset( $this->params[ $type ][ $offset ] ) ) { |
|
886 | + foreach ($order as $type) { |
|
887 | + if (isset($this->params[$type][$offset])) { |
|
888 | 888 | return true; |
889 | 889 | } |
890 | 890 | } |
@@ -901,8 +901,8 @@ discard block |
||
901 | 901 | * @param string $offset Parameter name. |
902 | 902 | * @return mixed|null Value if set, null otherwise. |
903 | 903 | */ |
904 | - public function offsetGet( $offset ) { |
|
905 | - return $this->get_param( $offset ); |
|
904 | + public function offsetGet($offset) { |
|
905 | + return $this->get_param($offset); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | /** |
@@ -914,8 +914,8 @@ discard block |
||
914 | 914 | * @param string $offset Parameter name. |
915 | 915 | * @param mixed $value Parameter value. |
916 | 916 | */ |
917 | - public function offsetSet( $offset, $value ) { |
|
918 | - $this->set_param( $offset, $value ); |
|
917 | + public function offsetSet($offset, $value) { |
|
918 | + $this->set_param($offset, $value); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
@@ -926,12 +926,12 @@ discard block |
||
926 | 926 | * |
927 | 927 | * @param string $offset Parameter name. |
928 | 928 | */ |
929 | - public function offsetUnset( $offset ) { |
|
929 | + public function offsetUnset($offset) { |
|
930 | 930 | $order = $this->get_parameter_order(); |
931 | 931 | |
932 | 932 | // Remove the offset from every group. |
933 | - foreach ( $order as $type ) { |
|
934 | - unset( $this->params[ $type ][ $offset ] ); |
|
933 | + foreach ($order as $type) { |
|
934 | + unset($this->params[$type][$offset]); |
|
935 | 935 | } |
936 | 936 | } |
937 | 937 | |
@@ -945,29 +945,29 @@ discard block |
||
945 | 945 | * @param string $url URL with protocol, domain, path and query args. |
946 | 946 | * @return WP_REST_Request|false WP_REST_Request object on success, false on failure. |
947 | 947 | */ |
948 | - public static function from_url( $url ) { |
|
949 | - $bits = parse_url( $url ); |
|
948 | + public static function from_url($url) { |
|
949 | + $bits = parse_url($url); |
|
950 | 950 | $query_params = array(); |
951 | 951 | |
952 | - if ( ! empty( $bits['query'] ) ) { |
|
953 | - wp_parse_str( $bits['query'], $query_params ); |
|
952 | + if ( ! empty($bits['query'])) { |
|
953 | + wp_parse_str($bits['query'], $query_params); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | $api_root = rest_url(); |
957 | - if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) { |
|
957 | + if (get_option('permalink_structure') && 0 === strpos($url, $api_root)) { |
|
958 | 958 | // Pretty permalinks on, and URL is under the API root |
959 | - $api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) ); |
|
960 | - $route = parse_url( $api_url_part, PHP_URL_PATH ); |
|
961 | - } elseif ( ! empty( $query_params['rest_route'] ) ) { |
|
959 | + $api_url_part = substr($url, strlen(untrailingslashit($api_root))); |
|
960 | + $route = parse_url($api_url_part, PHP_URL_PATH); |
|
961 | + } elseif ( ! empty($query_params['rest_route'])) { |
|
962 | 962 | // ?rest_route=... set directly |
963 | 963 | $route = $query_params['rest_route']; |
964 | - unset( $query_params['rest_route'] ); |
|
964 | + unset($query_params['rest_route']); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | $request = false; |
968 | - if ( ! empty( $route ) ) { |
|
969 | - $request = new WP_REST_Request( 'GET', $route ); |
|
970 | - $request->set_query_params( $query_params ); |
|
968 | + if ( ! empty($route)) { |
|
969 | + $request = new WP_REST_Request('GET', $route); |
|
970 | + $request->set_query_params($query_params); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
@@ -979,6 +979,6 @@ discard block |
||
979 | 979 | * could not be parsed. |
980 | 980 | * @param string $url URL the request was generated from. |
981 | 981 | */ |
982 | - return apply_filters( 'rest_request_from_url', $request, $url ); |
|
982 | + return apply_filters('rest_request_from_url', $request, $url); |
|
983 | 983 | } |
984 | 984 | } |
@@ -907,7 +907,7 @@ |
||
907 | 907 | * @since 4.4.0 |
908 | 908 | * @access protected |
909 | 909 | * |
910 | - * @return bool|string Boolean false or string error message. |
|
910 | + * @return false|string Boolean false or string error message. |
|
911 | 911 | */ |
912 | 912 | protected function get_json_last_error() { |
913 | 913 | // See https://core.trac.wordpress.org/ticket/27799. |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * REST API: WP_REST_Server class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage REST_API |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * REST API: WP_REST_Server class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage REST_API |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement the WordPress REST API server. |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $this->endpoints = array( |
92 | 92 | // Meta endpoints. |
93 | 93 | '/' => array( |
94 | - 'callback' => array( $this, 'get_index' ), |
|
94 | + 'callback' => array($this, 'get_index'), |
|
95 | 95 | 'methods' => 'GET', |
96 | 96 | 'args' => array( |
97 | 97 | 'context' => array( |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param WP_Error|null|bool WP_Error if authentication error, null if authentication |
138 | 138 | * method wasn't used, true if authentication succeeded. |
139 | 139 | */ |
140 | - return apply_filters( 'rest_authentication_errors', null ); |
|
140 | + return apply_filters('rest_authentication_errors', null); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | * @param WP_Error $error WP_Error instance. |
154 | 154 | * @return WP_REST_Response List of associative arrays with code and message keys. |
155 | 155 | */ |
156 | - protected function error_to_response( $error ) { |
|
156 | + protected function error_to_response($error) { |
|
157 | 157 | $error_data = $error->get_error_data(); |
158 | 158 | |
159 | - if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { |
|
159 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
160 | 160 | $status = $error_data['status']; |
161 | 161 | } else { |
162 | 162 | $status = 500; |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | |
165 | 165 | $errors = array(); |
166 | 166 | |
167 | - foreach ( (array) $error->errors as $code => $messages ) { |
|
168 | - foreach ( (array) $messages as $message ) { |
|
169 | - $errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) ); |
|
167 | + foreach ((array) $error->errors as $code => $messages) { |
|
168 | + foreach ((array) $messages as $message) { |
|
169 | + $errors[] = array('code' => $code, 'message' => $message, 'data' => $error->get_error_data($code)); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | 173 | $data = $errors[0]; |
174 | - if ( count( $errors ) > 1 ) { |
|
174 | + if (count($errors) > 1) { |
|
175 | 175 | // Remove the primary error. |
176 | - array_shift( $errors ); |
|
176 | + array_shift($errors); |
|
177 | 177 | $data['additional_errors'] = $errors; |
178 | 178 | } |
179 | 179 | |
180 | - $response = new WP_REST_Response( $data, $status ); |
|
180 | + $response = new WP_REST_Response($data, $status); |
|
181 | 181 | |
182 | 182 | return $response; |
183 | 183 | } |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | * @param int $status Optional. HTTP status code to send. Default null. |
199 | 199 | * @return string JSON representation of the error |
200 | 200 | */ |
201 | - protected function json_error( $code, $message, $status = null ) { |
|
202 | - if ( $status ) { |
|
203 | - $this->set_status( $status ); |
|
201 | + protected function json_error($code, $message, $status = null) { |
|
202 | + if ($status) { |
|
203 | + $this->set_status($status); |
|
204 | 204 | } |
205 | 205 | |
206 | - $error = compact( 'code', 'message' ); |
|
206 | + $error = compact('code', 'message'); |
|
207 | 207 | |
208 | - return wp_json_encode( $error ); |
|
208 | + return wp_json_encode($error); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -223,18 +223,18 @@ discard block |
||
223 | 223 | * Default null. |
224 | 224 | * @return false|null Null if not served and a HEAD request, false otherwise. |
225 | 225 | */ |
226 | - public function serve_request( $path = null ) { |
|
227 | - $content_type = isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json'; |
|
228 | - $this->send_header( 'Content-Type', $content_type . '; charset=' . get_option( 'blog_charset' ) ); |
|
226 | + public function serve_request($path = null) { |
|
227 | + $content_type = isset($_GET['_jsonp']) ? 'application/javascript' : 'application/json'; |
|
228 | + $this->send_header('Content-Type', $content_type.'; charset='.get_option('blog_charset')); |
|
229 | 229 | |
230 | 230 | /* |
231 | 231 | * Mitigate possible JSONP Flash attacks. |
232 | 232 | * |
233 | 233 | * http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ |
234 | 234 | */ |
235 | - $this->send_header( 'X-Content-Type-Options', 'nosniff' ); |
|
236 | - $this->send_header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages' ); |
|
237 | - $this->send_header( 'Access-Control-Allow-Headers', 'Authorization' ); |
|
235 | + $this->send_header('X-Content-Type-Options', 'nosniff'); |
|
236 | + $this->send_header('Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages'); |
|
237 | + $this->send_header('Access-Control-Allow-Headers', 'Authorization'); |
|
238 | 238 | |
239 | 239 | /** |
240 | 240 | * Send nocache headers on authenticated requests. |
@@ -243,10 +243,10 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @param bool $rest_send_nocache_headers Whether to send no-cache headers. |
245 | 245 | */ |
246 | - $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() ); |
|
247 | - if ( $send_no_cache_headers ) { |
|
248 | - foreach ( wp_get_nocache_headers() as $header => $header_value ) { |
|
249 | - $this->send_header( $header, $header_value ); |
|
246 | + $send_no_cache_headers = apply_filters('rest_send_nocache_headers', is_user_logged_in()); |
|
247 | + if ($send_no_cache_headers) { |
|
248 | + foreach (wp_get_nocache_headers() as $header => $header_value) { |
|
249 | + $this->send_header($header, $header_value); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @param bool $rest_enabled Whether the REST API is enabled. Default true. |
259 | 259 | */ |
260 | - $enabled = apply_filters( 'rest_enabled', true ); |
|
260 | + $enabled = apply_filters('rest_enabled', true); |
|
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Filter whether jsonp is enabled. |
@@ -266,72 +266,72 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @param bool $jsonp_enabled Whether jsonp is enabled. Default true. |
268 | 268 | */ |
269 | - $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
|
269 | + $jsonp_enabled = apply_filters('rest_jsonp_enabled', true); |
|
270 | 270 | |
271 | 271 | $jsonp_callback = null; |
272 | 272 | |
273 | - if ( ! $enabled ) { |
|
274 | - echo $this->json_error( 'rest_disabled', __( 'The REST API is disabled on this site.' ), 404 ); |
|
273 | + if ( ! $enabled) { |
|
274 | + echo $this->json_error('rest_disabled', __('The REST API is disabled on this site.'), 404); |
|
275 | 275 | return false; |
276 | 276 | } |
277 | - if ( isset( $_GET['_jsonp'] ) ) { |
|
278 | - if ( ! $jsonp_enabled ) { |
|
279 | - echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 ); |
|
277 | + if (isset($_GET['_jsonp'])) { |
|
278 | + if ( ! $jsonp_enabled) { |
|
279 | + echo $this->json_error('rest_callback_disabled', __('JSONP support is disabled on this site.'), 400); |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | // Check for invalid characters (only alphanumeric allowed). |
284 | - if ( is_string( $_GET['_jsonp'] ) ) { |
|
285 | - $jsonp_callback = preg_replace( '/[^\w\.]/', '', wp_unslash( $_GET['_jsonp'] ), -1, $illegal_char_count ); |
|
286 | - if ( 0 !== $illegal_char_count ) { |
|
284 | + if (is_string($_GET['_jsonp'])) { |
|
285 | + $jsonp_callback = preg_replace('/[^\w\.]/', '', wp_unslash($_GET['_jsonp']), -1, $illegal_char_count); |
|
286 | + if (0 !== $illegal_char_count) { |
|
287 | 287 | $jsonp_callback = null; |
288 | 288 | } |
289 | 289 | } |
290 | - if ( null === $jsonp_callback ) { |
|
291 | - echo $this->json_error( 'rest_callback_invalid', __( 'The JSONP callback function is invalid.' ), 400 ); |
|
290 | + if (null === $jsonp_callback) { |
|
291 | + echo $this->json_error('rest_callback_invalid', __('The JSONP callback function is invalid.'), 400); |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - if ( empty( $path ) ) { |
|
297 | - if ( isset( $_SERVER['PATH_INFO'] ) ) { |
|
296 | + if (empty($path)) { |
|
297 | + if (isset($_SERVER['PATH_INFO'])) { |
|
298 | 298 | $path = $_SERVER['PATH_INFO']; |
299 | 299 | } else { |
300 | 300 | $path = '/'; |
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $path ); |
|
304 | + $request = new WP_REST_Request($_SERVER['REQUEST_METHOD'], $path); |
|
305 | 305 | |
306 | - $request->set_query_params( $_GET ); |
|
307 | - $request->set_body_params( $_POST ); |
|
308 | - $request->set_file_params( $_FILES ); |
|
309 | - $request->set_headers( $this->get_headers( $_SERVER ) ); |
|
310 | - $request->set_body( $this->get_raw_data() ); |
|
306 | + $request->set_query_params($_GET); |
|
307 | + $request->set_body_params($_POST); |
|
308 | + $request->set_file_params($_FILES); |
|
309 | + $request->set_headers($this->get_headers($_SERVER)); |
|
310 | + $request->set_body($this->get_raw_data()); |
|
311 | 311 | |
312 | 312 | /* |
313 | 313 | * HTTP method override for clients that can't use PUT/PATCH/DELETE. First, we check |
314 | 314 | * $_GET['_method']. If that is not set, we check for the HTTP_X_HTTP_METHOD_OVERRIDE |
315 | 315 | * header. |
316 | 316 | */ |
317 | - if ( isset( $_GET['_method'] ) ) { |
|
318 | - $request->set_method( $_GET['_method'] ); |
|
319 | - } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) { |
|
320 | - $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ); |
|
317 | + if (isset($_GET['_method'])) { |
|
318 | + $request->set_method($_GET['_method']); |
|
319 | + } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
320 | + $request->set_method($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | $result = $this->check_authentication(); |
324 | 324 | |
325 | - if ( ! is_wp_error( $result ) ) { |
|
326 | - $result = $this->dispatch( $request ); |
|
325 | + if ( ! is_wp_error($result)) { |
|
326 | + $result = $this->dispatch($request); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Normalize to either WP_Error or WP_REST_Response... |
330 | - $result = rest_ensure_response( $result ); |
|
330 | + $result = rest_ensure_response($result); |
|
331 | 331 | |
332 | 332 | // ...then convert WP_Error across. |
333 | - if ( is_wp_error( $result ) ) { |
|
334 | - $result = $this->error_to_response( $result ); |
|
333 | + if (is_wp_error($result)) { |
|
334 | + $result = $this->error_to_response($result); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -346,19 +346,19 @@ discard block |
||
346 | 346 | * @param WP_REST_Server $this Server instance. |
347 | 347 | * @param WP_REST_Request $request Request used to generate the response. |
348 | 348 | */ |
349 | - $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request ); |
|
349 | + $result = apply_filters('rest_post_dispatch', rest_ensure_response($result), $this, $request); |
|
350 | 350 | |
351 | 351 | // Wrap the response in an envelope if asked for. |
352 | - if ( isset( $_GET['_envelope'] ) ) { |
|
353 | - $result = $this->envelope_response( $result, isset( $_GET['_embed'] ) ); |
|
352 | + if (isset($_GET['_envelope'])) { |
|
353 | + $result = $this->envelope_response($result, isset($_GET['_embed'])); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Send extra data from response objects. |
357 | 357 | $headers = $result->get_headers(); |
358 | - $this->send_headers( $headers ); |
|
358 | + $this->send_headers($headers); |
|
359 | 359 | |
360 | 360 | $code = $result->get_status(); |
361 | - $this->set_status( $code ); |
|
361 | + $this->set_status($code); |
|
362 | 362 | |
363 | 363 | /** |
364 | 364 | * Filter whether the request has already been served. |
@@ -374,29 +374,29 @@ discard block |
||
374 | 374 | * @param WP_REST_Request $request Request used to generate the response. |
375 | 375 | * @param WP_REST_Server $this Server instance. |
376 | 376 | */ |
377 | - $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this ); |
|
377 | + $served = apply_filters('rest_pre_serve_request', false, $result, $request, $this); |
|
378 | 378 | |
379 | - if ( ! $served ) { |
|
380 | - if ( 'HEAD' === $request->get_method() ) { |
|
379 | + if ( ! $served) { |
|
380 | + if ('HEAD' === $request->get_method()) { |
|
381 | 381 | return null; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // Embed links inside the request. |
385 | - $result = $this->response_to_data( $result, isset( $_GET['_embed'] ) ); |
|
385 | + $result = $this->response_to_data($result, isset($_GET['_embed'])); |
|
386 | 386 | |
387 | - $result = wp_json_encode( $result ); |
|
387 | + $result = wp_json_encode($result); |
|
388 | 388 | |
389 | 389 | $json_error_message = $this->get_json_last_error(); |
390 | - if ( $json_error_message ) { |
|
391 | - $json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) ); |
|
392 | - $result = $this->error_to_response( $json_error_obj ); |
|
393 | - $result = wp_json_encode( $result->data[0] ); |
|
390 | + if ($json_error_message) { |
|
391 | + $json_error_obj = new WP_Error('rest_encode_error', $json_error_message, array('status' => 500)); |
|
392 | + $result = $this->error_to_response($json_error_obj); |
|
393 | + $result = wp_json_encode($result->data[0]); |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( $jsonp_callback ) { |
|
396 | + if ($jsonp_callback) { |
|
397 | 397 | // Prepend '/**/' to mitigate possible JSONP Flash attacks |
398 | 398 | // http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ |
399 | - echo '/**/' . $jsonp_callback . '(' . $result . ')'; |
|
399 | + echo '/**/'.$jsonp_callback.'('.$result.')'; |
|
400 | 400 | } else { |
401 | 401 | echo $result; |
402 | 402 | } |
@@ -419,20 +419,20 @@ discard block |
||
419 | 419 | * @type array [$_embedded] Embeddeds. |
420 | 420 | * } |
421 | 421 | */ |
422 | - public function response_to_data( $response, $embed ) { |
|
422 | + public function response_to_data($response, $embed) { |
|
423 | 423 | $data = $response->get_data(); |
424 | - $links = $this->get_response_links( $response ); |
|
424 | + $links = $this->get_response_links($response); |
|
425 | 425 | |
426 | - if ( ! empty( $links ) ) { |
|
426 | + if ( ! empty($links)) { |
|
427 | 427 | // Convert links to part of the data. |
428 | 428 | $data['_links'] = $links; |
429 | 429 | } |
430 | - if ( $embed ) { |
|
430 | + if ($embed) { |
|
431 | 431 | // Determine if this is a numeric array. |
432 | - if ( wp_is_numeric_array( $data ) ) { |
|
433 | - $data = array_map( array( $this, 'embed_links' ), $data ); |
|
432 | + if (wp_is_numeric_array($data)) { |
|
433 | + $data = array_map(array($this, 'embed_links'), $data); |
|
434 | 434 | } else { |
435 | - $data = $this->embed_links( $data ); |
|
435 | + $data = $this->embed_links($data); |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | |
@@ -452,10 +452,10 @@ discard block |
||
452 | 452 | * @param WP_REST_Response $response Response to extract links from. |
453 | 453 | * @return array Map of link relation to list of link hashes. |
454 | 454 | */ |
455 | - public static function get_response_links( $response ) { |
|
455 | + public static function get_response_links($response) { |
|
456 | 456 | $links = $response->get_links(); |
457 | 457 | |
458 | - if ( empty( $links ) ) { |
|
458 | + if (empty($links)) { |
|
459 | 459 | return array(); |
460 | 460 | } |
461 | 461 | |
@@ -464,37 +464,37 @@ discard block |
||
464 | 464 | $curies = $response->get_curies(); |
465 | 465 | $used_curies = array(); |
466 | 466 | |
467 | - foreach ( $links as $rel => $items ) { |
|
467 | + foreach ($links as $rel => $items) { |
|
468 | 468 | |
469 | 469 | // Convert $rel URIs to their compact versions if they exist. |
470 | - foreach ( $curies as $curie ) { |
|
471 | - $href_prefix = substr( $curie['href'], 0, strpos( $curie['href'], '{rel}' ) ); |
|
472 | - if ( strpos( $rel, $href_prefix ) !== 0 ) { |
|
470 | + foreach ($curies as $curie) { |
|
471 | + $href_prefix = substr($curie['href'], 0, strpos($curie['href'], '{rel}')); |
|
472 | + if (strpos($rel, $href_prefix) !== 0) { |
|
473 | 473 | continue; |
474 | 474 | } |
475 | - $used_curies[ $curie['name'] ] = $curie; |
|
475 | + $used_curies[$curie['name']] = $curie; |
|
476 | 476 | |
477 | 477 | // Relation now changes from '$uri' to '$curie:$relation' |
478 | - $rel_regex = str_replace( '\{rel\}', '([\w]+)', preg_quote( $curie['href'], '!' ) ); |
|
479 | - preg_match( '!' . $rel_regex . '!', $rel, $matches ); |
|
480 | - if ( $matches ) { |
|
481 | - $rel = $curie['name'] . ':' . $matches[1]; |
|
478 | + $rel_regex = str_replace('\{rel\}', '([\w]+)', preg_quote($curie['href'], '!')); |
|
479 | + preg_match('!'.$rel_regex.'!', $rel, $matches); |
|
480 | + if ($matches) { |
|
481 | + $rel = $curie['name'].':'.$matches[1]; |
|
482 | 482 | } |
483 | 483 | break; |
484 | 484 | } |
485 | 485 | |
486 | - $data[ $rel ] = array(); |
|
486 | + $data[$rel] = array(); |
|
487 | 487 | |
488 | - foreach ( $items as $item ) { |
|
488 | + foreach ($items as $item) { |
|
489 | 489 | $attributes = $item['attributes']; |
490 | 490 | $attributes['href'] = $item['href']; |
491 | - $data[ $rel ][] = $attributes; |
|
491 | + $data[$rel][] = $attributes; |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Push the curies onto the start of the links array. |
496 | - if ( $used_curies ) { |
|
497 | - $data = array_merge( array( 'curies' => array_values( $used_curies ) ), $data ); |
|
496 | + if ($used_curies) { |
|
497 | + $data = array_merge(array('curies' => array_values($used_curies)), $data); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | return $data; |
@@ -514,57 +514,57 @@ discard block |
||
514 | 514 | * @type array [$_embedded] Embeddeds. |
515 | 515 | * } |
516 | 516 | */ |
517 | - protected function embed_links( $data ) { |
|
518 | - if ( empty( $data['_links'] ) ) { |
|
517 | + protected function embed_links($data) { |
|
518 | + if (empty($data['_links'])) { |
|
519 | 519 | return $data; |
520 | 520 | } |
521 | 521 | |
522 | 522 | $embedded = array(); |
523 | 523 | |
524 | - foreach ( $data['_links'] as $rel => $links ) { |
|
524 | + foreach ($data['_links'] as $rel => $links) { |
|
525 | 525 | // Ignore links to self, for obvious reasons. |
526 | - if ( 'self' === $rel ) { |
|
526 | + if ('self' === $rel) { |
|
527 | 527 | continue; |
528 | 528 | } |
529 | 529 | |
530 | 530 | $embeds = array(); |
531 | 531 | |
532 | - foreach ( $links as $item ) { |
|
532 | + foreach ($links as $item) { |
|
533 | 533 | // Determine if the link is embeddable. |
534 | - if ( empty( $item['embeddable'] ) ) { |
|
534 | + if (empty($item['embeddable'])) { |
|
535 | 535 | // Ensure we keep the same order. |
536 | 536 | $embeds[] = array(); |
537 | 537 | continue; |
538 | 538 | } |
539 | 539 | |
540 | 540 | // Run through our internal routing and serve. |
541 | - $request = WP_REST_Request::from_url( $item['href'] ); |
|
542 | - if ( ! $request ) { |
|
541 | + $request = WP_REST_Request::from_url($item['href']); |
|
542 | + if ( ! $request) { |
|
543 | 543 | $embeds[] = array(); |
544 | 544 | continue; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Embedded resources get passed context=embed. |
548 | - if ( empty( $request['context'] ) ) { |
|
548 | + if (empty($request['context'])) { |
|
549 | 549 | $request['context'] = 'embed'; |
550 | 550 | } |
551 | 551 | |
552 | - $response = $this->dispatch( $request ); |
|
552 | + $response = $this->dispatch($request); |
|
553 | 553 | |
554 | 554 | /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
555 | - $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request ); |
|
555 | + $response = apply_filters('rest_post_dispatch', rest_ensure_response($response), $this, $request); |
|
556 | 556 | |
557 | - $embeds[] = $this->response_to_data( $response, false ); |
|
557 | + $embeds[] = $this->response_to_data($response, false); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | // Determine if any real links were found. |
561 | - $has_links = count( array_filter( $embeds ) ); |
|
562 | - if ( $has_links ) { |
|
563 | - $embedded[ $rel ] = $embeds; |
|
561 | + $has_links = count(array_filter($embeds)); |
|
562 | + if ($has_links) { |
|
563 | + $embedded[$rel] = $embeds; |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | - if ( ! empty( $embedded ) ) { |
|
567 | + if ( ! empty($embedded)) { |
|
568 | 568 | $data['_embedded'] = $embedded; |
569 | 569 | } |
570 | 570 | |
@@ -585,9 +585,9 @@ discard block |
||
585 | 585 | * @param bool $embed Whether links should be embedded. |
586 | 586 | * @return WP_REST_Response New response with wrapped data |
587 | 587 | */ |
588 | - public function envelope_response( $response, $embed ) { |
|
588 | + public function envelope_response($response, $embed) { |
|
589 | 589 | $envelope = array( |
590 | - 'body' => $this->response_to_data( $response, $embed ), |
|
590 | + 'body' => $this->response_to_data($response, $embed), |
|
591 | 591 | 'status' => $response->get_status(), |
592 | 592 | 'headers' => $response->get_headers(), |
593 | 593 | ); |
@@ -600,10 +600,10 @@ discard block |
||
600 | 600 | * @param array $envelope Envelope data. |
601 | 601 | * @param WP_REST_Response $response Original response data. |
602 | 602 | */ |
603 | - $envelope = apply_filters( 'rest_envelope_response', $envelope, $response ); |
|
603 | + $envelope = apply_filters('rest_envelope_response', $envelope, $response); |
|
604 | 604 | |
605 | 605 | // Ensure it's still a response and return. |
606 | - return rest_ensure_response( $envelope ); |
|
606 | + return rest_ensure_response($envelope); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -618,14 +618,14 @@ discard block |
||
618 | 618 | * @param bool $override Optional. Whether the route should be overriden if it already exists. |
619 | 619 | * Default false. |
620 | 620 | */ |
621 | - public function register_route( $namespace, $route, $route_args, $override = false ) { |
|
622 | - if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
|
623 | - $this->namespaces[ $namespace ] = array(); |
|
621 | + public function register_route($namespace, $route, $route_args, $override = false) { |
|
622 | + if ( ! isset($this->namespaces[$namespace])) { |
|
623 | + $this->namespaces[$namespace] = array(); |
|
624 | 624 | |
625 | - $this->register_route( $namespace, '/' . $namespace, array( |
|
625 | + $this->register_route($namespace, '/'.$namespace, array( |
|
626 | 626 | array( |
627 | 627 | 'methods' => self::READABLE, |
628 | - 'callback' => array( $this, 'get_namespace_index' ), |
|
628 | + 'callback' => array($this, 'get_namespace_index'), |
|
629 | 629 | 'args' => array( |
630 | 630 | 'namespace' => array( |
631 | 631 | 'default' => $namespace, |
@@ -635,17 +635,17 @@ discard block |
||
635 | 635 | ), |
636 | 636 | ), |
637 | 637 | ), |
638 | - ) ); |
|
638 | + )); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | // Associative to avoid double-registration. |
642 | - $this->namespaces[ $namespace ][ $route ] = true; |
|
642 | + $this->namespaces[$namespace][$route] = true; |
|
643 | 643 | $route_args['namespace'] = $namespace; |
644 | 644 | |
645 | - if ( $override || empty( $this->endpoints[ $route ] ) ) { |
|
646 | - $this->endpoints[ $route ] = $route_args; |
|
645 | + if ($override || empty($this->endpoints[$route])) { |
|
646 | + $this->endpoints[$route] = $route_args; |
|
647 | 647 | } else { |
648 | - $this->endpoints[ $route ] = array_merge( $this->endpoints[ $route ], $route_args ); |
|
648 | + $this->endpoints[$route] = array_merge($this->endpoints[$route], $route_args); |
|
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | * `'/path/regex' => array( $callback, $bitmask )` or |
683 | 683 | * `'/path/regex' => array( array( $callback, $bitmask ). |
684 | 684 | */ |
685 | - $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
|
685 | + $endpoints = apply_filters('rest_endpoints', $this->endpoints); |
|
686 | 686 | |
687 | 687 | // Normalise the endpoints. |
688 | 688 | $defaults = array( |
@@ -693,32 +693,32 @@ discard block |
||
693 | 693 | 'args' => array(), |
694 | 694 | ); |
695 | 695 | |
696 | - foreach ( $endpoints as $route => &$handlers ) { |
|
696 | + foreach ($endpoints as $route => &$handlers) { |
|
697 | 697 | |
698 | - if ( isset( $handlers['callback'] ) ) { |
|
698 | + if (isset($handlers['callback'])) { |
|
699 | 699 | // Single endpoint, add one deeper. |
700 | - $handlers = array( $handlers ); |
|
700 | + $handlers = array($handlers); |
|
701 | 701 | } |
702 | 702 | |
703 | - if ( ! isset( $this->route_options[ $route ] ) ) { |
|
704 | - $this->route_options[ $route ] = array(); |
|
703 | + if ( ! isset($this->route_options[$route])) { |
|
704 | + $this->route_options[$route] = array(); |
|
705 | 705 | } |
706 | 706 | |
707 | - foreach ( $handlers as $key => &$handler ) { |
|
707 | + foreach ($handlers as $key => &$handler) { |
|
708 | 708 | |
709 | - if ( ! is_numeric( $key ) ) { |
|
709 | + if ( ! is_numeric($key)) { |
|
710 | 710 | // Route option, move it to the options. |
711 | - $this->route_options[ $route ][ $key ] = $handler; |
|
712 | - unset( $handlers[ $key ] ); |
|
711 | + $this->route_options[$route][$key] = $handler; |
|
712 | + unset($handlers[$key]); |
|
713 | 713 | continue; |
714 | 714 | } |
715 | 715 | |
716 | - $handler = wp_parse_args( $handler, $defaults ); |
|
716 | + $handler = wp_parse_args($handler, $defaults); |
|
717 | 717 | |
718 | 718 | // Allow comma-separated HTTP methods. |
719 | - if ( is_string( $handler['methods'] ) ) { |
|
720 | - $methods = explode( ',', $handler['methods'] ); |
|
721 | - } else if ( is_array( $handler['methods'] ) ) { |
|
719 | + if (is_string($handler['methods'])) { |
|
720 | + $methods = explode(',', $handler['methods']); |
|
721 | + } else if (is_array($handler['methods'])) { |
|
722 | 722 | $methods = $handler['methods']; |
723 | 723 | } else { |
724 | 724 | $methods = array(); |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | |
727 | 727 | $handler['methods'] = array(); |
728 | 728 | |
729 | - foreach ( $methods as $method ) { |
|
730 | - $method = strtoupper( trim( $method ) ); |
|
731 | - $handler['methods'][ $method ] = true; |
|
729 | + foreach ($methods as $method) { |
|
730 | + $method = strtoupper(trim($method)); |
|
731 | + $handler['methods'][$method] = true; |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | } |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * @return array List of registered namespaces. |
745 | 745 | */ |
746 | 746 | public function get_namespaces() { |
747 | - return array_keys( $this->namespaces ); |
|
747 | + return array_keys($this->namespaces); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
@@ -756,12 +756,12 @@ discard block |
||
756 | 756 | * @param string $route Route pattern to fetch options for. |
757 | 757 | * @return array|null Data as an associative array if found, or null if not found. |
758 | 758 | */ |
759 | - public function get_route_options( $route ) { |
|
760 | - if ( ! isset( $this->route_options[ $route ] ) ) { |
|
759 | + public function get_route_options($route) { |
|
760 | + if ( ! isset($this->route_options[$route])) { |
|
761 | 761 | return null; |
762 | 762 | } |
763 | 763 | |
764 | - return $this->route_options[ $route ]; |
|
764 | + return $this->route_options[$route]; |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | * @param WP_REST_Request $request Request to attempt dispatching. |
774 | 774 | * @return WP_REST_Response Response returned by the callback. |
775 | 775 | */ |
776 | - public function dispatch( $request ) { |
|
776 | + public function dispatch($request) { |
|
777 | 777 | /** |
778 | 778 | * Filter the pre-calculated result of a REST dispatch request. |
779 | 779 | * |
@@ -787,78 +787,78 @@ discard block |
||
787 | 787 | * @param WP_REST_Server $this Server instance. |
788 | 788 | * @param WP_REST_Request $request Request used to generate the response. |
789 | 789 | */ |
790 | - $result = apply_filters( 'rest_pre_dispatch', null, $this, $request ); |
|
790 | + $result = apply_filters('rest_pre_dispatch', null, $this, $request); |
|
791 | 791 | |
792 | - if ( ! empty( $result ) ) { |
|
792 | + if ( ! empty($result)) { |
|
793 | 793 | return $result; |
794 | 794 | } |
795 | 795 | |
796 | 796 | $method = $request->get_method(); |
797 | 797 | $path = $request->get_route(); |
798 | 798 | |
799 | - foreach ( $this->get_routes() as $route => $handlers ) { |
|
800 | - $match = preg_match( '@^' . $route . '$@i', $path, $args ); |
|
799 | + foreach ($this->get_routes() as $route => $handlers) { |
|
800 | + $match = preg_match('@^'.$route.'$@i', $path, $args); |
|
801 | 801 | |
802 | - if ( ! $match ) { |
|
802 | + if ( ! $match) { |
|
803 | 803 | continue; |
804 | 804 | } |
805 | 805 | |
806 | - foreach ( $handlers as $handler ) { |
|
807 | - $callback = $handler['callback']; |
|
806 | + foreach ($handlers as $handler) { |
|
807 | + $callback = $handler['callback']; |
|
808 | 808 | $response = null; |
809 | 809 | |
810 | 810 | // Fallback to GET method if no HEAD method is registered. |
811 | 811 | $checked_method = $method; |
812 | - if ( 'HEAD' === $method && empty( $handler['methods']['HEAD'] ) ) { |
|
812 | + if ('HEAD' === $method && empty($handler['methods']['HEAD'])) { |
|
813 | 813 | $checked_method = 'GET'; |
814 | 814 | } |
815 | - if ( empty( $handler['methods'][ $checked_method ] ) ) { |
|
815 | + if (empty($handler['methods'][$checked_method])) { |
|
816 | 816 | continue; |
817 | 817 | } |
818 | 818 | |
819 | - if ( ! is_callable( $callback ) ) { |
|
820 | - $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
|
819 | + if ( ! is_callable($callback)) { |
|
820 | + $response = new WP_Error('rest_invalid_handler', __('The handler for the route is invalid'), array('status' => 500)); |
|
821 | 821 | } |
822 | 822 | |
823 | - if ( ! is_wp_error( $response ) ) { |
|
823 | + if ( ! is_wp_error($response)) { |
|
824 | 824 | // Remove the redundant preg_match argument. |
825 | - unset( $args[0] ); |
|
825 | + unset($args[0]); |
|
826 | 826 | |
827 | - $request->set_url_params( $args ); |
|
828 | - $request->set_attributes( $handler ); |
|
827 | + $request->set_url_params($args); |
|
828 | + $request->set_attributes($handler); |
|
829 | 829 | |
830 | 830 | $request->sanitize_params(); |
831 | 831 | |
832 | 832 | $defaults = array(); |
833 | 833 | |
834 | - foreach ( $handler['args'] as $arg => $options ) { |
|
835 | - if ( isset( $options['default'] ) ) { |
|
836 | - $defaults[ $arg ] = $options['default']; |
|
834 | + foreach ($handler['args'] as $arg => $options) { |
|
835 | + if (isset($options['default'])) { |
|
836 | + $defaults[$arg] = $options['default']; |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | - $request->set_default_params( $defaults ); |
|
840 | + $request->set_default_params($defaults); |
|
841 | 841 | |
842 | 842 | $check_required = $request->has_valid_params(); |
843 | - if ( is_wp_error( $check_required ) ) { |
|
843 | + if (is_wp_error($check_required)) { |
|
844 | 844 | $response = $check_required; |
845 | 845 | } |
846 | 846 | } |
847 | 847 | |
848 | - if ( ! is_wp_error( $response ) ) { |
|
848 | + if ( ! is_wp_error($response)) { |
|
849 | 849 | // Check permission specified on the route. |
850 | - if ( ! empty( $handler['permission_callback'] ) ) { |
|
851 | - $permission = call_user_func( $handler['permission_callback'], $request ); |
|
850 | + if ( ! empty($handler['permission_callback'])) { |
|
851 | + $permission = call_user_func($handler['permission_callback'], $request); |
|
852 | 852 | |
853 | - if ( is_wp_error( $permission ) ) { |
|
853 | + if (is_wp_error($permission)) { |
|
854 | 854 | $response = $permission; |
855 | - } else if ( false === $permission || null === $permission ) { |
|
856 | - $response = new WP_Error( 'rest_forbidden', __( "You don't have permission to do this." ), array( 'status' => 403 ) ); |
|
855 | + } else if (false === $permission || null === $permission) { |
|
856 | + $response = new WP_Error('rest_forbidden', __("You don't have permission to do this."), array('status' => 403)); |
|
857 | 857 | } |
858 | 858 | } |
859 | 859 | } |
860 | 860 | |
861 | - if ( ! is_wp_error( $response ) ) { |
|
861 | + if ( ! is_wp_error($response)) { |
|
862 | 862 | /** |
863 | 863 | * Filter the REST dispatch request result. |
864 | 864 | * |
@@ -872,30 +872,30 @@ discard block |
||
872 | 872 | * @param string $route Route matched for the request. |
873 | 873 | * @param array $handler Route handler used for the request. |
874 | 874 | */ |
875 | - $dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $route, $handler ); |
|
875 | + $dispatch_result = apply_filters('rest_dispatch_request', null, $request, $route, $handler); |
|
876 | 876 | |
877 | 877 | // Allow plugins to halt the request via this filter. |
878 | - if ( null !== $dispatch_result ) { |
|
878 | + if (null !== $dispatch_result) { |
|
879 | 879 | $response = $dispatch_result; |
880 | 880 | } else { |
881 | - $response = call_user_func( $callback, $request ); |
|
881 | + $response = call_user_func($callback, $request); |
|
882 | 882 | } |
883 | 883 | } |
884 | 884 | |
885 | - if ( is_wp_error( $response ) ) { |
|
886 | - $response = $this->error_to_response( $response ); |
|
885 | + if (is_wp_error($response)) { |
|
886 | + $response = $this->error_to_response($response); |
|
887 | 887 | } else { |
888 | - $response = rest_ensure_response( $response ); |
|
888 | + $response = rest_ensure_response($response); |
|
889 | 889 | } |
890 | 890 | |
891 | - $response->set_matched_route( $route ); |
|
892 | - $response->set_matched_handler( $handler ); |
|
891 | + $response->set_matched_route($route); |
|
892 | + $response->set_matched_handler($handler); |
|
893 | 893 | |
894 | 894 | return $response; |
895 | 895 | } |
896 | 896 | } |
897 | 897 | |
898 | - return $this->error_to_response( new WP_Error( 'rest_no_route', __( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); |
|
898 | + return $this->error_to_response(new WP_Error('rest_no_route', __('No route was found matching the URL and request method'), array('status' => 404))); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | /** |
@@ -911,13 +911,13 @@ discard block |
||
911 | 911 | */ |
912 | 912 | protected function get_json_last_error() { |
913 | 913 | // See https://core.trac.wordpress.org/ticket/27799. |
914 | - if ( ! function_exists( 'json_last_error' ) ) { |
|
914 | + if ( ! function_exists('json_last_error')) { |
|
915 | 915 | return false; |
916 | 916 | } |
917 | 917 | |
918 | 918 | $last_error_code = json_last_error(); |
919 | 919 | |
920 | - if ( ( defined( 'JSON_ERROR_NONE' ) && JSON_ERROR_NONE === $last_error_code ) || empty( $last_error_code ) ) { |
|
920 | + if ((defined('JSON_ERROR_NONE') && JSON_ERROR_NONE === $last_error_code) || empty($last_error_code)) { |
|
921 | 921 | return false; |
922 | 922 | } |
923 | 923 | |
@@ -939,20 +939,20 @@ discard block |
||
939 | 939 | * } |
940 | 940 | * @return array Index entity |
941 | 941 | */ |
942 | - public function get_index( $request ) { |
|
942 | + public function get_index($request) { |
|
943 | 943 | // General site data. |
944 | 944 | $available = array( |
945 | - 'name' => get_option( 'blogname' ), |
|
946 | - 'description' => get_option( 'blogdescription' ), |
|
947 | - 'url' => get_option( 'siteurl' ), |
|
948 | - 'namespaces' => array_keys( $this->namespaces ), |
|
945 | + 'name' => get_option('blogname'), |
|
946 | + 'description' => get_option('blogdescription'), |
|
947 | + 'url' => get_option('siteurl'), |
|
948 | + 'namespaces' => array_keys($this->namespaces), |
|
949 | 949 | 'authentication' => array(), |
950 | - 'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ), |
|
950 | + 'routes' => $this->get_data_for_routes($this->get_routes(), $request['context']), |
|
951 | 951 | ); |
952 | 952 | |
953 | - $response = new WP_REST_Response( $available ); |
|
953 | + $response = new WP_REST_Response($available); |
|
954 | 954 | |
955 | - $response->add_link( 'help', 'http://v2.wp-api.org/' ); |
|
955 | + $response->add_link('help', 'http://v2.wp-api.org/'); |
|
956 | 956 | |
957 | 957 | /** |
958 | 958 | * Filter the API root index data. |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | * |
966 | 966 | * @param WP_REST_Response $response Response data. |
967 | 967 | */ |
968 | - return apply_filters( 'rest_index', $response ); |
|
968 | + return apply_filters('rest_index', $response); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
@@ -978,24 +978,24 @@ discard block |
||
978 | 978 | * @return WP_REST_Response|WP_Error WP_REST_Response instance if the index was found, |
979 | 979 | * WP_Error if the namespace isn't set. |
980 | 980 | */ |
981 | - public function get_namespace_index( $request ) { |
|
981 | + public function get_namespace_index($request) { |
|
982 | 982 | $namespace = $request['namespace']; |
983 | 983 | |
984 | - if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
|
985 | - return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
|
984 | + if ( ! isset($this->namespaces[$namespace])) { |
|
985 | + return new WP_Error('rest_invalid_namespace', __('The specified namespace could not be found.'), array('status' => 404)); |
|
986 | 986 | } |
987 | 987 | |
988 | - $routes = $this->namespaces[ $namespace ]; |
|
989 | - $endpoints = array_intersect_key( $this->get_routes(), $routes ); |
|
988 | + $routes = $this->namespaces[$namespace]; |
|
989 | + $endpoints = array_intersect_key($this->get_routes(), $routes); |
|
990 | 990 | |
991 | 991 | $data = array( |
992 | 992 | 'namespace' => $namespace, |
993 | - 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ), |
|
993 | + 'routes' => $this->get_data_for_routes($endpoints, $request['context']), |
|
994 | 994 | ); |
995 | - $response = rest_ensure_response( $data ); |
|
995 | + $response = rest_ensure_response($data); |
|
996 | 996 | |
997 | 997 | // Link to the root index. |
998 | - $response->add_link( 'up', rest_url( '/' ) ); |
|
998 | + $response->add_link('up', rest_url('/')); |
|
999 | 999 | |
1000 | 1000 | /** |
1001 | 1001 | * Filter the namespace index data. |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | * @param WP_REST_Response $response Response data. |
1009 | 1009 | * @param WP_REST_Request $request Request data. The namespace is passed as the 'namespace' parameter. |
1010 | 1010 | */ |
1011 | - return apply_filters( 'rest_namespace_index', $response, $request ); |
|
1011 | + return apply_filters('rest_namespace_index', $response, $request); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1021,13 +1021,13 @@ discard block |
||
1021 | 1021 | * @param string $context Optional. Context for data. Accepts 'view' or 'help'. Default 'view'. |
1022 | 1022 | * @return array Route data to expose in indexes. |
1023 | 1023 | */ |
1024 | - public function get_data_for_routes( $routes, $context = 'view' ) { |
|
1024 | + public function get_data_for_routes($routes, $context = 'view') { |
|
1025 | 1025 | $available = array(); |
1026 | 1026 | |
1027 | 1027 | // Find the available routes. |
1028 | - foreach ( $routes as $route => $callbacks ) { |
|
1029 | - $data = $this->get_data_for_route( $route, $callbacks, $context ); |
|
1030 | - if ( empty( $data ) ) { |
|
1028 | + foreach ($routes as $route => $callbacks) { |
|
1029 | + $data = $this->get_data_for_route($route, $callbacks, $context); |
|
1030 | + if (empty($data)) { |
|
1031 | 1031 | continue; |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | * |
1039 | 1039 | * @param WP_REST_Request $request Request data. The namespace is passed as the 'namespace' parameter. |
1040 | 1040 | */ |
1041 | - $available[ $route ] = apply_filters( 'rest_endpoints_description', $data ); |
|
1041 | + $available[$route] = apply_filters('rest_endpoints_description', $data); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | * @param array $available Map of route to route data. |
1054 | 1054 | * @param array $routes Internal route data as an associative array. |
1055 | 1055 | */ |
1056 | - return apply_filters( 'rest_route_data', $available, $routes ); |
|
1056 | + return apply_filters('rest_route_data', $available, $routes); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1067,68 +1067,68 @@ discard block |
||
1067 | 1067 | * @param string $context Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'. |
1068 | 1068 | * @return array|null Data for the route, or null if no publicly-visible data. |
1069 | 1069 | */ |
1070 | - public function get_data_for_route( $route, $callbacks, $context = 'view' ) { |
|
1070 | + public function get_data_for_route($route, $callbacks, $context = 'view') { |
|
1071 | 1071 | $data = array( |
1072 | 1072 | 'namespace' => '', |
1073 | 1073 | 'methods' => array(), |
1074 | 1074 | 'endpoints' => array(), |
1075 | 1075 | ); |
1076 | 1076 | |
1077 | - if ( isset( $this->route_options[ $route ] ) ) { |
|
1078 | - $options = $this->route_options[ $route ]; |
|
1077 | + if (isset($this->route_options[$route])) { |
|
1078 | + $options = $this->route_options[$route]; |
|
1079 | 1079 | |
1080 | - if ( isset( $options['namespace'] ) ) { |
|
1080 | + if (isset($options['namespace'])) { |
|
1081 | 1081 | $data['namespace'] = $options['namespace']; |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - if ( isset( $options['schema'] ) && 'help' === $context ) { |
|
1085 | - $data['schema'] = call_user_func( $options['schema'] ); |
|
1084 | + if (isset($options['schema']) && 'help' === $context) { |
|
1085 | + $data['schema'] = call_user_func($options['schema']); |
|
1086 | 1086 | } |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - $route = preg_replace( '#\(\?P<(\w+?)>.*?\)#', '{$1}', $route ); |
|
1089 | + $route = preg_replace('#\(\?P<(\w+?)>.*?\)#', '{$1}', $route); |
|
1090 | 1090 | |
1091 | - foreach ( $callbacks as $callback ) { |
|
1091 | + foreach ($callbacks as $callback) { |
|
1092 | 1092 | // Skip to the next route if any callback is hidden. |
1093 | - if ( empty( $callback['show_in_index'] ) ) { |
|
1093 | + if (empty($callback['show_in_index'])) { |
|
1094 | 1094 | continue; |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - $data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) ); |
|
1097 | + $data['methods'] = array_merge($data['methods'], array_keys($callback['methods'])); |
|
1098 | 1098 | $endpoint_data = array( |
1099 | - 'methods' => array_keys( $callback['methods'] ), |
|
1099 | + 'methods' => array_keys($callback['methods']), |
|
1100 | 1100 | ); |
1101 | 1101 | |
1102 | - if ( isset( $callback['args'] ) ) { |
|
1102 | + if (isset($callback['args'])) { |
|
1103 | 1103 | $endpoint_data['args'] = array(); |
1104 | - foreach ( $callback['args'] as $key => $opts ) { |
|
1104 | + foreach ($callback['args'] as $key => $opts) { |
|
1105 | 1105 | $arg_data = array( |
1106 | - 'required' => ! empty( $opts['required'] ), |
|
1106 | + 'required' => ! empty($opts['required']), |
|
1107 | 1107 | ); |
1108 | - if ( isset( $opts['default'] ) ) { |
|
1108 | + if (isset($opts['default'])) { |
|
1109 | 1109 | $arg_data['default'] = $opts['default']; |
1110 | 1110 | } |
1111 | - if ( isset( $opts['enum'] ) ) { |
|
1111 | + if (isset($opts['enum'])) { |
|
1112 | 1112 | $arg_data['enum'] = $opts['enum']; |
1113 | 1113 | } |
1114 | - if ( isset( $opts['description'] ) ) { |
|
1114 | + if (isset($opts['description'])) { |
|
1115 | 1115 | $arg_data['description'] = $opts['description']; |
1116 | 1116 | } |
1117 | - $endpoint_data['args'][ $key ] = $arg_data; |
|
1117 | + $endpoint_data['args'][$key] = $arg_data; |
|
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | $data['endpoints'][] = $endpoint_data; |
1122 | 1122 | |
1123 | 1123 | // For non-variable routes, generate links. |
1124 | - if ( strpos( $route, '{' ) === false ) { |
|
1124 | + if (strpos($route, '{') === false) { |
|
1125 | 1125 | $data['_links'] = array( |
1126 | - 'self' => rest_url( $route ), |
|
1126 | + 'self' => rest_url($route), |
|
1127 | 1127 | ); |
1128 | 1128 | } |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - if ( empty( $data['methods'] ) ) { |
|
1131 | + if (empty($data['methods'])) { |
|
1132 | 1132 | // No methods supported, hide the route. |
1133 | 1133 | return null; |
1134 | 1134 | } |
@@ -1144,8 +1144,8 @@ discard block |
||
1144 | 1144 | * |
1145 | 1145 | * @param int $code HTTP status. |
1146 | 1146 | */ |
1147 | - protected function set_status( $code ) { |
|
1148 | - status_header( $code ); |
|
1147 | + protected function set_status($code) { |
|
1148 | + status_header($code); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | * @param string $key Header key. |
1158 | 1158 | * @param string $value Header value. |
1159 | 1159 | */ |
1160 | - public function send_header( $key, $value ) { |
|
1160 | + public function send_header($key, $value) { |
|
1161 | 1161 | /* |
1162 | 1162 | * Sanitize as per RFC2616 (Section 4.2): |
1163 | 1163 | * |
@@ -1165,8 +1165,8 @@ discard block |
||
1165 | 1165 | * single SP before interpreting the field value or forwarding the |
1166 | 1166 | * message downstream. |
1167 | 1167 | */ |
1168 | - $value = preg_replace( '/\s+/', ' ', $value ); |
|
1169 | - header( sprintf( '%s: %s', $key, $value ) ); |
|
1168 | + $value = preg_replace('/\s+/', ' ', $value); |
|
1169 | + header(sprintf('%s: %s', $key, $value)); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | 1172 | /** |
@@ -1177,9 +1177,9 @@ discard block |
||
1177 | 1177 | * |
1178 | 1178 | * @param array $headers Map of header name to header value. |
1179 | 1179 | */ |
1180 | - public function send_headers( $headers ) { |
|
1181 | - foreach ( $headers as $key => $value ) { |
|
1182 | - $this->send_header( $key, $value ); |
|
1180 | + public function send_headers($headers) { |
|
1181 | + foreach ($headers as $key => $value) { |
|
1182 | + $this->send_header($key, $value); |
|
1183 | 1183 | } |
1184 | 1184 | } |
1185 | 1185 | |
@@ -1200,8 +1200,8 @@ discard block |
||
1200 | 1200 | * A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, |
1201 | 1201 | * but we can do it ourself. |
1202 | 1202 | */ |
1203 | - if ( ! isset( $HTTP_RAW_POST_DATA ) ) { |
|
1204 | - $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' ); |
|
1203 | + if ( ! isset($HTTP_RAW_POST_DATA)) { |
|
1204 | + $HTTP_RAW_POST_DATA = file_get_contents('php://input'); |
|
1205 | 1205 | } |
1206 | 1206 | |
1207 | 1207 | return $HTTP_RAW_POST_DATA; |
@@ -1216,17 +1216,17 @@ discard block |
||
1216 | 1216 | * @param array $server Associative array similar to `$_SERVER`. |
1217 | 1217 | * @return array Headers extracted from the input. |
1218 | 1218 | */ |
1219 | - public function get_headers( $server ) { |
|
1219 | + public function get_headers($server) { |
|
1220 | 1220 | $headers = array(); |
1221 | 1221 | |
1222 | 1222 | // CONTENT_* headers are not prefixed with HTTP_. |
1223 | - $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true ); |
|
1223 | + $additional = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true); |
|
1224 | 1224 | |
1225 | - foreach ( $server as $key => $value ) { |
|
1226 | - if ( strpos( $key, 'HTTP_' ) === 0 ) { |
|
1227 | - $headers[ substr( $key, 5 ) ] = $value; |
|
1228 | - } elseif ( isset( $additional[ $key ] ) ) { |
|
1229 | - $headers[ $key ] = $value; |
|
1225 | + foreach ($server as $key => $value) { |
|
1226 | + if (strpos($key, 'HTTP_') === 0) { |
|
1227 | + $headers[substr($key, 5)] = $value; |
|
1228 | + } elseif (isset($additional[$key])) { |
|
1229 | + $headers[$key] = $value; |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * |
441 | 441 | * @see get_children() |
442 | 442 | * |
443 | - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`. |
|
443 | + * @param integer $post_id Optional. Post ID or WP_Post object. Default is global `$post`. |
|
444 | 444 | * @param array|null $args Optional. Arguments for retrieving post revisions. Default null. |
445 | 445 | * @return array An array of revisions, or an empty array if none. |
446 | 446 | */ |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * @access private |
520 | 520 | * |
521 | 521 | * @param WP_Post $post |
522 | - * @return WP_Post|false |
|
522 | + * @return WP_Post |
|
523 | 523 | */ |
524 | 524 | function _set_preview( $post ) { |
525 | 525 | if ( ! is_object( $post ) ) { |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | * @param bool $deprecated Not used. |
22 | 22 | * @return array Array of fields that can be versioned. |
23 | 23 | */ |
24 | -function _wp_post_revision_fields( $post = array(), $deprecated = false ) { |
|
24 | +function _wp_post_revision_fields($post = array(), $deprecated = false) { |
|
25 | 25 | static $fields = null; |
26 | 26 | |
27 | - if ( ! is_array( $post ) ) { |
|
28 | - $post = get_post( $post, ARRAY_A ); |
|
27 | + if ( ! is_array($post)) { |
|
28 | + $post = get_post($post, ARRAY_A); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( is_null( $fields ) ) { |
|
31 | + if (is_null($fields)) { |
|
32 | 32 | // Allow these to be versioned |
33 | 33 | $fields = array( |
34 | - 'post_title' => __( 'Title' ), |
|
35 | - 'post_content' => __( 'Content' ), |
|
36 | - 'post_excerpt' => __( 'Excerpt' ), |
|
34 | + 'post_title' => __('Title'), |
|
35 | + 'post_content' => __('Content'), |
|
36 | + 'post_excerpt' => __('Excerpt'), |
|
37 | 37 | ); |
38 | 38 | } |
39 | 39 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * 'post_content', and 'post_excerpt' by default. |
54 | 54 | * @param array $post A post array being processed for insertion as a post revision. |
55 | 55 | */ |
56 | - $fields = apply_filters( '_wp_post_revision_fields', $fields, $post ); |
|
56 | + $fields = apply_filters('_wp_post_revision_fields', $fields, $post); |
|
57 | 57 | |
58 | 58 | // WP uses these internally either in versioning or elsewhere - they cannot be versioned |
59 | - foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) { |
|
60 | - unset( $fields[ $protect ] ); |
|
59 | + foreach (array('ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author') as $protect) { |
|
60 | + unset($fields[$protect]); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | * @param bool $autosave Optional. Is the revision an autosave? Default false. |
76 | 76 | * @return array Post array ready to be inserted as a post revision. |
77 | 77 | */ |
78 | -function _wp_post_revision_data( $post = array(), $autosave = false ) { |
|
79 | - if ( ! is_array( $post ) ) { |
|
80 | - $post = get_post( $post, ARRAY_A ); |
|
78 | +function _wp_post_revision_data($post = array(), $autosave = false) { |
|
79 | + if ( ! is_array($post)) { |
|
80 | + $post = get_post($post, ARRAY_A); |
|
81 | 81 | } |
82 | 82 | |
83 | - $fields = _wp_post_revision_fields( $post ); |
|
83 | + $fields = _wp_post_revision_fields($post); |
|
84 | 84 | |
85 | 85 | $revision_data = array(); |
86 | 86 | |
87 | - foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) { |
|
88 | - $revision_data[ $field ] = $post[ $field ]; |
|
87 | + foreach (array_intersect(array_keys($post), array_keys($fields)) as $field) { |
|
88 | + $revision_data[$field] = $post[$field]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $revision_data['post_parent'] = $post['ID']; |
92 | 92 | $revision_data['post_status'] = 'inherit'; |
93 | 93 | $revision_data['post_type'] = 'revision'; |
94 | 94 | $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version |
95 | - $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; |
|
96 | - $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; |
|
95 | + $revision_data['post_date'] = isset($post['post_modified']) ? $post['post_modified'] : ''; |
|
96 | + $revision_data['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : ''; |
|
97 | 97 | |
98 | 98 | return $revision_data; |
99 | 99 | } |
@@ -109,29 +109,29 @@ discard block |
||
109 | 109 | * @param int $post_id The ID of the post to save as a revision. |
110 | 110 | * @return int|WP_Error|void Void or 0 if error, new revision ID, if success. |
111 | 111 | */ |
112 | -function wp_save_post_revision( $post_id ) { |
|
113 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
112 | +function wp_save_post_revision($post_id) { |
|
113 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
114 | 114 | return; |
115 | 115 | |
116 | - if ( ! $post = get_post( $post_id ) ) |
|
116 | + if ( ! $post = get_post($post_id)) |
|
117 | 117 | return; |
118 | 118 | |
119 | - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) |
|
119 | + if ( ! post_type_supports($post->post_type, 'revisions')) |
|
120 | 120 | return; |
121 | 121 | |
122 | - if ( 'auto-draft' == $post->post_status ) |
|
122 | + if ('auto-draft' == $post->post_status) |
|
123 | 123 | return; |
124 | 124 | |
125 | - if ( ! wp_revisions_enabled( $post ) ) |
|
125 | + if ( ! wp_revisions_enabled($post)) |
|
126 | 126 | return; |
127 | 127 | |
128 | 128 | // Compare the proposed update with the last stored revision verifying that |
129 | 129 | // they are different, unless a plugin tells us to always save regardless. |
130 | 130 | // If no previous revisions, save one |
131 | - if ( $revisions = wp_get_post_revisions( $post_id ) ) { |
|
131 | + if ($revisions = wp_get_post_revisions($post_id)) { |
|
132 | 132 | // grab the last revision, but not an autosave |
133 | - foreach ( $revisions as $revision ) { |
|
134 | - if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) { |
|
133 | + foreach ($revisions as $revision) { |
|
134 | + if (false !== strpos($revision->post_name, "{$revision->post_parent}-revision")) { |
|
135 | 135 | $last_revision = $revision; |
136 | 136 | break; |
137 | 137 | } |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * @param WP_Post $post The post object. |
152 | 152 | * |
153 | 153 | */ |
154 | - if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) { |
|
154 | + if (isset($last_revision) && apply_filters('wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post)) { |
|
155 | 155 | $post_has_changed = false; |
156 | 156 | |
157 | - foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) { |
|
158 | - if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) { |
|
157 | + foreach (array_keys(_wp_post_revision_fields($post)) as $field) { |
|
158 | + if (normalize_whitespace($post->$field) != normalize_whitespace($last_revision->$field)) { |
|
159 | 159 | $post_has_changed = true; |
160 | 160 | break; |
161 | 161 | } |
@@ -174,38 +174,38 @@ discard block |
||
174 | 174 | * @param WP_Post $post The post object. |
175 | 175 | * |
176 | 176 | */ |
177 | - $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post ); |
|
177 | + $post_has_changed = (bool) apply_filters('wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post); |
|
178 | 178 | |
179 | 179 | //don't save revision if post unchanged |
180 | - if ( ! $post_has_changed ) { |
|
180 | + if ( ! $post_has_changed) { |
|
181 | 181 | return; |
182 | 182 | } |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - $return = _wp_put_post_revision( $post ); |
|
186 | + $return = _wp_put_post_revision($post); |
|
187 | 187 | |
188 | 188 | // If a limit for the number of revisions to keep has been set, |
189 | 189 | // delete the oldest ones. |
190 | - $revisions_to_keep = wp_revisions_to_keep( $post ); |
|
190 | + $revisions_to_keep = wp_revisions_to_keep($post); |
|
191 | 191 | |
192 | - if ( $revisions_to_keep < 0 ) |
|
192 | + if ($revisions_to_keep < 0) |
|
193 | 193 | return $return; |
194 | 194 | |
195 | - $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); |
|
195 | + $revisions = wp_get_post_revisions($post_id, array('order' => 'ASC')); |
|
196 | 196 | |
197 | 197 | $delete = count($revisions) - $revisions_to_keep; |
198 | 198 | |
199 | - if ( $delete < 1 ) |
|
199 | + if ($delete < 1) |
|
200 | 200 | return $return; |
201 | 201 | |
202 | - $revisions = array_slice( $revisions, 0, $delete ); |
|
202 | + $revisions = array_slice($revisions, 0, $delete); |
|
203 | 203 | |
204 | - for ( $i = 0; isset( $revisions[$i] ); $i++ ) { |
|
205 | - if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) |
|
204 | + for ($i = 0; isset($revisions[$i]); $i++) { |
|
205 | + if (false !== strpos($revisions[$i]->post_name, 'autosave')) |
|
206 | 206 | continue; |
207 | 207 | |
208 | - wp_delete_post_revision( $revisions[ $i ]->ID ); |
|
208 | + wp_delete_post_revision($revisions[$i]->ID); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | return $return; |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | * @param int $user_id Optional The post author ID. |
225 | 225 | * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. |
226 | 226 | */ |
227 | -function wp_get_post_autosave( $post_id, $user_id = 0 ) { |
|
228 | - $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) ); |
|
227 | +function wp_get_post_autosave($post_id, $user_id = 0) { |
|
228 | + $revisions = wp_get_post_revisions($post_id, array('check_enabled' => false)); |
|
229 | 229 | |
230 | - foreach ( $revisions as $revision ) { |
|
231 | - if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { |
|
232 | - if ( $user_id && $user_id != $revision->post_author ) |
|
230 | + foreach ($revisions as $revision) { |
|
231 | + if (false !== strpos($revision->post_name, "{$post_id}-autosave")) { |
|
232 | + if ($user_id && $user_id != $revision->post_author) |
|
233 | 233 | continue; |
234 | 234 | |
235 | 235 | return $revision; |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param int|WP_Post $post Post ID or post object. |
248 | 248 | * @return false|int False if not a revision, ID of revision's parent otherwise. |
249 | 249 | */ |
250 | -function wp_is_post_revision( $post ) { |
|
251 | - if ( !$post = wp_get_post_revision( $post ) ) |
|
250 | +function wp_is_post_revision($post) { |
|
251 | + if ( ! $post = wp_get_post_revision($post)) |
|
252 | 252 | return false; |
253 | 253 | |
254 | 254 | return (int) $post->post_parent; |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * @param int|WP_Post $post Post ID or post object. |
263 | 263 | * @return false|int False if not a revision, ID of autosave's parent otherwise |
264 | 264 | */ |
265 | -function wp_is_post_autosave( $post ) { |
|
266 | - if ( !$post = wp_get_post_revision( $post ) ) |
|
265 | +function wp_is_post_autosave($post) { |
|
266 | + if ( ! $post = wp_get_post_revision($post)) |
|
267 | 267 | return false; |
268 | 268 | |
269 | - if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) |
|
269 | + if (false !== strpos($post->post_name, "{$post->post_parent}-autosave")) |
|
270 | 270 | return (int) $post->post_parent; |
271 | 271 | |
272 | 272 | return false; |
@@ -282,26 +282,26 @@ discard block |
||
282 | 282 | * @param bool $autosave Optional. Is the revision an autosave? |
283 | 283 | * @return int|WP_Error WP_Error or 0 if error, new revision ID if success. |
284 | 284 | */ |
285 | -function _wp_put_post_revision( $post = null, $autosave = false ) { |
|
286 | - if ( is_object($post) ) |
|
287 | - $post = get_object_vars( $post ); |
|
288 | - elseif ( !is_array($post) ) |
|
285 | +function _wp_put_post_revision($post = null, $autosave = false) { |
|
286 | + if (is_object($post)) |
|
287 | + $post = get_object_vars($post); |
|
288 | + elseif ( ! is_array($post)) |
|
289 | 289 | $post = get_post($post, ARRAY_A); |
290 | 290 | |
291 | - if ( ! $post || empty($post['ID']) ) |
|
292 | - return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
291 | + if ( ! $post || empty($post['ID'])) |
|
292 | + return new WP_Error('invalid_post', __('Invalid post ID.')); |
|
293 | 293 | |
294 | - if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) |
|
295 | - return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); |
|
294 | + if (isset($post['post_type']) && 'revision' == $post['post_type']) |
|
295 | + return new WP_Error('post_type', __('Cannot create a revision of a revision')); |
|
296 | 296 | |
297 | - $post = _wp_post_revision_data( $post, $autosave ); |
|
297 | + $post = _wp_post_revision_data($post, $autosave); |
|
298 | 298 | $post = wp_slash($post); //since data is from db |
299 | 299 | |
300 | - $revision_id = wp_insert_post( $post ); |
|
301 | - if ( is_wp_error($revision_id) ) |
|
300 | + $revision_id = wp_insert_post($post); |
|
301 | + if (is_wp_error($revision_id)) |
|
302 | 302 | return $revision_id; |
303 | 303 | |
304 | - if ( $revision_id ) { |
|
304 | + if ($revision_id) { |
|
305 | 305 | /** |
306 | 306 | * Fires once a revision has been saved. |
307 | 307 | * |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param int $revision_id Post revision ID. |
311 | 311 | */ |
312 | - do_action( '_wp_put_post_revision', $revision_id ); |
|
312 | + do_action('_wp_put_post_revision', $revision_id); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | return $revision_id; |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | * @return WP_Post|array|null Null if error or post object if success. |
327 | 327 | */ |
328 | 328 | function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { |
329 | - if ( !$revision = get_post( $post, OBJECT, $filter ) ) |
|
329 | + if ( ! $revision = get_post($post, OBJECT, $filter)) |
|
330 | 330 | return $revision; |
331 | - if ( 'revision' !== $revision->post_type ) |
|
331 | + if ('revision' !== $revision->post_type) |
|
332 | 332 | return null; |
333 | 333 | |
334 | - if ( $output == OBJECT ) { |
|
334 | + if ($output == OBJECT) { |
|
335 | 335 | return $revision; |
336 | - } elseif ( $output == ARRAY_A ) { |
|
336 | + } elseif ($output == ARRAY_A) { |
|
337 | 337 | $_revision = get_object_vars($revision); |
338 | 338 | return $_revision; |
339 | - } elseif ( $output == ARRAY_N ) { |
|
339 | + } elseif ($output == ARRAY_N) { |
|
340 | 340 | $_revision = array_values(get_object_vars($revision)); |
341 | 341 | return $_revision; |
342 | 342 | } |
@@ -355,27 +355,27 @@ discard block |
||
355 | 355 | * @param array $fields Optional. What fields to restore from. Defaults to all. |
356 | 356 | * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success. |
357 | 357 | */ |
358 | -function wp_restore_post_revision( $revision_id, $fields = null ) { |
|
359 | - if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) |
|
358 | +function wp_restore_post_revision($revision_id, $fields = null) { |
|
359 | + if ( ! $revision = wp_get_post_revision($revision_id, ARRAY_A)) |
|
360 | 360 | return $revision; |
361 | 361 | |
362 | - if ( !is_array( $fields ) ) |
|
363 | - $fields = array_keys( _wp_post_revision_fields( $revision ) ); |
|
362 | + if ( ! is_array($fields)) |
|
363 | + $fields = array_keys(_wp_post_revision_fields($revision)); |
|
364 | 364 | |
365 | 365 | $update = array(); |
366 | - foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) { |
|
366 | + foreach (array_intersect(array_keys($revision), $fields) as $field) { |
|
367 | 367 | $update[$field] = $revision[$field]; |
368 | 368 | } |
369 | 369 | |
370 | - if ( !$update ) |
|
370 | + if ( ! $update) |
|
371 | 371 | return false; |
372 | 372 | |
373 | 373 | $update['ID'] = $revision['post_parent']; |
374 | 374 | |
375 | - $update = wp_slash( $update ); //since data is from db |
|
375 | + $update = wp_slash($update); //since data is from db |
|
376 | 376 | |
377 | - $post_id = wp_update_post( $update ); |
|
378 | - if ( ! $post_id || is_wp_error( $post_id ) ) |
|
377 | + $post_id = wp_update_post($update); |
|
378 | + if ( ! $post_id || is_wp_error($post_id)) |
|
379 | 379 | return $post_id; |
380 | 380 | |
381 | 381 | // Add restore from details |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | 'restored_by_user' => get_current_user_id(), |
385 | 385 | 'restored_time' => time() |
386 | 386 | ); |
387 | - update_post_meta( $post_id, '_post_restored_from', $restore_details ); |
|
387 | + update_post_meta($post_id, '_post_restored_from', $restore_details); |
|
388 | 388 | |
389 | 389 | // Update last edit user |
390 | - update_post_meta( $post_id, '_edit_last', get_current_user_id() ); |
|
390 | + update_post_meta($post_id, '_edit_last', get_current_user_id()); |
|
391 | 391 | |
392 | 392 | /** |
393 | 393 | * Fires after a post revision has been restored. |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * @param int $post_id Post ID. |
398 | 398 | * @param int $revision_id Post revision ID. |
399 | 399 | */ |
400 | - do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] ); |
|
400 | + do_action('wp_restore_post_revision', $post_id, $revision['ID']); |
|
401 | 401 | |
402 | 402 | return $post_id; |
403 | 403 | } |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | * @param int|WP_Post $revision_id Revision ID or revision object. |
413 | 413 | * @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success. |
414 | 414 | */ |
415 | -function wp_delete_post_revision( $revision_id ) { |
|
416 | - if ( ! $revision = wp_get_post_revision( $revision_id ) ) { |
|
415 | +function wp_delete_post_revision($revision_id) { |
|
416 | + if ( ! $revision = wp_get_post_revision($revision_id)) { |
|
417 | 417 | return $revision; |
418 | 418 | } |
419 | 419 | |
420 | - $delete = wp_delete_post( $revision->ID ); |
|
421 | - if ( $delete ) { |
|
420 | + $delete = wp_delete_post($revision->ID); |
|
421 | + if ($delete) { |
|
422 | 422 | /** |
423 | 423 | * Fires once a post revision has been deleted. |
424 | 424 | * |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @param int $revision_id Post revision ID. |
428 | 428 | * @param object|array $revision Post revision object or array. |
429 | 429 | */ |
430 | - do_action( 'wp_delete_post_revision', $revision->ID, $revision ); |
|
430 | + do_action('wp_delete_post_revision', $revision->ID, $revision); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | return $delete; |
@@ -444,20 +444,20 @@ discard block |
||
444 | 444 | * @param array|null $args Optional. Arguments for retrieving post revisions. Default null. |
445 | 445 | * @return array An array of revisions, or an empty array if none. |
446 | 446 | */ |
447 | -function wp_get_post_revisions( $post_id = 0, $args = null ) { |
|
448 | - $post = get_post( $post_id ); |
|
449 | - if ( ! $post || empty( $post->ID ) ) |
|
447 | +function wp_get_post_revisions($post_id = 0, $args = null) { |
|
448 | + $post = get_post($post_id); |
|
449 | + if ( ! $post || empty($post->ID)) |
|
450 | 450 | return array(); |
451 | 451 | |
452 | - $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true ); |
|
453 | - $args = wp_parse_args( $args, $defaults ); |
|
452 | + $defaults = array('order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true); |
|
453 | + $args = wp_parse_args($args, $defaults); |
|
454 | 454 | |
455 | - if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) |
|
455 | + if ($args['check_enabled'] && ! wp_revisions_enabled($post)) |
|
456 | 456 | return array(); |
457 | 457 | |
458 | - $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); |
|
458 | + $args = array_merge($args, array('post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit')); |
|
459 | 459 | |
460 | - if ( ! $revisions = get_children( $args ) ) |
|
460 | + if ( ! $revisions = get_children($args)) |
|
461 | 461 | return array(); |
462 | 462 | |
463 | 463 | return $revisions; |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | * @param WP_Post $post The post object. |
472 | 472 | * @return bool True if number of revisions to keep isn't zero, false otherwise. |
473 | 473 | */ |
474 | -function wp_revisions_enabled( $post ) { |
|
475 | - return wp_revisions_to_keep( $post ) !== 0; |
|
474 | +function wp_revisions_enabled($post) { |
|
475 | + return wp_revisions_to_keep($post) !== 0; |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -488,15 +488,15 @@ discard block |
||
488 | 488 | * @param WP_Post $post The post object. |
489 | 489 | * @return int The number of revisions to keep. |
490 | 490 | */ |
491 | -function wp_revisions_to_keep( $post ) { |
|
491 | +function wp_revisions_to_keep($post) { |
|
492 | 492 | $num = WP_POST_REVISIONS; |
493 | 493 | |
494 | - if ( true === $num ) |
|
494 | + if (true === $num) |
|
495 | 495 | $num = -1; |
496 | 496 | else |
497 | - $num = intval( $num ); |
|
497 | + $num = intval($num); |
|
498 | 498 | |
499 | - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) |
|
499 | + if ( ! post_type_supports($post->post_type, 'revisions')) |
|
500 | 500 | $num = 0; |
501 | 501 | |
502 | 502 | /** |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @param int $num Number of revisions to store. |
510 | 510 | * @param WP_Post $post Post object. |
511 | 511 | */ |
512 | - return (int) apply_filters( 'wp_revisions_to_keep', $num, $post ); |
|
512 | + return (int) apply_filters('wp_revisions_to_keep', $num, $post); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -521,23 +521,23 @@ discard block |
||
521 | 521 | * @param WP_Post $post |
522 | 522 | * @return WP_Post|false |
523 | 523 | */ |
524 | -function _set_preview( $post ) { |
|
525 | - if ( ! is_object( $post ) ) { |
|
524 | +function _set_preview($post) { |
|
525 | + if ( ! is_object($post)) { |
|
526 | 526 | return $post; |
527 | 527 | } |
528 | 528 | |
529 | - $preview = wp_get_post_autosave( $post->ID ); |
|
530 | - if ( ! is_object( $preview ) ) { |
|
529 | + $preview = wp_get_post_autosave($post->ID); |
|
530 | + if ( ! is_object($preview)) { |
|
531 | 531 | return $post; |
532 | 532 | } |
533 | 533 | |
534 | - $preview = sanitize_post( $preview ); |
|
534 | + $preview = sanitize_post($preview); |
|
535 | 535 | |
536 | 536 | $post->post_content = $preview->post_content; |
537 | 537 | $post->post_title = $preview->post_title; |
538 | 538 | $post->post_excerpt = $preview->post_excerpt; |
539 | 539 | |
540 | - add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
540 | + add_filter('get_the_terms', '_wp_preview_terms_filter', 10, 3); |
|
541 | 541 | |
542 | 542 | return $post; |
543 | 543 | } |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | * @access private |
550 | 550 | */ |
551 | 551 | function _show_post_preview() { |
552 | - if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { |
|
552 | + if (isset($_GET['preview_id']) && isset($_GET['preview_nonce'])) { |
|
553 | 553 | $id = (int) $_GET['preview_id']; |
554 | 554 | |
555 | - if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) |
|
556 | - wp_die( __('You do not have permission to preview drafts.') ); |
|
555 | + if (false === wp_verify_nonce($_GET['preview_nonce'], 'post_preview_'.$id)) |
|
556 | + wp_die(__('You do not have permission to preview drafts.')); |
|
557 | 557 | |
558 | 558 | add_filter('the_preview', '_set_preview'); |
559 | 559 | } |
@@ -570,17 +570,17 @@ discard block |
||
570 | 570 | * @param string $taxonomy |
571 | 571 | * @return array |
572 | 572 | */ |
573 | -function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { |
|
574 | - if ( ! $post = get_post() ) |
|
573 | +function _wp_preview_terms_filter($terms, $post_id, $taxonomy) { |
|
574 | + if ( ! $post = get_post()) |
|
575 | 575 | return $terms; |
576 | 576 | |
577 | - if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) |
|
577 | + if (empty($_REQUEST['post_format']) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type) |
|
578 | 578 | return $terms; |
579 | 579 | |
580 | - if ( 'standard' == $_REQUEST['post_format'] ) |
|
580 | + if ('standard' == $_REQUEST['post_format']) |
|
581 | 581 | $terms = array(); |
582 | - elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) |
|
583 | - $terms = array( $term ); // Can only have one post format |
|
582 | + elseif ($term = get_term_by('slug', 'post-format-'.sanitize_key($_REQUEST['post_format']), 'post_format')) |
|
583 | + $terms = array($term); // Can only have one post format |
|
584 | 584 | |
585 | 585 | return $terms; |
586 | 586 | } |
@@ -594,13 +594,13 @@ discard block |
||
594 | 594 | * @param WP_Post $revision |
595 | 595 | * @return int|false |
596 | 596 | */ |
597 | -function _wp_get_post_revision_version( $revision ) { |
|
598 | - if ( is_object( $revision ) ) |
|
599 | - $revision = get_object_vars( $revision ); |
|
600 | - elseif ( !is_array( $revision ) ) |
|
597 | +function _wp_get_post_revision_version($revision) { |
|
598 | + if (is_object($revision)) |
|
599 | + $revision = get_object_vars($revision); |
|
600 | + elseif ( ! is_array($revision)) |
|
601 | 601 | return false; |
602 | 602 | |
603 | - if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) |
|
603 | + if (preg_match('/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches)) |
|
604 | 604 | return (int) $matches[1]; |
605 | 605 | |
606 | 606 | return 0; |
@@ -618,23 +618,23 @@ discard block |
||
618 | 618 | * @param array $revisions Current revisions of the post |
619 | 619 | * @return bool true if the revisions were upgraded, false if problems |
620 | 620 | */ |
621 | -function _wp_upgrade_revisions_of_post( $post, $revisions ) { |
|
621 | +function _wp_upgrade_revisions_of_post($post, $revisions) { |
|
622 | 622 | global $wpdb; |
623 | 623 | |
624 | 624 | // Add post option exclusively |
625 | 625 | $lock = "revision-upgrade-{$post->ID}"; |
626 | 626 | $now = time(); |
627 | - $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) ); |
|
628 | - if ( ! $result ) { |
|
627 | + $result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now)); |
|
628 | + if ( ! $result) { |
|
629 | 629 | // If we couldn't get a lock, see how old the previous lock is |
630 | - $locked = get_option( $lock ); |
|
631 | - if ( ! $locked ) { |
|
630 | + $locked = get_option($lock); |
|
631 | + if ( ! $locked) { |
|
632 | 632 | // Can't write to the lock, and can't read the lock. |
633 | 633 | // Something broken has happened |
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | - if ( $locked > $now - 3600 ) { |
|
637 | + if ($locked > $now - 3600) { |
|
638 | 638 | // Lock is not too old: some other process may be upgrading this post. Bail. |
639 | 639 | return false; |
640 | 640 | } |
@@ -643,57 +643,57 @@ discard block |
||
643 | 643 | } |
644 | 644 | |
645 | 645 | // If we could get a lock, re-"add" the option to fire all the correct filters. |
646 | - update_option( $lock, $now ); |
|
646 | + update_option($lock, $now); |
|
647 | 647 | |
648 | - reset( $revisions ); |
|
648 | + reset($revisions); |
|
649 | 649 | $add_last = true; |
650 | 650 | |
651 | 651 | do { |
652 | - $this_revision = current( $revisions ); |
|
653 | - $prev_revision = next( $revisions ); |
|
652 | + $this_revision = current($revisions); |
|
653 | + $prev_revision = next($revisions); |
|
654 | 654 | |
655 | - $this_revision_version = _wp_get_post_revision_version( $this_revision ); |
|
655 | + $this_revision_version = _wp_get_post_revision_version($this_revision); |
|
656 | 656 | |
657 | 657 | // Something terrible happened |
658 | - if ( false === $this_revision_version ) |
|
658 | + if (false === $this_revision_version) |
|
659 | 659 | continue; |
660 | 660 | |
661 | 661 | // 1 is the latest revision version, so we're already up to date. |
662 | 662 | // No need to add a copy of the post as latest revision. |
663 | - if ( 0 < $this_revision_version ) { |
|
663 | + if (0 < $this_revision_version) { |
|
664 | 664 | $add_last = false; |
665 | 665 | continue; |
666 | 666 | } |
667 | 667 | |
668 | 668 | // Always update the revision version |
669 | 669 | $update = array( |
670 | - 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ), |
|
670 | + 'post_name' => preg_replace('/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name), |
|
671 | 671 | ); |
672 | 672 | |
673 | 673 | // If this revision is the oldest revision of the post, i.e. no $prev_revision, |
674 | 674 | // the correct post_author is probably $post->post_author, but that's only a good guess. |
675 | 675 | // Update the revision version only and Leave the author as-is. |
676 | - if ( $prev_revision ) { |
|
677 | - $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); |
|
676 | + if ($prev_revision) { |
|
677 | + $prev_revision_version = _wp_get_post_revision_version($prev_revision); |
|
678 | 678 | |
679 | 679 | // If the previous revision is already up to date, it no longer has the information we need :( |
680 | - if ( $prev_revision_version < 1 ) |
|
680 | + if ($prev_revision_version < 1) |
|
681 | 681 | $update['post_author'] = $prev_revision->post_author; |
682 | 682 | } |
683 | 683 | |
684 | 684 | // Upgrade this revision |
685 | - $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); |
|
685 | + $result = $wpdb->update($wpdb->posts, $update, array('ID' => $this_revision->ID)); |
|
686 | 686 | |
687 | - if ( $result ) |
|
688 | - wp_cache_delete( $this_revision->ID, 'posts' ); |
|
687 | + if ($result) |
|
688 | + wp_cache_delete($this_revision->ID, 'posts'); |
|
689 | 689 | |
690 | - } while ( $prev_revision ); |
|
690 | + } while ($prev_revision); |
|
691 | 691 | |
692 | - delete_option( $lock ); |
|
692 | + delete_option($lock); |
|
693 | 693 | |
694 | 694 | // Add a copy of the post as latest revision. |
695 | - if ( $add_last ) |
|
696 | - wp_save_post_revision( $post->ID ); |
|
695 | + if ($add_last) |
|
696 | + wp_save_post_revision($post->ID); |
|
697 | 697 | |
698 | 698 | return true; |
699 | 699 | } |
@@ -110,20 +110,25 @@ discard block |
||
110 | 110 | * @return int|WP_Error|void Void or 0 if error, new revision ID, if success. |
111 | 111 | */ |
112 | 112 | function wp_save_post_revision( $post_id ) { |
113 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
114 | - return; |
|
113 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
114 | + return; |
|
115 | + } |
|
115 | 116 | |
116 | - if ( ! $post = get_post( $post_id ) ) |
|
117 | - return; |
|
117 | + if ( ! $post = get_post( $post_id ) ) { |
|
118 | + return; |
|
119 | + } |
|
118 | 120 | |
119 | - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) |
|
120 | - return; |
|
121 | + if ( ! post_type_supports( $post->post_type, 'revisions' ) ) { |
|
122 | + return; |
|
123 | + } |
|
121 | 124 | |
122 | - if ( 'auto-draft' == $post->post_status ) |
|
123 | - return; |
|
125 | + if ( 'auto-draft' == $post->post_status ) { |
|
126 | + return; |
|
127 | + } |
|
124 | 128 | |
125 | - if ( ! wp_revisions_enabled( $post ) ) |
|
126 | - return; |
|
129 | + if ( ! wp_revisions_enabled( $post ) ) { |
|
130 | + return; |
|
131 | + } |
|
127 | 132 | |
128 | 133 | // Compare the proposed update with the last stored revision verifying that |
129 | 134 | // they are different, unless a plugin tells us to always save regardless. |
@@ -189,21 +194,24 @@ discard block |
||
189 | 194 | // delete the oldest ones. |
190 | 195 | $revisions_to_keep = wp_revisions_to_keep( $post ); |
191 | 196 | |
192 | - if ( $revisions_to_keep < 0 ) |
|
193 | - return $return; |
|
197 | + if ( $revisions_to_keep < 0 ) { |
|
198 | + return $return; |
|
199 | + } |
|
194 | 200 | |
195 | 201 | $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); |
196 | 202 | |
197 | 203 | $delete = count($revisions) - $revisions_to_keep; |
198 | 204 | |
199 | - if ( $delete < 1 ) |
|
200 | - return $return; |
|
205 | + if ( $delete < 1 ) { |
|
206 | + return $return; |
|
207 | + } |
|
201 | 208 | |
202 | 209 | $revisions = array_slice( $revisions, 0, $delete ); |
203 | 210 | |
204 | 211 | for ( $i = 0; isset( $revisions[$i] ); $i++ ) { |
205 | - if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) |
|
206 | - continue; |
|
212 | + if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) { |
|
213 | + continue; |
|
214 | + } |
|
207 | 215 | |
208 | 216 | wp_delete_post_revision( $revisions[ $i ]->ID ); |
209 | 217 | } |
@@ -229,8 +237,9 @@ discard block |
||
229 | 237 | |
230 | 238 | foreach ( $revisions as $revision ) { |
231 | 239 | if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { |
232 | - if ( $user_id && $user_id != $revision->post_author ) |
|
233 | - continue; |
|
240 | + if ( $user_id && $user_id != $revision->post_author ) { |
|
241 | + continue; |
|
242 | + } |
|
234 | 243 | |
235 | 244 | return $revision; |
236 | 245 | } |
@@ -248,8 +257,9 @@ discard block |
||
248 | 257 | * @return false|int False if not a revision, ID of revision's parent otherwise. |
249 | 258 | */ |
250 | 259 | function wp_is_post_revision( $post ) { |
251 | - if ( !$post = wp_get_post_revision( $post ) ) |
|
252 | - return false; |
|
260 | + if ( !$post = wp_get_post_revision( $post ) ) { |
|
261 | + return false; |
|
262 | + } |
|
253 | 263 | |
254 | 264 | return (int) $post->post_parent; |
255 | 265 | } |
@@ -263,11 +273,13 @@ discard block |
||
263 | 273 | * @return false|int False if not a revision, ID of autosave's parent otherwise |
264 | 274 | */ |
265 | 275 | function wp_is_post_autosave( $post ) { |
266 | - if ( !$post = wp_get_post_revision( $post ) ) |
|
267 | - return false; |
|
276 | + if ( !$post = wp_get_post_revision( $post ) ) { |
|
277 | + return false; |
|
278 | + } |
|
268 | 279 | |
269 | - if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) |
|
270 | - return (int) $post->post_parent; |
|
280 | + if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) { |
|
281 | + return (int) $post->post_parent; |
|
282 | + } |
|
271 | 283 | |
272 | 284 | return false; |
273 | 285 | } |
@@ -283,23 +295,27 @@ discard block |
||
283 | 295 | * @return int|WP_Error WP_Error or 0 if error, new revision ID if success. |
284 | 296 | */ |
285 | 297 | function _wp_put_post_revision( $post = null, $autosave = false ) { |
286 | - if ( is_object($post) ) |
|
287 | - $post = get_object_vars( $post ); |
|
288 | - elseif ( !is_array($post) ) |
|
289 | - $post = get_post($post, ARRAY_A); |
|
298 | + if ( is_object($post) ) { |
|
299 | + $post = get_object_vars( $post ); |
|
300 | + } elseif ( !is_array($post) ) { |
|
301 | + $post = get_post($post, ARRAY_A); |
|
302 | + } |
|
290 | 303 | |
291 | - if ( ! $post || empty($post['ID']) ) |
|
292 | - return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
304 | + if ( ! $post || empty($post['ID']) ) { |
|
305 | + return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
306 | + } |
|
293 | 307 | |
294 | - if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) |
|
295 | - return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); |
|
308 | + if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) { |
|
309 | + return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); |
|
310 | + } |
|
296 | 311 | |
297 | 312 | $post = _wp_post_revision_data( $post, $autosave ); |
298 | 313 | $post = wp_slash($post); //since data is from db |
299 | 314 | |
300 | 315 | $revision_id = wp_insert_post( $post ); |
301 | - if ( is_wp_error($revision_id) ) |
|
302 | - return $revision_id; |
|
316 | + if ( is_wp_error($revision_id) ) { |
|
317 | + return $revision_id; |
|
318 | + } |
|
303 | 319 | |
304 | 320 | if ( $revision_id ) { |
305 | 321 | /** |
@@ -326,10 +342,12 @@ discard block |
||
326 | 342 | * @return WP_Post|array|null Null if error or post object if success. |
327 | 343 | */ |
328 | 344 | function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { |
329 | - if ( !$revision = get_post( $post, OBJECT, $filter ) ) |
|
330 | - return $revision; |
|
331 | - if ( 'revision' !== $revision->post_type ) |
|
332 | - return null; |
|
345 | + if ( !$revision = get_post( $post, OBJECT, $filter ) ) { |
|
346 | + return $revision; |
|
347 | + } |
|
348 | + if ( 'revision' !== $revision->post_type ) { |
|
349 | + return null; |
|
350 | + } |
|
333 | 351 | |
334 | 352 | if ( $output == OBJECT ) { |
335 | 353 | return $revision; |
@@ -356,27 +374,31 @@ discard block |
||
356 | 374 | * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success. |
357 | 375 | */ |
358 | 376 | function wp_restore_post_revision( $revision_id, $fields = null ) { |
359 | - if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) |
|
360 | - return $revision; |
|
377 | + if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) { |
|
378 | + return $revision; |
|
379 | + } |
|
361 | 380 | |
362 | - if ( !is_array( $fields ) ) |
|
363 | - $fields = array_keys( _wp_post_revision_fields( $revision ) ); |
|
381 | + if ( !is_array( $fields ) ) { |
|
382 | + $fields = array_keys( _wp_post_revision_fields( $revision ) ); |
|
383 | + } |
|
364 | 384 | |
365 | 385 | $update = array(); |
366 | 386 | foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) { |
367 | 387 | $update[$field] = $revision[$field]; |
368 | 388 | } |
369 | 389 | |
370 | - if ( !$update ) |
|
371 | - return false; |
|
390 | + if ( !$update ) { |
|
391 | + return false; |
|
392 | + } |
|
372 | 393 | |
373 | 394 | $update['ID'] = $revision['post_parent']; |
374 | 395 | |
375 | 396 | $update = wp_slash( $update ); //since data is from db |
376 | 397 | |
377 | 398 | $post_id = wp_update_post( $update ); |
378 | - if ( ! $post_id || is_wp_error( $post_id ) ) |
|
379 | - return $post_id; |
|
399 | + if ( ! $post_id || is_wp_error( $post_id ) ) { |
|
400 | + return $post_id; |
|
401 | + } |
|
380 | 402 | |
381 | 403 | // Add restore from details |
382 | 404 | $restore_details = array( |
@@ -446,19 +468,22 @@ discard block |
||
446 | 468 | */ |
447 | 469 | function wp_get_post_revisions( $post_id = 0, $args = null ) { |
448 | 470 | $post = get_post( $post_id ); |
449 | - if ( ! $post || empty( $post->ID ) ) |
|
450 | - return array(); |
|
471 | + if ( ! $post || empty( $post->ID ) ) { |
|
472 | + return array(); |
|
473 | + } |
|
451 | 474 | |
452 | 475 | $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true ); |
453 | 476 | $args = wp_parse_args( $args, $defaults ); |
454 | 477 | |
455 | - if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) |
|
456 | - return array(); |
|
478 | + if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) { |
|
479 | + return array(); |
|
480 | + } |
|
457 | 481 | |
458 | 482 | $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); |
459 | 483 | |
460 | - if ( ! $revisions = get_children( $args ) ) |
|
461 | - return array(); |
|
484 | + if ( ! $revisions = get_children( $args ) ) { |
|
485 | + return array(); |
|
486 | + } |
|
462 | 487 | |
463 | 488 | return $revisions; |
464 | 489 | } |
@@ -491,13 +516,15 @@ discard block |
||
491 | 516 | function wp_revisions_to_keep( $post ) { |
492 | 517 | $num = WP_POST_REVISIONS; |
493 | 518 | |
494 | - if ( true === $num ) |
|
495 | - $num = -1; |
|
496 | - else |
|
497 | - $num = intval( $num ); |
|
519 | + if ( true === $num ) { |
|
520 | + $num = -1; |
|
521 | + } else { |
|
522 | + $num = intval( $num ); |
|
523 | + } |
|
498 | 524 | |
499 | - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) |
|
500 | - $num = 0; |
|
525 | + if ( ! post_type_supports( $post->post_type, 'revisions' ) ) { |
|
526 | + $num = 0; |
|
527 | + } |
|
501 | 528 | |
502 | 529 | /** |
503 | 530 | * Filter the number of revisions to save for the given post. |
@@ -552,8 +579,9 @@ discard block |
||
552 | 579 | if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { |
553 | 580 | $id = (int) $_GET['preview_id']; |
554 | 581 | |
555 | - if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) |
|
556 | - wp_die( __('You do not have permission to preview drafts.') ); |
|
582 | + if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) { |
|
583 | + wp_die( __('You do not have permission to preview drafts.') ); |
|
584 | + } |
|
557 | 585 | |
558 | 586 | add_filter('the_preview', '_set_preview'); |
559 | 587 | } |
@@ -571,16 +599,20 @@ discard block |
||
571 | 599 | * @return array |
572 | 600 | */ |
573 | 601 | function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { |
574 | - if ( ! $post = get_post() ) |
|
575 | - return $terms; |
|
602 | + if ( ! $post = get_post() ) { |
|
603 | + return $terms; |
|
604 | + } |
|
576 | 605 | |
577 | - if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) |
|
578 | - return $terms; |
|
606 | + if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) { |
|
607 | + return $terms; |
|
608 | + } |
|
579 | 609 | |
580 | - if ( 'standard' == $_REQUEST['post_format'] ) |
|
581 | - $terms = array(); |
|
582 | - elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) |
|
583 | - $terms = array( $term ); // Can only have one post format |
|
610 | + if ( 'standard' == $_REQUEST['post_format'] ) { |
|
611 | + $terms = array(); |
|
612 | + } elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) { |
|
613 | + $terms = array( $term ); |
|
614 | + } |
|
615 | + // Can only have one post format |
|
584 | 616 | |
585 | 617 | return $terms; |
586 | 618 | } |
@@ -595,13 +627,15 @@ discard block |
||
595 | 627 | * @return int|false |
596 | 628 | */ |
597 | 629 | function _wp_get_post_revision_version( $revision ) { |
598 | - if ( is_object( $revision ) ) |
|
599 | - $revision = get_object_vars( $revision ); |
|
600 | - elseif ( !is_array( $revision ) ) |
|
601 | - return false; |
|
630 | + if ( is_object( $revision ) ) { |
|
631 | + $revision = get_object_vars( $revision ); |
|
632 | + } elseif ( !is_array( $revision ) ) { |
|
633 | + return false; |
|
634 | + } |
|
602 | 635 | |
603 | - if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) |
|
604 | - return (int) $matches[1]; |
|
636 | + if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) { |
|
637 | + return (int) $matches[1]; |
|
638 | + } |
|
605 | 639 | |
606 | 640 | return 0; |
607 | 641 | } |
@@ -655,8 +689,9 @@ discard block |
||
655 | 689 | $this_revision_version = _wp_get_post_revision_version( $this_revision ); |
656 | 690 | |
657 | 691 | // Something terrible happened |
658 | - if ( false === $this_revision_version ) |
|
659 | - continue; |
|
692 | + if ( false === $this_revision_version ) { |
|
693 | + continue; |
|
694 | + } |
|
660 | 695 | |
661 | 696 | // 1 is the latest revision version, so we're already up to date. |
662 | 697 | // No need to add a copy of the post as latest revision. |
@@ -677,23 +712,26 @@ discard block |
||
677 | 712 | $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); |
678 | 713 | |
679 | 714 | // If the previous revision is already up to date, it no longer has the information we need :( |
680 | - if ( $prev_revision_version < 1 ) |
|
681 | - $update['post_author'] = $prev_revision->post_author; |
|
715 | + if ( $prev_revision_version < 1 ) { |
|
716 | + $update['post_author'] = $prev_revision->post_author; |
|
717 | + } |
|
682 | 718 | } |
683 | 719 | |
684 | 720 | // Upgrade this revision |
685 | 721 | $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); |
686 | 722 | |
687 | - if ( $result ) |
|
688 | - wp_cache_delete( $this_revision->ID, 'posts' ); |
|
723 | + if ( $result ) { |
|
724 | + wp_cache_delete( $this_revision->ID, 'posts' ); |
|
725 | + } |
|
689 | 726 | |
690 | 727 | } while ( $prev_revision ); |
691 | 728 | |
692 | 729 | delete_option( $lock ); |
693 | 730 | |
694 | 731 | // Add a copy of the post as latest revision. |
695 | - if ( $add_last ) |
|
696 | - wp_save_post_revision( $post->ID ); |
|
732 | + if ( $add_last ) { |
|
733 | + wp_save_post_revision( $post->ID ); |
|
734 | + } |
|
697 | 735 | |
698 | 736 | return true; |
699 | 737 | } |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @param int $user_id User ID. |
736 | 736 | * @param string $meta_key Metadata name. |
737 | - * @param mixed $meta_value Metadata value. |
|
737 | + * @param string $meta_value Metadata value. |
|
738 | 738 | * @param bool $unique Optional, default is false. Whether the same key should not be added. |
739 | 739 | * @return int|false Meta ID on success, false on failure. |
740 | 740 | */ |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | * @since 3.0.0 |
1212 | 1212 | * |
1213 | 1213 | * @param object|WP_User $user User object to be cached |
1214 | - * @return bool|null Returns false on failure. |
|
1214 | + * @return false|null Returns false on failure. |
|
1215 | 1215 | */ |
1216 | 1216 | function update_user_caches( $user ) { |
1217 | 1217 | if ( $user instanceof WP_User ) { |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Core User API |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Users |
|
7 | - */ |
|
3 | + * Core User API |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Users |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authenticates and logs a user in with 'remember' capability. |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param bool $secure_cookie Whether to use a secure sign-on cookie. |
67 | 67 | * @param array $credentials { |
68 | - * Array of entered sign-on data. |
|
69 | - * |
|
70 | - * @type string $user_login Username. |
|
71 | - * @type string $user_password Password entered. |
|
68 | + * Array of entered sign-on data. |
|
69 | + * |
|
70 | + * @type string $user_login Username. |
|
71 | + * @type string $user_password Password entered. |
|
72 | 72 | * @type bool $remember Whether to 'remember' the user. Increases the time |
73 | 73 | * that the cookie will be kept. Default false. |
74 | - * } |
|
74 | + * } |
|
75 | 75 | */ |
76 | 76 | $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
77 | 77 | |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | * |
1164 | 1164 | * The dynamic portion of the hook name, `$field`, refers to the prefixed user |
1165 | 1165 | * field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
1166 | - * |
|
1166 | + * |
|
1167 | 1167 | * @since 2.9.0 |
1168 | 1168 | * |
1169 | 1169 | * @param mixed $value Value of the prefixed user field. |
@@ -1604,16 +1604,16 @@ discard block |
||
1604 | 1604 | $user = new WP_User( $user_id ); |
1605 | 1605 | |
1606 | 1606 | /** |
1607 | - * Filter a user's meta values and keys before the user is created or updated. |
|
1608 | - * |
|
1609 | - * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
1610 | - * |
|
1611 | - * @since 4.4.0 |
|
1612 | - * |
|
1613 | - * @param array $meta { |
|
1614 | - * Default meta values and keys for the user. |
|
1615 | - * |
|
1616 | - * @type string $nickname The user's nickname. Default is the user's username. |
|
1607 | + * Filter a user's meta values and keys before the user is created or updated. |
|
1608 | + * |
|
1609 | + * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
1610 | + * |
|
1611 | + * @since 4.4.0 |
|
1612 | + * |
|
1613 | + * @param array $meta { |
|
1614 | + * Default meta values and keys for the user. |
|
1615 | + * |
|
1616 | + * @type string $nickname The user's nickname. Default is the user's username. |
|
1617 | 1617 | * @type string $first_name The user's first name. |
1618 | 1618 | * @type string $last_name The user's last name. |
1619 | 1619 | * @type string $description The user's description. |
@@ -1624,10 +1624,10 @@ discard block |
||
1624 | 1624 | * not forced. |
1625 | 1625 | * @type bool $show_admin_bar_front Whether to show the admin bar on the front end for the user. |
1626 | 1626 | * Default true. |
1627 | - * } |
|
1627 | + * } |
|
1628 | 1628 | * @param WP_User $user User object. |
1629 | 1629 | * @param bool $update Whether the user is being updated rather than created. |
1630 | - */ |
|
1630 | + */ |
|
1631 | 1631 | $meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); |
1632 | 1632 | |
1633 | 1633 | // Update user meta. |
@@ -1962,7 +1962,7 @@ discard block |
||
1962 | 1962 | * @since 2.9.0 |
1963 | 1963 | * |
1964 | 1964 | * @param array $methods Array of contact methods and their labels. |
1965 | - * @param WP_User $user WP_User object. |
|
1965 | + * @param WP_User $user WP_User object. |
|
1966 | 1966 | */ |
1967 | 1967 | return apply_filters( 'user_contactmethods', $methods, $user ); |
1968 | 1968 | } |
@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | * @param string|bool $secure_cookie Optional. Whether to use secure cookie. |
26 | 26 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
27 | 27 | */ |
28 | -function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
|
29 | - if ( empty($credentials) ) { |
|
30 | - if ( ! empty($_POST['log']) ) |
|
28 | +function wp_signon($credentials = array(), $secure_cookie = '') { |
|
29 | + if (empty($credentials)) { |
|
30 | + if ( ! empty($_POST['log'])) |
|
31 | 31 | $credentials['user_login'] = $_POST['log']; |
32 | - if ( ! empty($_POST['pwd']) ) |
|
32 | + if ( ! empty($_POST['pwd'])) |
|
33 | 33 | $credentials['user_password'] = $_POST['pwd']; |
34 | - if ( ! empty($_POST['rememberme']) ) |
|
34 | + if ( ! empty($_POST['rememberme'])) |
|
35 | 35 | $credentials['remember'] = $_POST['rememberme']; |
36 | 36 | } |
37 | 37 | |
38 | - if ( !empty($credentials['remember']) ) |
|
38 | + if ( ! empty($credentials['remember'])) |
|
39 | 39 | $credentials['remember'] = true; |
40 | 40 | else |
41 | 41 | $credentials['remember'] = false; |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * @param string $user_login Username, passed by reference. |
54 | 54 | * @param string $user_password User password, passed by reference. |
55 | 55 | */ |
56 | - do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
|
56 | + do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password'])); |
|
57 | 57 | |
58 | - if ( '' === $secure_cookie ) |
|
58 | + if ('' === $secure_cookie) |
|
59 | 59 | $secure_cookie = is_ssl(); |
60 | 60 | |
61 | 61 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * that the cookie will be kept. Default false. |
74 | 74 | * } |
75 | 75 | */ |
76 | - $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
|
76 | + $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials); |
|
77 | 77 | |
78 | 78 | global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie |
79 | 79 | $auth_secure_cookie = $secure_cookie; |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | |
83 | 83 | $user = wp_authenticate($credentials['user_login'], $credentials['user_password']); |
84 | 84 | |
85 | - if ( is_wp_error($user) ) { |
|
86 | - if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) { |
|
85 | + if (is_wp_error($user)) { |
|
86 | + if ($user->get_error_codes() == array('empty_username', 'empty_password')) { |
|
87 | 87 | $user = new WP_Error('', ''); |
88 | 88 | } |
89 | 89 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $user_login Username. |
100 | 100 | * @param WP_User $user WP_User object of the logged-in user. |
101 | 101 | */ |
102 | - do_action( 'wp_login', $user->user_login, $user ); |
|
102 | + do_action('wp_login', $user->user_login, $user); |
|
103 | 103 | return $user; |
104 | 104 | } |
105 | 105 | |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
115 | 115 | */ |
116 | 116 | function wp_authenticate_username_password($user, $username, $password) { |
117 | - if ( $user instanceof WP_User ) { |
|
117 | + if ($user instanceof WP_User) { |
|
118 | 118 | return $user; |
119 | 119 | } |
120 | 120 | |
121 | - if ( empty($username) || empty($password) ) { |
|
122 | - if ( is_wp_error( $user ) ) |
|
121 | + if (empty($username) || empty($password)) { |
|
122 | + if (is_wp_error($user)) |
|
123 | 123 | return $user; |
124 | 124 | |
125 | 125 | $error = new WP_Error(); |
126 | 126 | |
127 | - if ( empty($username) ) |
|
127 | + if (empty($username)) |
|
128 | 128 | $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
129 | 129 | |
130 | - if ( empty($password) ) |
|
130 | + if (empty($password)) |
|
131 | 131 | $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
132 | 132 | |
133 | 133 | return $error; |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | |
136 | 136 | $user = get_user_by('login', $username); |
137 | 137 | |
138 | - if ( !$user ) { |
|
139 | - return new WP_Error( 'invalid_username', |
|
140 | - __( '<strong>ERROR</strong>: Invalid username.' ) . |
|
141 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
142 | - __( 'Lost your password?' ) . |
|
138 | + if ( ! $user) { |
|
139 | + return new WP_Error('invalid_username', |
|
140 | + __('<strong>ERROR</strong>: Invalid username.'). |
|
141 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
142 | + __('Lost your password?'). |
|
143 | 143 | '</a>' |
144 | 144 | ); |
145 | 145 | } |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * callback failed authentication. |
154 | 154 | * @param string $password Password to check against the user. |
155 | 155 | */ |
156 | - $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
157 | - if ( is_wp_error($user) ) |
|
156 | + $user = apply_filters('wp_authenticate_user', $user, $password); |
|
157 | + if (is_wp_error($user)) |
|
158 | 158 | return $user; |
159 | 159 | |
160 | - if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
|
161 | - return new WP_Error( 'incorrect_password', |
|
160 | + if ( ! wp_check_password($password, $user->user_pass, $user->ID)) { |
|
161 | + return new WP_Error('incorrect_password', |
|
162 | 162 | sprintf( |
163 | 163 | /* translators: %s: user name */ |
164 | - __( '<strong>ERROR</strong>: The password you entered for the username %s is incorrect.' ), |
|
165 | - '<strong>' . $username . '</strong>' |
|
166 | - ) . |
|
167 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
168 | - __( 'Lost your password?' ) . |
|
164 | + __('<strong>ERROR</strong>: The password you entered for the username %s is incorrect.'), |
|
165 | + '<strong>'.$username.'</strong>' |
|
166 | + ). |
|
167 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
168 | + __('Lost your password?'). |
|
169 | 169 | '</a>' |
170 | 170 | ); |
171 | 171 | } |
@@ -184,60 +184,60 @@ discard block |
||
184 | 184 | * @param string $password Password for authentication. |
185 | 185 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
186 | 186 | */ |
187 | -function wp_authenticate_email_password( $user, $email, $password ) { |
|
188 | - if ( $user instanceof WP_User ) { |
|
187 | +function wp_authenticate_email_password($user, $email, $password) { |
|
188 | + if ($user instanceof WP_User) { |
|
189 | 189 | return $user; |
190 | 190 | } |
191 | 191 | |
192 | - if ( empty( $email ) || empty( $password ) ) { |
|
193 | - if ( is_wp_error( $user ) ) { |
|
192 | + if (empty($email) || empty($password)) { |
|
193 | + if (is_wp_error($user)) { |
|
194 | 194 | return $user; |
195 | 195 | } |
196 | 196 | |
197 | 197 | $error = new WP_Error(); |
198 | 198 | |
199 | - if ( empty( $email ) ) { |
|
200 | - $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon() |
|
199 | + if (empty($email)) { |
|
200 | + $error->add('empty_username', __('<strong>ERROR</strong>: The email field is empty.')); // Uses 'empty_username' for back-compat with wp_signon() |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( empty( $password ) ) { |
|
204 | - $error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); |
|
203 | + if (empty($password)) { |
|
204 | + $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $error; |
208 | 208 | } |
209 | 209 | |
210 | - if ( ! is_email( $email ) ) { |
|
210 | + if ( ! is_email($email)) { |
|
211 | 211 | return $user; |
212 | 212 | } |
213 | 213 | |
214 | - $user = get_user_by( 'email', $email ); |
|
214 | + $user = get_user_by('email', $email); |
|
215 | 215 | |
216 | - if ( ! $user ) { |
|
217 | - return new WP_Error( 'invalid_email', |
|
218 | - __( '<strong>ERROR</strong>: Invalid email address.' ) . |
|
219 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
220 | - __( 'Lost your password?' ) . |
|
216 | + if ( ! $user) { |
|
217 | + return new WP_Error('invalid_email', |
|
218 | + __('<strong>ERROR</strong>: Invalid email address.'). |
|
219 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
220 | + __('Lost your password?'). |
|
221 | 221 | '</a>' |
222 | 222 | ); |
223 | 223 | } |
224 | 224 | |
225 | 225 | /** This filter is documented in wp-includes/user.php */ |
226 | - $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
226 | + $user = apply_filters('wp_authenticate_user', $user, $password); |
|
227 | 227 | |
228 | - if ( is_wp_error( $user ) ) { |
|
228 | + if (is_wp_error($user)) { |
|
229 | 229 | return $user; |
230 | 230 | } |
231 | 231 | |
232 | - if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
|
233 | - return new WP_Error( 'incorrect_password', |
|
232 | + if ( ! wp_check_password($password, $user->user_pass, $user->ID)) { |
|
233 | + return new WP_Error('incorrect_password', |
|
234 | 234 | sprintf( |
235 | 235 | /* translators: %s: email address */ |
236 | - __( '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.' ), |
|
237 | - '<strong>' . $email . '</strong>' |
|
238 | - ) . |
|
239 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
240 | - __( 'Lost your password?' ) . |
|
236 | + __('<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.'), |
|
237 | + '<strong>'.$email.'</strong>' |
|
238 | + ). |
|
239 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
240 | + __('Lost your password?'). |
|
241 | 241 | '</a>' |
242 | 242 | ); |
243 | 243 | } |
@@ -258,23 +258,23 @@ discard block |
||
258 | 258 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
259 | 259 | */ |
260 | 260 | function wp_authenticate_cookie($user, $username, $password) { |
261 | - if ( $user instanceof WP_User ) { |
|
261 | + if ($user instanceof WP_User) { |
|
262 | 262 | return $user; |
263 | 263 | } |
264 | 264 | |
265 | - if ( empty($username) && empty($password) ) { |
|
265 | + if (empty($username) && empty($password)) { |
|
266 | 266 | $user_id = wp_validate_auth_cookie(); |
267 | - if ( $user_id ) |
|
267 | + if ($user_id) |
|
268 | 268 | return new WP_User($user_id); |
269 | 269 | |
270 | 270 | global $auth_secure_cookie; |
271 | 271 | |
272 | - if ( $auth_secure_cookie ) |
|
272 | + if ($auth_secure_cookie) |
|
273 | 273 | $auth_cookie = SECURE_AUTH_COOKIE; |
274 | 274 | else |
275 | 275 | $auth_cookie = AUTH_COOKIE; |
276 | 276 | |
277 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
277 | + if ( ! empty($_COOKIE[$auth_cookie])) |
|
278 | 278 | return new WP_Error('expired_session', __('Please log in again.')); |
279 | 279 | |
280 | 280 | // If the cookie is not set, be silent. |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
293 | 293 | * @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer. |
294 | 294 | */ |
295 | -function wp_authenticate_spam_check( $user ) { |
|
296 | - if ( $user instanceof WP_User && is_multisite() ) { |
|
295 | +function wp_authenticate_spam_check($user) { |
|
296 | + if ($user instanceof WP_User && is_multisite()) { |
|
297 | 297 | /** |
298 | 298 | * Filter whether the user has been marked as a spammer. |
299 | 299 | * |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | * @param bool $spammed Whether the user is considered a spammer. |
303 | 303 | * @param WP_User $user User to check against. |
304 | 304 | */ |
305 | - $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
|
305 | + $spammed = apply_filters('check_is_user_spammed', is_user_spammy(), $user); |
|
306 | 306 | |
307 | - if ( $spammed ) |
|
308 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
307 | + if ($spammed) |
|
308 | + return new WP_Error('spammer_account', __('<strong>ERROR</strong>: Your account has been marked as a spammer.')); |
|
309 | 309 | } |
310 | 310 | return $user; |
311 | 311 | } |
@@ -325,16 +325,16 @@ discard block |
||
325 | 325 | * @return int|false User ID if validated, false otherwise. If a user ID from |
326 | 326 | * an earlier filter callback is received, that value is returned. |
327 | 327 | */ |
328 | -function wp_validate_logged_in_cookie( $user_id ) { |
|
329 | - if ( $user_id ) { |
|
328 | +function wp_validate_logged_in_cookie($user_id) { |
|
329 | + if ($user_id) { |
|
330 | 330 | return $user_id; |
331 | 331 | } |
332 | 332 | |
333 | - if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) { |
|
333 | + if (is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE])) { |
|
334 | 334 | return false; |
335 | 335 | } |
336 | 336 | |
337 | - return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ); |
|
337 | + return wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in'); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @param bool $public_only Optional. Whether to only return counts for public posts. Default false. |
353 | 353 | * @return string Number of posts the user has written in this post type. |
354 | 354 | */ |
355 | -function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { |
|
355 | +function count_user_posts($userid, $post_type = 'post', $public_only = false) { |
|
356 | 356 | global $wpdb; |
357 | 357 | |
358 | - $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); |
|
358 | + $where = get_posts_by_author_sql($post_type, true, $userid, $public_only); |
|
359 | 359 | |
360 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
|
360 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts $where"); |
|
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Filter the number of posts a user has written. |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param string|array $post_type Single post type or array of post types to count the number of posts for. |
372 | 372 | * @param bool $public_only Whether to limit counted posts to public posts. |
373 | 373 | */ |
374 | - return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only ); |
|
374 | + return apply_filters('get_usernumposts', $count, $userid, $post_type, $public_only); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -386,24 +386,24 @@ discard block |
||
386 | 386 | * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
387 | 387 | * @return array Amount of posts each user has written. |
388 | 388 | */ |
389 | -function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
|
389 | +function count_many_users_posts($users, $post_type = 'post', $public_only = false) { |
|
390 | 390 | global $wpdb; |
391 | 391 | |
392 | 392 | $count = array(); |
393 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
393 | + if (empty($users) || ! is_array($users)) |
|
394 | 394 | return $count; |
395 | 395 | |
396 | - $userlist = implode( ',', array_map( 'absint', $users ) ); |
|
397 | - $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
|
396 | + $userlist = implode(',', array_map('absint', $users)); |
|
397 | + $where = get_posts_by_author_sql($post_type, true, null, $public_only); |
|
398 | 398 | |
399 | - $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
|
400 | - foreach ( $result as $row ) { |
|
401 | - $count[ $row[0] ] = $row[1]; |
|
399 | + $result = $wpdb->get_results("SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N); |
|
400 | + foreach ($result as $row) { |
|
401 | + $count[$row[0]] = $row[1]; |
|
402 | 402 | } |
403 | 403 | |
404 | - foreach ( $users as $id ) { |
|
405 | - if ( ! isset( $count[ $id ] ) ) |
|
406 | - $count[ $id ] = 0; |
|
404 | + foreach ($users as $id) { |
|
405 | + if ( ! isset($count[$id])) |
|
406 | + $count[$id] = 0; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | return $count; |
@@ -421,10 +421,10 @@ discard block |
||
421 | 421 | * @return int The current user's ID |
422 | 422 | */ |
423 | 423 | function get_current_user_id() { |
424 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
424 | + if ( ! function_exists('wp_get_current_user')) |
|
425 | 425 | return 0; |
426 | 426 | $user = wp_get_current_user(); |
427 | - return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
|
427 | + return (isset($user->ID) ? (int) $user->ID : 0); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -446,23 +446,23 @@ discard block |
||
446 | 446 | * @param string $deprecated Use get_option() to check for an option in the options table. |
447 | 447 | * @return mixed User option value on success, false on failure. |
448 | 448 | */ |
449 | -function get_user_option( $option, $user = 0, $deprecated = '' ) { |
|
449 | +function get_user_option($option, $user = 0, $deprecated = '') { |
|
450 | 450 | global $wpdb; |
451 | 451 | |
452 | - if ( !empty( $deprecated ) ) |
|
453 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
452 | + if ( ! empty($deprecated)) |
|
453 | + _deprecated_argument(__FUNCTION__, '3.0'); |
|
454 | 454 | |
455 | - if ( empty( $user ) ) |
|
455 | + if (empty($user)) |
|
456 | 456 | $user = get_current_user_id(); |
457 | 457 | |
458 | - if ( ! $user = get_userdata( $user ) ) |
|
458 | + if ( ! $user = get_userdata($user)) |
|
459 | 459 | return false; |
460 | 460 | |
461 | 461 | $prefix = $wpdb->get_blog_prefix(); |
462 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
463 | - $result = $user->get( $prefix . $option ); |
|
464 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
465 | - $result = $user->get( $option ); |
|
462 | + if ($user->has_prop($prefix.$option)) // Blog specific |
|
463 | + $result = $user->get($prefix.$option); |
|
464 | + elseif ($user->has_prop($option)) // User specific and cross-blog |
|
465 | + $result = $user->get($option); |
|
466 | 466 | else |
467 | 467 | $result = false; |
468 | 468 | |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @param string $option Name of the option being retrieved. |
478 | 478 | * @param WP_User $user WP_User object of the user whose option is being retrieved. |
479 | 479 | */ |
480 | - return apply_filters( "get_user_option_{$option}", $result, $option, $user ); |
|
480 | + return apply_filters("get_user_option_{$option}", $result, $option, $user); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -501,13 +501,13 @@ discard block |
||
501 | 501 | * @return int|bool User meta ID if the option didn't exist, true on successful update, |
502 | 502 | * false on failure. |
503 | 503 | */ |
504 | -function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
|
504 | +function update_user_option($user_id, $option_name, $newvalue, $global = false) { |
|
505 | 505 | global $wpdb; |
506 | 506 | |
507 | - if ( !$global ) |
|
508 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
507 | + if ( ! $global) |
|
508 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
509 | 509 | |
510 | - return update_user_meta( $user_id, $option_name, $newvalue ); |
|
510 | + return update_user_meta($user_id, $option_name, $newvalue); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -527,12 +527,12 @@ discard block |
||
527 | 527 | * Default false (blog specific). |
528 | 528 | * @return bool True on success, false on failure. |
529 | 529 | */ |
530 | -function delete_user_option( $user_id, $option_name, $global = false ) { |
|
530 | +function delete_user_option($user_id, $option_name, $global = false) { |
|
531 | 531 | global $wpdb; |
532 | 532 | |
533 | - if ( !$global ) |
|
534 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
535 | - return delete_user_meta( $user_id, $option_name ); |
|
533 | + if ( ! $global) |
|
534 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
535 | + return delete_user_meta($user_id, $option_name); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -546,9 +546,9 @@ discard block |
||
546 | 546 | * for more information on accepted arguments. |
547 | 547 | * @return array List of users. |
548 | 548 | */ |
549 | -function get_users( $args = array() ) { |
|
549 | +function get_users($args = array()) { |
|
550 | 550 | |
551 | - $args = wp_parse_args( $args ); |
|
551 | + $args = wp_parse_args($args); |
|
552 | 552 | $args['count_total'] = false; |
553 | 553 | |
554 | 554 | $user_search = new WP_User_Query($args); |
@@ -569,40 +569,40 @@ discard block |
||
569 | 569 | * @return array A list of the user's blogs. An empty array if the user doesn't exist |
570 | 570 | * or belongs to no blogs. |
571 | 571 | */ |
572 | -function get_blogs_of_user( $user_id, $all = false ) { |
|
572 | +function get_blogs_of_user($user_id, $all = false) { |
|
573 | 573 | global $wpdb; |
574 | 574 | |
575 | 575 | $user_id = (int) $user_id; |
576 | 576 | |
577 | 577 | // Logged out users can't have blogs |
578 | - if ( empty( $user_id ) ) |
|
578 | + if (empty($user_id)) |
|
579 | 579 | return array(); |
580 | 580 | |
581 | - $keys = get_user_meta( $user_id ); |
|
582 | - if ( empty( $keys ) ) |
|
581 | + $keys = get_user_meta($user_id); |
|
582 | + if (empty($keys)) |
|
583 | 583 | return array(); |
584 | 584 | |
585 | - if ( ! is_multisite() ) { |
|
585 | + if ( ! is_multisite()) { |
|
586 | 586 | $blog_id = get_current_blog_id(); |
587 | - $blogs = array( $blog_id => new stdClass ); |
|
588 | - $blogs[ $blog_id ]->userblog_id = $blog_id; |
|
589 | - $blogs[ $blog_id ]->blogname = get_option('blogname'); |
|
590 | - $blogs[ $blog_id ]->domain = ''; |
|
591 | - $blogs[ $blog_id ]->path = ''; |
|
592 | - $blogs[ $blog_id ]->site_id = 1; |
|
593 | - $blogs[ $blog_id ]->siteurl = get_option('siteurl'); |
|
594 | - $blogs[ $blog_id ]->archived = 0; |
|
595 | - $blogs[ $blog_id ]->spam = 0; |
|
596 | - $blogs[ $blog_id ]->deleted = 0; |
|
587 | + $blogs = array($blog_id => new stdClass); |
|
588 | + $blogs[$blog_id]->userblog_id = $blog_id; |
|
589 | + $blogs[$blog_id]->blogname = get_option('blogname'); |
|
590 | + $blogs[$blog_id]->domain = ''; |
|
591 | + $blogs[$blog_id]->path = ''; |
|
592 | + $blogs[$blog_id]->site_id = 1; |
|
593 | + $blogs[$blog_id]->siteurl = get_option('siteurl'); |
|
594 | + $blogs[$blog_id]->archived = 0; |
|
595 | + $blogs[$blog_id]->spam = 0; |
|
596 | + $blogs[$blog_id]->deleted = 0; |
|
597 | 597 | return $blogs; |
598 | 598 | } |
599 | 599 | |
600 | 600 | $blogs = array(); |
601 | 601 | |
602 | - if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { |
|
603 | - $blog = get_blog_details( 1 ); |
|
604 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
605 | - $blogs[ 1 ] = (object) array( |
|
602 | + if (isset($keys[$wpdb->base_prefix.'capabilities']) && defined('MULTISITE')) { |
|
603 | + $blog = get_blog_details(1); |
|
604 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
605 | + $blogs[1] = (object) array( |
|
606 | 606 | 'userblog_id' => 1, |
607 | 607 | 'blogname' => $blog->blogname, |
608 | 608 | 'domain' => $blog->domain, |
@@ -615,24 +615,24 @@ discard block |
||
615 | 615 | 'deleted' => $blog->deleted, |
616 | 616 | ); |
617 | 617 | } |
618 | - unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); |
|
618 | + unset($keys[$wpdb->base_prefix.'capabilities']); |
|
619 | 619 | } |
620 | 620 | |
621 | - $keys = array_keys( $keys ); |
|
621 | + $keys = array_keys($keys); |
|
622 | 622 | |
623 | - foreach ( $keys as $key ) { |
|
624 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
623 | + foreach ($keys as $key) { |
|
624 | + if ('capabilities' !== substr($key, -12)) |
|
625 | 625 | continue; |
626 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
626 | + if ($wpdb->base_prefix && 0 !== strpos($key, $wpdb->base_prefix)) |
|
627 | 627 | continue; |
628 | - $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
|
629 | - if ( ! is_numeric( $blog_id ) ) |
|
628 | + $blog_id = str_replace(array($wpdb->base_prefix, '_capabilities'), '', $key); |
|
629 | + if ( ! is_numeric($blog_id)) |
|
630 | 630 | continue; |
631 | 631 | |
632 | 632 | $blog_id = (int) $blog_id; |
633 | - $blog = get_blog_details( $blog_id ); |
|
634 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
635 | - $blogs[ $blog_id ] = (object) array( |
|
633 | + $blog = get_blog_details($blog_id); |
|
634 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
635 | + $blogs[$blog_id] = (object) array( |
|
636 | 636 | 'userblog_id' => $blog_id, |
637 | 637 | 'blogname' => $blog->blogname, |
638 | 638 | 'domain' => $blog->domain, |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | * @param bool $all Whether the returned blogs array should contain all blogs, including |
658 | 658 | * those marked 'deleted', 'archived', or 'spam'. Default false. |
659 | 659 | */ |
660 | - return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all ); |
|
660 | + return apply_filters('get_blogs_of_user', $blogs, $user_id, $all); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -669,55 +669,55 @@ discard block |
||
669 | 669 | * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site. |
670 | 670 | * @return bool |
671 | 671 | */ |
672 | -function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { |
|
672 | +function is_user_member_of_blog($user_id = 0, $blog_id = 0) { |
|
673 | 673 | global $wpdb; |
674 | 674 | |
675 | 675 | $user_id = (int) $user_id; |
676 | 676 | $blog_id = (int) $blog_id; |
677 | 677 | |
678 | - if ( empty( $user_id ) ) { |
|
678 | + if (empty($user_id)) { |
|
679 | 679 | $user_id = get_current_user_id(); |
680 | 680 | } |
681 | 681 | |
682 | 682 | // Technically not needed, but does save calls to get_blog_details and get_user_meta |
683 | 683 | // in the event that the function is called when a user isn't logged in |
684 | - if ( empty( $user_id ) ) { |
|
684 | + if (empty($user_id)) { |
|
685 | 685 | return false; |
686 | 686 | } else { |
687 | - $user = get_userdata( $user_id ); |
|
688 | - if ( ! $user instanceof WP_User ) { |
|
687 | + $user = get_userdata($user_id); |
|
688 | + if ( ! $user instanceof WP_User) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - if ( ! is_multisite() ) { |
|
693 | + if ( ! is_multisite()) { |
|
694 | 694 | return true; |
695 | 695 | } |
696 | 696 | |
697 | - if ( empty( $blog_id ) ) { |
|
697 | + if (empty($blog_id)) { |
|
698 | 698 | $blog_id = get_current_blog_id(); |
699 | 699 | } |
700 | 700 | |
701 | - $blog = get_blog_details( $blog_id ); |
|
701 | + $blog = get_blog_details($blog_id); |
|
702 | 702 | |
703 | - if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) { |
|
703 | + if ( ! $blog || ! isset($blog->domain) || $blog->archived || $blog->spam || $blog->deleted) { |
|
704 | 704 | return false; |
705 | 705 | } |
706 | 706 | |
707 | - $keys = get_user_meta( $user_id ); |
|
708 | - if ( empty( $keys ) ) { |
|
707 | + $keys = get_user_meta($user_id); |
|
708 | + if (empty($keys)) { |
|
709 | 709 | return false; |
710 | 710 | } |
711 | 711 | |
712 | 712 | // no underscore before capabilities in $base_capabilities_key |
713 | - $base_capabilities_key = $wpdb->base_prefix . 'capabilities'; |
|
714 | - $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; |
|
713 | + $base_capabilities_key = $wpdb->base_prefix.'capabilities'; |
|
714 | + $site_capabilities_key = $wpdb->base_prefix.$blog_id.'_capabilities'; |
|
715 | 715 | |
716 | - if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1 ) { |
|
716 | + if (isset($keys[$base_capabilities_key]) && $blog_id == 1) { |
|
717 | 717 | return true; |
718 | 718 | } |
719 | 719 | |
720 | - if ( isset( $keys[ $site_capabilities_key ] ) ) { |
|
720 | + if (isset($keys[$site_capabilities_key])) { |
|
721 | 721 | return true; |
722 | 722 | } |
723 | 723 | |
@@ -821,24 +821,24 @@ discard block |
||
821 | 821 | $blog_prefix = $wpdb->get_blog_prefix($id); |
822 | 822 | $result = array(); |
823 | 823 | |
824 | - if ( 'time' == $strategy ) { |
|
824 | + if ('time' == $strategy) { |
|
825 | 825 | $avail_roles = wp_roles()->get_names(); |
826 | 826 | |
827 | 827 | // Build a CPU-intensive query that will return concise information. |
828 | 828 | $select_count = array(); |
829 | - foreach ( $avail_roles as $this_role => $name ) { |
|
830 | - $select_count[] = $wpdb->prepare( "COUNT(NULLIF(`meta_value` LIKE %s, false))", '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%'); |
|
829 | + foreach ($avail_roles as $this_role => $name) { |
|
830 | + $select_count[] = $wpdb->prepare("COUNT(NULLIF(`meta_value` LIKE %s, false))", '%'.$wpdb->esc_like('"'.$this_role.'"').'%'); |
|
831 | 831 | } |
832 | 832 | $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))"; |
833 | 833 | $select_count = implode(', ', $select_count); |
834 | 834 | |
835 | 835 | // Add the meta_value index to the selection list, then run the query. |
836 | - $row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); |
|
836 | + $row = $wpdb->get_row("SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N); |
|
837 | 837 | |
838 | 838 | // Run the previous loop again to associate results with role names. |
839 | 839 | $col = 0; |
840 | 840 | $role_counts = array(); |
841 | - foreach ( $avail_roles as $this_role => $name ) { |
|
841 | + foreach ($avail_roles as $this_role => $name) { |
|
842 | 842 | $count = (int) $row[$col++]; |
843 | 843 | if ($count > 0) { |
844 | 844 | $role_counts[$this_role] = $count; |
@@ -851,23 +851,23 @@ discard block |
||
851 | 851 | $total_users = (int) $row[$col]; |
852 | 852 | |
853 | 853 | $result['total_users'] = $total_users; |
854 | - $result['avail_roles'] =& $role_counts; |
|
854 | + $result['avail_roles'] = & $role_counts; |
|
855 | 855 | } else { |
856 | 856 | $avail_roles = array( |
857 | 857 | 'none' => 0, |
858 | 858 | ); |
859 | 859 | |
860 | - $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" ); |
|
860 | + $users_of_blog = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'"); |
|
861 | 861 | |
862 | - foreach ( $users_of_blog as $caps_meta ) { |
|
862 | + foreach ($users_of_blog as $caps_meta) { |
|
863 | 863 | $b_roles = maybe_unserialize($caps_meta); |
864 | - if ( ! is_array( $b_roles ) ) |
|
864 | + if ( ! is_array($b_roles)) |
|
865 | 865 | continue; |
866 | - if ( empty( $b_roles ) ) { |
|
866 | + if (empty($b_roles)) { |
|
867 | 867 | $avail_roles['none']++; |
868 | 868 | } |
869 | - foreach ( $b_roles as $b_role => $val ) { |
|
870 | - if ( isset($avail_roles[$b_role]) ) { |
|
869 | + foreach ($b_roles as $b_role => $val) { |
|
870 | + if (isset($avail_roles[$b_role])) { |
|
871 | 871 | $avail_roles[$b_role]++; |
872 | 872 | } else { |
873 | 873 | $avail_roles[$b_role] = 1; |
@@ -875,11 +875,11 @@ discard block |
||
875 | 875 | } |
876 | 876 | } |
877 | 877 | |
878 | - $result['total_users'] = count( $users_of_blog ); |
|
879 | - $result['avail_roles'] =& $avail_roles; |
|
878 | + $result['total_users'] = count($users_of_blog); |
|
879 | + $result['avail_roles'] = & $avail_roles; |
|
880 | 880 | } |
881 | 881 | |
882 | - if ( is_multisite() ) { |
|
882 | + if (is_multisite()) { |
|
883 | 883 | $result['avail_roles']['none'] = 0; |
884 | 884 | } |
885 | 885 | |
@@ -910,11 +910,11 @@ discard block |
||
910 | 910 | function setup_userdata($for_user_id = '') { |
911 | 911 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
912 | 912 | |
913 | - if ( '' == $for_user_id ) |
|
913 | + if ('' == $for_user_id) |
|
914 | 914 | $for_user_id = get_current_user_id(); |
915 | - $user = get_userdata( $for_user_id ); |
|
915 | + $user = get_userdata($for_user_id); |
|
916 | 916 | |
917 | - if ( ! $user ) { |
|
917 | + if ( ! $user) { |
|
918 | 918 | $user_ID = 0; |
919 | 919 | $user_level = 0; |
920 | 920 | $userdata = null; |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | * } |
989 | 989 | * @return string String of HTML content. |
990 | 990 | */ |
991 | -function wp_dropdown_users( $args = '' ) { |
|
991 | +function wp_dropdown_users($args = '') { |
|
992 | 992 | $defaults = array( |
993 | 993 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
994 | 994 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -999,16 +999,16 @@ discard block |
||
999 | 999 | 'option_none_value' => -1 |
1000 | 1000 | ); |
1001 | 1001 | |
1002 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
1002 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
1003 | 1003 | |
1004 | - $r = wp_parse_args( $args, $defaults ); |
|
1004 | + $r = wp_parse_args($args, $defaults); |
|
1005 | 1005 | |
1006 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
1006 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
1007 | 1007 | |
1008 | - $fields = array( 'ID', 'user_login' ); |
|
1008 | + $fields = array('ID', 'user_login'); |
|
1009 | 1009 | |
1010 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
1011 | - if ( 'display_name_with_login' === $show ) { |
|
1010 | + $show = ! empty($r['show']) ? $r['show'] : 'display_name'; |
|
1011 | + if ('display_name_with_login' === $show) { |
|
1012 | 1012 | $fields[] = 'display_name'; |
1013 | 1013 | } else { |
1014 | 1014 | $fields[] = $show; |
@@ -1028,56 +1028,56 @@ discard block |
||
1028 | 1028 | * @param array $query_args The query arguments for wp_dropdown_users(). |
1029 | 1029 | * @param array $r The default arguments for wp_dropdown_users(). |
1030 | 1030 | */ |
1031 | - $query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $r ); |
|
1031 | + $query_args = apply_filters('wp_dropdown_users_args', $query_args, $r); |
|
1032 | 1032 | |
1033 | - $users = get_users( $query_args ); |
|
1033 | + $users = get_users($query_args); |
|
1034 | 1034 | |
1035 | 1035 | $output = ''; |
1036 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
1037 | - $name = esc_attr( $r['name'] ); |
|
1038 | - if ( $r['multi'] && ! $r['id'] ) { |
|
1036 | + if ( ! empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
1037 | + $name = esc_attr($r['name']); |
|
1038 | + if ($r['multi'] && ! $r['id']) { |
|
1039 | 1039 | $id = ''; |
1040 | 1040 | } else { |
1041 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
1041 | + $id = $r['id'] ? " id='".esc_attr($r['id'])."'" : " id='$name'"; |
|
1042 | 1042 | } |
1043 | - $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
|
1043 | + $output = "<select name='{$name}'{$id} class='".$r['class']."'>\n"; |
|
1044 | 1044 | |
1045 | - if ( $show_option_all ) { |
|
1045 | + if ($show_option_all) { |
|
1046 | 1046 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - if ( $show_option_none ) { |
|
1050 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
1051 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
1049 | + if ($show_option_none) { |
|
1050 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
1051 | + $output .= "\t<option value='".esc_attr($option_none_value)."'$_selected>$show_option_none</option>\n"; |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
1054 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
1055 | 1055 | $found_selected = false; |
1056 | 1056 | $r['selected'] = (int) $r['selected']; |
1057 | - foreach ( (array) $users as $user ) { |
|
1057 | + foreach ((array) $users as $user) { |
|
1058 | 1058 | $user->ID = (int) $user->ID; |
1059 | - if ( $user->ID === $r['selected'] ) { |
|
1059 | + if ($user->ID === $r['selected']) { |
|
1060 | 1060 | $found_selected = true; |
1061 | 1061 | } |
1062 | 1062 | } |
1063 | 1063 | |
1064 | - if ( ! $found_selected ) { |
|
1065 | - $users[] = get_userdata( $r['selected'] ); |
|
1064 | + if ( ! $found_selected) { |
|
1065 | + $users[] = get_userdata($r['selected']); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - foreach ( (array) $users as $user ) { |
|
1070 | - if ( 'display_name_with_login' === $show ) { |
|
1069 | + foreach ((array) $users as $user) { |
|
1070 | + if ('display_name_with_login' === $show) { |
|
1071 | 1071 | /* translators: 1: display name, 2: user_login */ |
1072 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
1073 | - } elseif ( ! empty( $user->$show ) ) { |
|
1072 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
1073 | + } elseif ( ! empty($user->$show)) { |
|
1074 | 1074 | $display = $user->$show; |
1075 | 1075 | } else { |
1076 | - $display = '(' . $user->user_login . ')'; |
|
1076 | + $display = '('.$user->user_login.')'; |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
1080 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
1079 | + $_selected = selected($user->ID, $r['selected'], false); |
|
1080 | + $output .= "\t<option value='$user->ID'$_selected>".esc_html($display)."</option>\n"; |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | $output .= "</select>"; |
@@ -1090,9 +1090,9 @@ discard block |
||
1090 | 1090 | * |
1091 | 1091 | * @param string $output HTML output generated by wp_dropdown_users(). |
1092 | 1092 | */ |
1093 | - $html = apply_filters( 'wp_dropdown_users', $output ); |
|
1093 | + $html = apply_filters('wp_dropdown_users', $output); |
|
1094 | 1094 | |
1095 | - if ( $r['echo'] ) { |
|
1095 | + if ($r['echo']) { |
|
1096 | 1096 | echo $html; |
1097 | 1097 | } |
1098 | 1098 | return $html; |
@@ -1116,22 +1116,22 @@ discard block |
||
1116 | 1116 | */ |
1117 | 1117 | function sanitize_user_field($field, $value, $user_id, $context) { |
1118 | 1118 | $int_fields = array('ID'); |
1119 | - if ( in_array($field, $int_fields) ) |
|
1119 | + if (in_array($field, $int_fields)) |
|
1120 | 1120 | $value = (int) $value; |
1121 | 1121 | |
1122 | - if ( 'raw' == $context ) |
|
1122 | + if ('raw' == $context) |
|
1123 | 1123 | return $value; |
1124 | 1124 | |
1125 | - if ( !is_string($value) && !is_numeric($value) ) |
|
1125 | + if ( ! is_string($value) && ! is_numeric($value)) |
|
1126 | 1126 | return $value; |
1127 | 1127 | |
1128 | - $prefixed = false !== strpos( $field, 'user_' ); |
|
1128 | + $prefixed = false !== strpos($field, 'user_'); |
|
1129 | 1129 | |
1130 | - if ( 'edit' == $context ) { |
|
1131 | - if ( $prefixed ) { |
|
1130 | + if ('edit' == $context) { |
|
1131 | + if ($prefixed) { |
|
1132 | 1132 | |
1133 | 1133 | /** This filter is documented in wp-includes/post.php */ |
1134 | - $value = apply_filters( "edit_{$field}", $value, $user_id ); |
|
1134 | + $value = apply_filters("edit_{$field}", $value, $user_id); |
|
1135 | 1135 | } else { |
1136 | 1136 | |
1137 | 1137 | /** |
@@ -1145,17 +1145,17 @@ discard block |
||
1145 | 1145 | * @param mixed $value Value of the prefixed user field. |
1146 | 1146 | * @param int $user_id User ID. |
1147 | 1147 | */ |
1148 | - $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
|
1148 | + $value = apply_filters("edit_user_{$field}", $value, $user_id); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | - if ( 'description' == $field ) |
|
1152 | - $value = esc_html( $value ); // textarea_escaped? |
|
1151 | + if ('description' == $field) |
|
1152 | + $value = esc_html($value); // textarea_escaped? |
|
1153 | 1153 | else |
1154 | 1154 | $value = esc_attr($value); |
1155 | - } elseif ( 'db' == $context ) { |
|
1156 | - if ( $prefixed ) { |
|
1155 | + } elseif ('db' == $context) { |
|
1156 | + if ($prefixed) { |
|
1157 | 1157 | /** This filter is documented in wp-includes/post.php */ |
1158 | - $value = apply_filters( "pre_{$field}", $value ); |
|
1158 | + $value = apply_filters("pre_{$field}", $value); |
|
1159 | 1159 | } else { |
1160 | 1160 | |
1161 | 1161 | /** |
@@ -1168,14 +1168,14 @@ discard block |
||
1168 | 1168 | * |
1169 | 1169 | * @param mixed $value Value of the prefixed user field. |
1170 | 1170 | */ |
1171 | - $value = apply_filters( "pre_user_{$field}", $value ); |
|
1171 | + $value = apply_filters("pre_user_{$field}", $value); |
|
1172 | 1172 | } |
1173 | 1173 | } else { |
1174 | 1174 | // Use display filters by default. |
1175 | - if ( $prefixed ) { |
|
1175 | + if ($prefixed) { |
|
1176 | 1176 | |
1177 | 1177 | /** This filter is documented in wp-includes/post.php */ |
1178 | - $value = apply_filters( $field, $value, $user_id, $context ); |
|
1178 | + $value = apply_filters($field, $value, $user_id, $context); |
|
1179 | 1179 | } else { |
1180 | 1180 | |
1181 | 1181 | /** |
@@ -1190,17 +1190,17 @@ discard block |
||
1190 | 1190 | * @param int $user_id User ID. |
1191 | 1191 | * @param string $context The context to filter within. |
1192 | 1192 | */ |
1193 | - $value = apply_filters( "user_{$field}", $value, $user_id, $context ); |
|
1193 | + $value = apply_filters("user_{$field}", $value, $user_id, $context); |
|
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( 'user_url' == $field ) |
|
1197 | + if ('user_url' == $field) |
|
1198 | 1198 | $value = esc_url($value); |
1199 | 1199 | |
1200 | - if ( 'attribute' == $context ) { |
|
1201 | - $value = esc_attr( $value ); |
|
1202 | - } elseif ( 'js' == $context ) { |
|
1203 | - $value = esc_js( $value ); |
|
1200 | + if ('attribute' == $context) { |
|
1201 | + $value = esc_attr($value); |
|
1202 | + } elseif ('js' == $context) { |
|
1203 | + $value = esc_js($value); |
|
1204 | 1204 | } |
1205 | 1205 | return $value; |
1206 | 1206 | } |
@@ -1213,9 +1213,9 @@ discard block |
||
1213 | 1213 | * @param object|WP_User $user User object to be cached |
1214 | 1214 | * @return bool|null Returns false on failure. |
1215 | 1215 | */ |
1216 | -function update_user_caches( $user ) { |
|
1217 | - if ( $user instanceof WP_User ) { |
|
1218 | - if ( ! $user->exists() ) { |
|
1216 | +function update_user_caches($user) { |
|
1217 | + if ($user instanceof WP_User) { |
|
1218 | + if ( ! $user->exists()) { |
|
1219 | 1219 | return false; |
1220 | 1220 | } |
1221 | 1221 | |
@@ -1236,17 +1236,17 @@ discard block |
||
1236 | 1236 | * |
1237 | 1237 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
1238 | 1238 | */ |
1239 | -function clean_user_cache( $user ) { |
|
1240 | - if ( is_numeric( $user ) ) |
|
1241 | - $user = new WP_User( $user ); |
|
1239 | +function clean_user_cache($user) { |
|
1240 | + if (is_numeric($user)) |
|
1241 | + $user = new WP_User($user); |
|
1242 | 1242 | |
1243 | - if ( ! $user->exists() ) |
|
1243 | + if ( ! $user->exists()) |
|
1244 | 1244 | return; |
1245 | 1245 | |
1246 | - wp_cache_delete( $user->ID, 'users' ); |
|
1247 | - wp_cache_delete( $user->user_login, 'userlogins' ); |
|
1248 | - wp_cache_delete( $user->user_email, 'useremail' ); |
|
1249 | - wp_cache_delete( $user->user_nicename, 'userslugs' ); |
|
1246 | + wp_cache_delete($user->ID, 'users'); |
|
1247 | + wp_cache_delete($user->user_login, 'userlogins'); |
|
1248 | + wp_cache_delete($user->user_email, 'useremail'); |
|
1249 | + wp_cache_delete($user->user_nicename, 'userslugs'); |
|
1250 | 1250 | |
1251 | 1251 | /** |
1252 | 1252 | * Fires immediately after the given user's cache is cleaned. |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | * @param int $user_id User ID. |
1257 | 1257 | * @param WP_User $user User object. |
1258 | 1258 | */ |
1259 | - do_action( 'clean_user_cache', $user->ID, $user ); |
|
1259 | + do_action('clean_user_cache', $user->ID, $user); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | /** |
@@ -1267,8 +1267,8 @@ discard block |
||
1267 | 1267 | * @param string $username Username. |
1268 | 1268 | * @return int|false The user's ID on success, and false on failure. |
1269 | 1269 | */ |
1270 | -function username_exists( $username ) { |
|
1271 | - if ( $user = get_user_by( 'login', $username ) ) { |
|
1270 | +function username_exists($username) { |
|
1271 | + if ($user = get_user_by('login', $username)) { |
|
1272 | 1272 | return $user->ID; |
1273 | 1273 | } |
1274 | 1274 | return false; |
@@ -1282,8 +1282,8 @@ discard block |
||
1282 | 1282 | * @param string $email Email. |
1283 | 1283 | * @return int|false The user's ID on success, and false on failure. |
1284 | 1284 | */ |
1285 | -function email_exists( $email ) { |
|
1286 | - if ( $user = get_user_by( 'email', $email) ) { |
|
1285 | +function email_exists($email) { |
|
1286 | + if ($user = get_user_by('email', $email)) { |
|
1287 | 1287 | return $user->ID; |
1288 | 1288 | } |
1289 | 1289 | return false; |
@@ -1298,9 +1298,9 @@ discard block |
||
1298 | 1298 | * @param string $username Username. |
1299 | 1299 | * @return bool Whether username given is valid |
1300 | 1300 | */ |
1301 | -function validate_username( $username ) { |
|
1302 | - $sanitized = sanitize_user( $username, true ); |
|
1303 | - $valid = ( $sanitized == $username && ! empty( $sanitized ) ); |
|
1301 | +function validate_username($username) { |
|
1302 | + $sanitized = sanitize_user($username, true); |
|
1303 | + $valid = ($sanitized == $username && ! empty($sanitized)); |
|
1304 | 1304 | |
1305 | 1305 | /** |
1306 | 1306 | * Filter whether the provided username is valid or not. |
@@ -1310,7 +1310,7 @@ discard block |
||
1310 | 1310 | * @param bool $valid Whether given username is valid. |
1311 | 1311 | * @param string $username Username to check. |
1312 | 1312 | */ |
1313 | - return apply_filters( 'validate_username', $valid, $username ); |
|
1313 | + return apply_filters('validate_username', $valid, $username); |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | /** |
@@ -1363,34 +1363,34 @@ discard block |
||
1363 | 1363 | * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
1364 | 1364 | * be created. |
1365 | 1365 | */ |
1366 | -function wp_insert_user( $userdata ) { |
|
1366 | +function wp_insert_user($userdata) { |
|
1367 | 1367 | global $wpdb; |
1368 | 1368 | |
1369 | - if ( $userdata instanceof stdClass ) { |
|
1370 | - $userdata = get_object_vars( $userdata ); |
|
1371 | - } elseif ( $userdata instanceof WP_User ) { |
|
1369 | + if ($userdata instanceof stdClass) { |
|
1370 | + $userdata = get_object_vars($userdata); |
|
1371 | + } elseif ($userdata instanceof WP_User) { |
|
1372 | 1372 | $userdata = $userdata->to_array(); |
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | // Are we updating or creating? |
1376 | - if ( ! empty( $userdata['ID'] ) ) { |
|
1376 | + if ( ! empty($userdata['ID'])) { |
|
1377 | 1377 | $ID = (int) $userdata['ID']; |
1378 | 1378 | $update = true; |
1379 | - $old_user_data = get_userdata( $ID ); |
|
1379 | + $old_user_data = get_userdata($ID); |
|
1380 | 1380 | |
1381 | - if ( ! $old_user_data ) { |
|
1382 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
1381 | + if ( ! $old_user_data) { |
|
1382 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | // hashed in wp_update_user(), plaintext if called directly |
1386 | - $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; |
|
1386 | + $user_pass = ! empty($userdata['user_pass']) ? $userdata['user_pass'] : $old_user_data->user_pass; |
|
1387 | 1387 | } else { |
1388 | 1388 | $update = false; |
1389 | 1389 | // Hash the password |
1390 | - $user_pass = wp_hash_password( $userdata['user_pass'] ); |
|
1390 | + $user_pass = wp_hash_password($userdata['user_pass']); |
|
1391 | 1391 | } |
1392 | 1392 | |
1393 | - $sanitized_user_login = sanitize_user( $userdata['user_login'], true ); |
|
1393 | + $sanitized_user_login = sanitize_user($userdata['user_login'], true); |
|
1394 | 1394 | |
1395 | 1395 | /** |
1396 | 1396 | * Filter a username after it has been sanitized. |
@@ -1401,20 +1401,20 @@ discard block |
||
1401 | 1401 | * |
1402 | 1402 | * @param string $sanitized_user_login Username after it has been sanitized. |
1403 | 1403 | */ |
1404 | - $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); |
|
1404 | + $pre_user_login = apply_filters('pre_user_login', $sanitized_user_login); |
|
1405 | 1405 | |
1406 | 1406 | //Remove any non-printable chars from the login string to see if we have ended up with an empty username |
1407 | - $user_login = trim( $pre_user_login ); |
|
1407 | + $user_login = trim($pre_user_login); |
|
1408 | 1408 | |
1409 | 1409 | // user_login must be between 0 and 60 characters. |
1410 | - if ( empty( $user_login ) ) { |
|
1411 | - return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); |
|
1412 | - } elseif ( mb_strlen( $user_login ) > 60 ) { |
|
1413 | - return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); |
|
1410 | + if (empty($user_login)) { |
|
1411 | + return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.')); |
|
1412 | + } elseif (mb_strlen($user_login) > 60) { |
|
1413 | + return new WP_Error('user_login_too_long', __('Username may not be longer than 60 characters.')); |
|
1414 | 1414 | } |
1415 | 1415 | |
1416 | - if ( ! $update && username_exists( $user_login ) ) { |
|
1417 | - return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
|
1416 | + if ( ! $update && username_exists($user_login)) { |
|
1417 | + return new WP_Error('existing_user_login', __('Sorry, that username already exists!')); |
|
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | /** |
@@ -1424,26 +1424,26 @@ discard block |
||
1424 | 1424 | * |
1425 | 1425 | * @param array $usernames Array of blacklisted usernames. |
1426 | 1426 | */ |
1427 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
1427 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
1428 | 1428 | |
1429 | - if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ) ) ) { |
|
1430 | - return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) ); |
|
1429 | + if (in_array(strtolower($user_login), array_map('strtolower', $illegal_logins))) { |
|
1430 | + return new WP_Error('invalid_username', __('Sorry, that username is not allowed.')); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | /* |
1434 | 1434 | * If a nicename is provided, remove unsafe user characters before using it. |
1435 | 1435 | * Otherwise build a nicename from the user_login. |
1436 | 1436 | */ |
1437 | - if ( ! empty( $userdata['user_nicename'] ) ) { |
|
1438 | - $user_nicename = sanitize_user( $userdata['user_nicename'], true ); |
|
1439 | - if ( mb_strlen( $user_nicename ) > 50 ) { |
|
1440 | - return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) ); |
|
1437 | + if ( ! empty($userdata['user_nicename'])) { |
|
1438 | + $user_nicename = sanitize_user($userdata['user_nicename'], true); |
|
1439 | + if (mb_strlen($user_nicename) > 50) { |
|
1440 | + return new WP_Error('user_nicename_too_long', __('Nicename may not be longer than 50 characters.')); |
|
1441 | 1441 | } |
1442 | 1442 | } else { |
1443 | - $user_nicename = mb_substr( $user_login, 0, 50 ); |
|
1443 | + $user_nicename = mb_substr($user_login, 0, 50); |
|
1444 | 1444 | } |
1445 | 1445 | |
1446 | - $user_nicename = sanitize_title( $user_nicename ); |
|
1446 | + $user_nicename = sanitize_title($user_nicename); |
|
1447 | 1447 | |
1448 | 1448 | // Store values to save in user meta. |
1449 | 1449 | $meta = array(); |
@@ -1455,9 +1455,9 @@ discard block |
||
1455 | 1455 | * |
1456 | 1456 | * @param string $user_nicename The user's nicename. |
1457 | 1457 | */ |
1458 | - $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); |
|
1458 | + $user_nicename = apply_filters('pre_user_nicename', $user_nicename); |
|
1459 | 1459 | |
1460 | - $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; |
|
1460 | + $raw_user_url = empty($userdata['user_url']) ? '' : $userdata['user_url']; |
|
1461 | 1461 | |
1462 | 1462 | /** |
1463 | 1463 | * Filter a user's URL before the user is created or updated. |
@@ -1466,9 +1466,9 @@ discard block |
||
1466 | 1466 | * |
1467 | 1467 | * @param string $raw_user_url The user's URL. |
1468 | 1468 | */ |
1469 | - $user_url = apply_filters( 'pre_user_url', $raw_user_url ); |
|
1469 | + $user_url = apply_filters('pre_user_url', $raw_user_url); |
|
1470 | 1470 | |
1471 | - $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; |
|
1471 | + $raw_user_email = empty($userdata['user_email']) ? '' : $userdata['user_email']; |
|
1472 | 1472 | |
1473 | 1473 | /** |
1474 | 1474 | * Filter a user's email before the user is created or updated. |
@@ -1477,20 +1477,20 @@ discard block |
||
1477 | 1477 | * |
1478 | 1478 | * @param string $raw_user_email The user's email. |
1479 | 1479 | */ |
1480 | - $user_email = apply_filters( 'pre_user_email', $raw_user_email ); |
|
1480 | + $user_email = apply_filters('pre_user_email', $raw_user_email); |
|
1481 | 1481 | |
1482 | 1482 | /* |
1483 | 1483 | * If there is no update, just check for `email_exists`. If there is an update, |
1484 | 1484 | * check if current email and new email are the same, or not, and check `email_exists` |
1485 | 1485 | * accordingly. |
1486 | 1486 | */ |
1487 | - if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) ) |
|
1488 | - && ! defined( 'WP_IMPORTING' ) |
|
1489 | - && email_exists( $user_email ) |
|
1487 | + if (( ! $update || ( ! empty($old_user_data) && 0 !== strcasecmp($user_email, $old_user_data->user_email))) |
|
1488 | + && ! defined('WP_IMPORTING') |
|
1489 | + && email_exists($user_email) |
|
1490 | 1490 | ) { |
1491 | - return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); |
|
1491 | + return new WP_Error('existing_user_email', __('Sorry, that email address is already used!')); |
|
1492 | 1492 | } |
1493 | - $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; |
|
1493 | + $nickname = empty($userdata['nickname']) ? $user_login : $userdata['nickname']; |
|
1494 | 1494 | |
1495 | 1495 | /** |
1496 | 1496 | * Filter a user's nickname before the user is created or updated. |
@@ -1499,9 +1499,9 @@ discard block |
||
1499 | 1499 | * |
1500 | 1500 | * @param string $nickname The user's nickname. |
1501 | 1501 | */ |
1502 | - $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname ); |
|
1502 | + $meta['nickname'] = apply_filters('pre_user_nickname', $nickname); |
|
1503 | 1503 | |
1504 | - $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; |
|
1504 | + $first_name = empty($userdata['first_name']) ? '' : $userdata['first_name']; |
|
1505 | 1505 | |
1506 | 1506 | /** |
1507 | 1507 | * Filter a user's first name before the user is created or updated. |
@@ -1510,9 +1510,9 @@ discard block |
||
1510 | 1510 | * |
1511 | 1511 | * @param string $first_name The user's first name. |
1512 | 1512 | */ |
1513 | - $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name ); |
|
1513 | + $meta['first_name'] = apply_filters('pre_user_first_name', $first_name); |
|
1514 | 1514 | |
1515 | - $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; |
|
1515 | + $last_name = empty($userdata['last_name']) ? '' : $userdata['last_name']; |
|
1516 | 1516 | |
1517 | 1517 | /** |
1518 | 1518 | * Filter a user's last name before the user is created or updated. |
@@ -1521,17 +1521,17 @@ discard block |
||
1521 | 1521 | * |
1522 | 1522 | * @param string $last_name The user's last name. |
1523 | 1523 | */ |
1524 | - $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name ); |
|
1524 | + $meta['last_name'] = apply_filters('pre_user_last_name', $last_name); |
|
1525 | 1525 | |
1526 | - if ( empty( $userdata['display_name'] ) ) { |
|
1527 | - if ( $update ) { |
|
1526 | + if (empty($userdata['display_name'])) { |
|
1527 | + if ($update) { |
|
1528 | 1528 | $display_name = $user_login; |
1529 | - } elseif ( $meta['first_name'] && $meta['last_name'] ) { |
|
1529 | + } elseif ($meta['first_name'] && $meta['last_name']) { |
|
1530 | 1530 | /* translators: 1: first name, 2: last name */ |
1531 | - $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] ); |
|
1532 | - } elseif ( $meta['first_name'] ) { |
|
1531 | + $display_name = sprintf(_x('%1$s %2$s', 'Display name based on first name and last name'), $meta['first_name'], $meta['last_name']); |
|
1532 | + } elseif ($meta['first_name']) { |
|
1533 | 1533 | $display_name = $meta['first_name']; |
1534 | - } elseif ( $meta['last_name'] ) { |
|
1534 | + } elseif ($meta['last_name']) { |
|
1535 | 1535 | $display_name = $meta['last_name']; |
1536 | 1536 | } else { |
1537 | 1537 | $display_name = $user_login; |
@@ -1547,9 +1547,9 @@ discard block |
||
1547 | 1547 | * |
1548 | 1548 | * @param string $display_name The user's display name. |
1549 | 1549 | */ |
1550 | - $display_name = apply_filters( 'pre_user_display_name', $display_name ); |
|
1550 | + $display_name = apply_filters('pre_user_display_name', $display_name); |
|
1551 | 1551 | |
1552 | - $description = empty( $userdata['description'] ) ? '' : $userdata['description']; |
|
1552 | + $description = empty($userdata['description']) ? '' : $userdata['description']; |
|
1553 | 1553 | |
1554 | 1554 | /** |
1555 | 1555 | * Filter a user's description before the user is created or updated. |
@@ -1558,50 +1558,50 @@ discard block |
||
1558 | 1558 | * |
1559 | 1559 | * @param string $description The user's description. |
1560 | 1560 | */ |
1561 | - $meta['description'] = apply_filters( 'pre_user_description', $description ); |
|
1561 | + $meta['description'] = apply_filters('pre_user_description', $description); |
|
1562 | 1562 | |
1563 | - $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
|
1563 | + $meta['rich_editing'] = empty($userdata['rich_editing']) ? 'true' : $userdata['rich_editing']; |
|
1564 | 1564 | |
1565 | - $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
1565 | + $meta['comment_shortcuts'] = empty($userdata['comment_shortcuts']) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
1566 | 1566 | |
1567 | - $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; |
|
1568 | - $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); |
|
1567 | + $admin_color = empty($userdata['admin_color']) ? 'fresh' : $userdata['admin_color']; |
|
1568 | + $meta['admin_color'] = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color); |
|
1569 | 1569 | |
1570 | - $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl']; |
|
1570 | + $meta['use_ssl'] = empty($userdata['use_ssl']) ? 0 : $userdata['use_ssl']; |
|
1571 | 1571 | |
1572 | - $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; |
|
1572 | + $user_registered = empty($userdata['user_registered']) ? gmdate('Y-m-d H:i:s') : $userdata['user_registered']; |
|
1573 | 1573 | |
1574 | - $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; |
|
1574 | + $meta['show_admin_bar_front'] = empty($userdata['show_admin_bar_front']) ? 'true' : $userdata['show_admin_bar_front']; |
|
1575 | 1575 | |
1576 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); |
|
1576 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login)); |
|
1577 | 1577 | |
1578 | - if ( $user_nicename_check ) { |
|
1578 | + if ($user_nicename_check) { |
|
1579 | 1579 | $suffix = 2; |
1580 | 1580 | while ($user_nicename_check) { |
1581 | 1581 | // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. |
1582 | - $base_length = 49 - mb_strlen( $suffix ); |
|
1583 | - $alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; |
|
1584 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login)); |
|
1582 | + $base_length = 49 - mb_strlen($suffix); |
|
1583 | + $alt_user_nicename = mb_substr($user_nicename, 0, $base_length)."-$suffix"; |
|
1584 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login)); |
|
1585 | 1585 | $suffix++; |
1586 | 1586 | } |
1587 | 1587 | $user_nicename = $alt_user_nicename; |
1588 | 1588 | } |
1589 | 1589 | |
1590 | - $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); |
|
1591 | - $data = wp_unslash( $compacted ); |
|
1590 | + $compacted = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered'); |
|
1591 | + $data = wp_unslash($compacted); |
|
1592 | 1592 | |
1593 | - if ( $update ) { |
|
1594 | - if ( $user_email !== $old_user_data->user_email ) { |
|
1593 | + if ($update) { |
|
1594 | + if ($user_email !== $old_user_data->user_email) { |
|
1595 | 1595 | $data['user_activation_key'] = ''; |
1596 | 1596 | } |
1597 | - $wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); |
|
1597 | + $wpdb->update($wpdb->users, $data, compact('ID')); |
|
1598 | 1598 | $user_id = (int) $ID; |
1599 | 1599 | } else { |
1600 | - $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) ); |
|
1600 | + $wpdb->insert($wpdb->users, $data + compact('user_login')); |
|
1601 | 1601 | $user_id = (int) $wpdb->insert_id; |
1602 | 1602 | } |
1603 | 1603 | |
1604 | - $user = new WP_User( $user_id ); |
|
1604 | + $user = new WP_User($user_id); |
|
1605 | 1605 | |
1606 | 1606 | /** |
1607 | 1607 | * Filter a user's meta values and keys before the user is created or updated. |
@@ -1628,28 +1628,28 @@ discard block |
||
1628 | 1628 | * @param WP_User $user User object. |
1629 | 1629 | * @param bool $update Whether the user is being updated rather than created. |
1630 | 1630 | */ |
1631 | - $meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); |
|
1631 | + $meta = apply_filters('insert_user_meta', $meta, $user, $update); |
|
1632 | 1632 | |
1633 | 1633 | // Update user meta. |
1634 | - foreach ( $meta as $key => $value ) { |
|
1635 | - update_user_meta( $user_id, $key, $value ); |
|
1634 | + foreach ($meta as $key => $value) { |
|
1635 | + update_user_meta($user_id, $key, $value); |
|
1636 | 1636 | } |
1637 | 1637 | |
1638 | - foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) { |
|
1639 | - if ( isset( $userdata[ $key ] ) ) { |
|
1640 | - update_user_meta( $user_id, $key, $userdata[ $key ] ); |
|
1638 | + foreach (wp_get_user_contact_methods($user) as $key => $value) { |
|
1639 | + if (isset($userdata[$key])) { |
|
1640 | + update_user_meta($user_id, $key, $userdata[$key]); |
|
1641 | 1641 | } |
1642 | 1642 | } |
1643 | 1643 | |
1644 | - if ( isset( $userdata['role'] ) ) { |
|
1645 | - $user->set_role( $userdata['role'] ); |
|
1646 | - } elseif ( ! $update ) { |
|
1644 | + if (isset($userdata['role'])) { |
|
1645 | + $user->set_role($userdata['role']); |
|
1646 | + } elseif ( ! $update) { |
|
1647 | 1647 | $user->set_role(get_option('default_role')); |
1648 | 1648 | } |
1649 | - wp_cache_delete( $user_id, 'users' ); |
|
1650 | - wp_cache_delete( $user_login, 'userlogins' ); |
|
1649 | + wp_cache_delete($user_id, 'users'); |
|
1650 | + wp_cache_delete($user_login, 'userlogins'); |
|
1651 | 1651 | |
1652 | - if ( $update ) { |
|
1652 | + if ($update) { |
|
1653 | 1653 | /** |
1654 | 1654 | * Fires immediately after an existing user is updated. |
1655 | 1655 | * |
@@ -1658,7 +1658,7 @@ discard block |
||
1658 | 1658 | * @param int $user_id User ID. |
1659 | 1659 | * @param object $old_user_data Object containing user's data prior to update. |
1660 | 1660 | */ |
1661 | - do_action( 'profile_update', $user_id, $old_user_data ); |
|
1661 | + do_action('profile_update', $user_id, $old_user_data); |
|
1662 | 1662 | } else { |
1663 | 1663 | /** |
1664 | 1664 | * Fires immediately after a new user is registered. |
@@ -1667,7 +1667,7 @@ discard block |
||
1667 | 1667 | * |
1668 | 1668 | * @param int $user_id User ID. |
1669 | 1669 | */ |
1670 | - do_action( 'user_register', $user_id ); |
|
1670 | + do_action('user_register', $user_id); |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | 1673 | return $user_id; |
@@ -1690,37 +1690,37 @@ discard block |
||
1690 | 1690 | * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. |
1691 | 1691 | */ |
1692 | 1692 | function wp_update_user($userdata) { |
1693 | - if ( $userdata instanceof stdClass ) { |
|
1694 | - $userdata = get_object_vars( $userdata ); |
|
1695 | - } elseif ( $userdata instanceof WP_User ) { |
|
1693 | + if ($userdata instanceof stdClass) { |
|
1694 | + $userdata = get_object_vars($userdata); |
|
1695 | + } elseif ($userdata instanceof WP_User) { |
|
1696 | 1696 | $userdata = $userdata->to_array(); |
1697 | 1697 | } |
1698 | 1698 | |
1699 | - $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0; |
|
1700 | - if ( ! $ID ) { |
|
1701 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
1699 | + $ID = isset($userdata['ID']) ? (int) $userdata['ID'] : 0; |
|
1700 | + if ( ! $ID) { |
|
1701 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
1702 | 1702 | } |
1703 | 1703 | |
1704 | 1704 | // First, get all of the original fields |
1705 | - $user_obj = get_userdata( $ID ); |
|
1706 | - if ( ! $user_obj ) { |
|
1707 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
1705 | + $user_obj = get_userdata($ID); |
|
1706 | + if ( ! $user_obj) { |
|
1707 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | 1710 | $user = $user_obj->to_array(); |
1711 | 1711 | |
1712 | 1712 | // Add additional custom fields |
1713 | - foreach ( _get_additional_user_keys( $user_obj ) as $key ) { |
|
1714 | - $user[ $key ] = get_user_meta( $ID, $key, true ); |
|
1713 | + foreach (_get_additional_user_keys($user_obj) as $key) { |
|
1714 | + $user[$key] = get_user_meta($ID, $key, true); |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | // Escape data pulled from DB. |
1718 | - $user = add_magic_quotes( $user ); |
|
1718 | + $user = add_magic_quotes($user); |
|
1719 | 1719 | |
1720 | - if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) { |
|
1720 | + if ( ! empty($userdata['user_pass']) && $userdata['user_pass'] !== $user_obj->user_pass) { |
|
1721 | 1721 | // If password is changing, hash it now |
1722 | 1722 | $plaintext_pass = $userdata['user_pass']; |
1723 | - $userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); |
|
1723 | + $userdata['user_pass'] = wp_hash_password($userdata['user_pass']); |
|
1724 | 1724 | |
1725 | 1725 | /** |
1726 | 1726 | * Filter whether to send the password change email. |
@@ -1734,10 +1734,10 @@ discard block |
||
1734 | 1734 | * @param array $userdata The updated user array. |
1735 | 1735 | * |
1736 | 1736 | */ |
1737 | - $send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata ); |
|
1737 | + $send_password_change_email = apply_filters('send_password_change_email', true, $user, $userdata); |
|
1738 | 1738 | } |
1739 | 1739 | |
1740 | - if ( isset( $userdata['user_email'] ) && $user['user_email'] !== $userdata['user_email'] ) { |
|
1740 | + if (isset($userdata['user_email']) && $user['user_email'] !== $userdata['user_email']) { |
|
1741 | 1741 | /** |
1742 | 1742 | * Filter whether to send the email change email. |
1743 | 1743 | * |
@@ -1750,24 +1750,24 @@ discard block |
||
1750 | 1750 | * @param array $userdata The updated user array. |
1751 | 1751 | * |
1752 | 1752 | */ |
1753 | - $send_email_change_email = apply_filters( 'send_email_change_email', true, $user, $userdata ); |
|
1753 | + $send_email_change_email = apply_filters('send_email_change_email', true, $user, $userdata); |
|
1754 | 1754 | } |
1755 | 1755 | |
1756 | - wp_cache_delete( $user['user_email'], 'useremail' ); |
|
1757 | - wp_cache_delete( $user['user_nicename'], 'userslugs' ); |
|
1756 | + wp_cache_delete($user['user_email'], 'useremail'); |
|
1757 | + wp_cache_delete($user['user_nicename'], 'userslugs'); |
|
1758 | 1758 | |
1759 | 1759 | // Merge old and new fields with new fields overwriting old ones. |
1760 | - $userdata = array_merge( $user, $userdata ); |
|
1761 | - $user_id = wp_insert_user( $userdata ); |
|
1760 | + $userdata = array_merge($user, $userdata); |
|
1761 | + $user_id = wp_insert_user($userdata); |
|
1762 | 1762 | |
1763 | - if ( ! is_wp_error( $user_id ) ) { |
|
1763 | + if ( ! is_wp_error($user_id)) { |
|
1764 | 1764 | |
1765 | - $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
1765 | + $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
1766 | 1766 | |
1767 | - if ( ! empty( $send_password_change_email ) ) { |
|
1767 | + if ( ! empty($send_password_change_email)) { |
|
1768 | 1768 | |
1769 | 1769 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
1770 | - $pass_change_text = __( 'Hi ###USERNAME###, |
|
1770 | + $pass_change_text = __('Hi ###USERNAME###, |
|
1771 | 1771 | |
1772 | 1772 | This notice confirms that your password was changed on ###SITENAME###. |
1773 | 1773 | |
@@ -1782,7 +1782,7 @@ discard block |
||
1782 | 1782 | |
1783 | 1783 | $pass_change_email = array( |
1784 | 1784 | 'to' => $user['user_email'], |
1785 | - 'subject' => __( '[%s] Notice of Password Change' ), |
|
1785 | + 'subject' => __('[%s] Notice of Password Change'), |
|
1786 | 1786 | 'message' => $pass_change_text, |
1787 | 1787 | 'headers' => '', |
1788 | 1788 | ); |
@@ -1809,20 +1809,20 @@ discard block |
||
1809 | 1809 | * @param array $userdata The updated user array. |
1810 | 1810 | * |
1811 | 1811 | */ |
1812 | - $pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata ); |
|
1812 | + $pass_change_email = apply_filters('password_change_email', $pass_change_email, $user, $userdata); |
|
1813 | 1813 | |
1814 | - $pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] ); |
|
1815 | - $pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] ); |
|
1816 | - $pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] ); |
|
1817 | - $pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] ); |
|
1818 | - $pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] ); |
|
1814 | + $pass_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $pass_change_email['message']); |
|
1815 | + $pass_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $pass_change_email['message']); |
|
1816 | + $pass_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $pass_change_email['message']); |
|
1817 | + $pass_change_email['message'] = str_replace('###SITENAME###', $blog_name, $pass_change_email['message']); |
|
1818 | + $pass_change_email['message'] = str_replace('###SITEURL###', home_url(), $pass_change_email['message']); |
|
1819 | 1819 | |
1820 | - wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); |
|
1820 | + wp_mail($pass_change_email['to'], sprintf($pass_change_email['subject'], $blog_name), $pass_change_email['message'], $pass_change_email['headers']); |
|
1821 | 1821 | } |
1822 | 1822 | |
1823 | - if ( ! empty( $send_email_change_email ) ) { |
|
1823 | + if ( ! empty($send_email_change_email)) { |
|
1824 | 1824 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
1825 | - $email_change_text = __( 'Hi ###USERNAME###, |
|
1825 | + $email_change_text = __('Hi ###USERNAME###, |
|
1826 | 1826 | |
1827 | 1827 | This notice confirms that your email was changed on ###SITENAME###. |
1828 | 1828 | |
@@ -1837,7 +1837,7 @@ discard block |
||
1837 | 1837 | |
1838 | 1838 | $email_change_email = array( |
1839 | 1839 | 'to' => $user['user_email'], |
1840 | - 'subject' => __( '[%s] Notice of Email Change' ), |
|
1840 | + 'subject' => __('[%s] Notice of Email Change'), |
|
1841 | 1841 | 'message' => $email_change_text, |
1842 | 1842 | 'headers' => '', |
1843 | 1843 | ); |
@@ -1863,32 +1863,32 @@ discard block |
||
1863 | 1863 | * @param array $user The original user array. |
1864 | 1864 | * @param array $userdata The updated user array. |
1865 | 1865 | */ |
1866 | - $email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata ); |
|
1866 | + $email_change_email = apply_filters('email_change_email', $email_change_email, $user, $userdata); |
|
1867 | 1867 | |
1868 | - $email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] ); |
|
1869 | - $email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] ); |
|
1870 | - $email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] ); |
|
1871 | - $email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] ); |
|
1872 | - $email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
|
1868 | + $email_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $email_change_email['message']); |
|
1869 | + $email_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $email_change_email['message']); |
|
1870 | + $email_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $email_change_email['message']); |
|
1871 | + $email_change_email['message'] = str_replace('###SITENAME###', $blog_name, $email_change_email['message']); |
|
1872 | + $email_change_email['message'] = str_replace('###SITEURL###', home_url(), $email_change_email['message']); |
|
1873 | 1873 | |
1874 | - wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); |
|
1874 | + wp_mail($email_change_email['to'], sprintf($email_change_email['subject'], $blog_name), $email_change_email['message'], $email_change_email['headers']); |
|
1875 | 1875 | } |
1876 | 1876 | } |
1877 | 1877 | |
1878 | 1878 | // Update the cookies if the password changed. |
1879 | 1879 | $current_user = wp_get_current_user(); |
1880 | - if ( $current_user->ID == $ID ) { |
|
1881 | - if ( isset($plaintext_pass) ) { |
|
1880 | + if ($current_user->ID == $ID) { |
|
1881 | + if (isset($plaintext_pass)) { |
|
1882 | 1882 | wp_clear_auth_cookie(); |
1883 | 1883 | |
1884 | 1884 | // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
1885 | 1885 | // If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
1886 | - $logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
1886 | + $logged_in_cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
1887 | 1887 | /** This filter is documented in wp-includes/pluggable.php */ |
1888 | - $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false ); |
|
1889 | - $remember = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ); |
|
1888 | + $default_cookie_life = apply_filters('auth_cookie_expiration', (2 * DAY_IN_SECONDS), $ID, false); |
|
1889 | + $remember = (($logged_in_cookie['expiration'] - time()) > $default_cookie_life); |
|
1890 | 1890 | |
1891 | - wp_set_auth_cookie( $ID, $remember ); |
|
1891 | + wp_set_auth_cookie($ID, $remember); |
|
1892 | 1892 | } |
1893 | 1893 | } |
1894 | 1894 | |
@@ -1911,8 +1911,8 @@ discard block |
||
1911 | 1911 | * be created. |
1912 | 1912 | */ |
1913 | 1913 | function wp_create_user($username, $password, $email = '') { |
1914 | - $user_login = wp_slash( $username ); |
|
1915 | - $user_email = wp_slash( $email ); |
|
1914 | + $user_login = wp_slash($username); |
|
1915 | + $user_email = wp_slash($email); |
|
1916 | 1916 | $user_pass = $password; |
1917 | 1917 | |
1918 | 1918 | $userdata = compact('user_login', 'user_email', 'user_pass'); |
@@ -1931,9 +1931,9 @@ discard block |
||
1931 | 1931 | * @param WP_User $user WP_User instance. |
1932 | 1932 | * @return array List of user keys to be populated in wp_update_user(). |
1933 | 1933 | */ |
1934 | -function _get_additional_user_keys( $user ) { |
|
1935 | - $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' ); |
|
1936 | - return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); |
|
1934 | +function _get_additional_user_keys($user) { |
|
1935 | + $keys = array('first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front'); |
|
1936 | + return array_merge($keys, array_keys(wp_get_user_contact_methods($user))); |
|
1937 | 1937 | } |
1938 | 1938 | |
1939 | 1939 | /** |
@@ -1946,13 +1946,13 @@ discard block |
||
1946 | 1946 | * @param WP_User $user Optional. WP_User object. |
1947 | 1947 | * @return array Array of contact methods and their labels. |
1948 | 1948 | */ |
1949 | -function wp_get_user_contact_methods( $user = null ) { |
|
1949 | +function wp_get_user_contact_methods($user = null) { |
|
1950 | 1950 | $methods = array(); |
1951 | - if ( get_site_option( 'initial_db_version' ) < 23588 ) { |
|
1951 | + if (get_site_option('initial_db_version') < 23588) { |
|
1952 | 1952 | $methods = array( |
1953 | - 'aim' => __( 'AIM' ), |
|
1954 | - 'yim' => __( 'Yahoo IM' ), |
|
1955 | - 'jabber' => __( 'Jabber / Google Talk' ) |
|
1953 | + 'aim' => __('AIM'), |
|
1954 | + 'yim' => __('Yahoo IM'), |
|
1955 | + 'jabber' => __('Jabber / Google Talk') |
|
1956 | 1956 | ); |
1957 | 1957 | } |
1958 | 1958 | |
@@ -1964,7 +1964,7 @@ discard block |
||
1964 | 1964 | * @param array $methods Array of contact methods and their labels. |
1965 | 1965 | * @param WP_User $user WP_User object. |
1966 | 1966 | */ |
1967 | - return apply_filters( 'user_contactmethods', $methods, $user ); |
|
1967 | + return apply_filters('user_contactmethods', $methods, $user); |
|
1968 | 1968 | } |
1969 | 1969 | |
1970 | 1970 | /** |
@@ -1978,8 +1978,8 @@ discard block |
||
1978 | 1978 | * @param WP_User $user Optional. WP_User object. Default null. |
1979 | 1979 | * @return array Array of contact methods and their labels. |
1980 | 1980 | */ |
1981 | -function _wp_get_user_contactmethods( $user = null ) { |
|
1982 | - return wp_get_user_contact_methods( $user ); |
|
1981 | +function _wp_get_user_contactmethods($user = null) { |
|
1982 | + return wp_get_user_contact_methods($user); |
|
1983 | 1983 | } |
1984 | 1984 | |
1985 | 1985 | /** |
@@ -1990,7 +1990,7 @@ discard block |
||
1990 | 1990 | * @return string The password hint text. |
1991 | 1991 | */ |
1992 | 1992 | function wp_get_password_hint() { |
1993 | - $hint = __( 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' ); |
|
1993 | + $hint = __('Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'); |
|
1994 | 1994 | |
1995 | 1995 | /** |
1996 | 1996 | * Filter the text describing the site's password complexity policy. |
@@ -1999,7 +1999,7 @@ discard block |
||
1999 | 1999 | * |
2000 | 2000 | * @param string $hint The password hint text. |
2001 | 2001 | */ |
2002 | - return apply_filters( 'password_hint', $hint ); |
|
2002 | + return apply_filters('password_hint', $hint); |
|
2003 | 2003 | } |
2004 | 2004 | |
2005 | 2005 | /** |
@@ -2014,7 +2014,7 @@ discard block |
||
2014 | 2014 | * |
2015 | 2015 | * @return string|WP_Error Password reset key on success. WP_Error on error. |
2016 | 2016 | */ |
2017 | -function get_password_reset_key( $user ) { |
|
2017 | +function get_password_reset_key($user) { |
|
2018 | 2018 | global $wpdb, $wp_hasher; |
2019 | 2019 | |
2020 | 2020 | /** |
@@ -2025,7 +2025,7 @@ discard block |
||
2025 | 2025 | * |
2026 | 2026 | * @param string $user_login The user login name. |
2027 | 2027 | */ |
2028 | - do_action( 'retreive_password', $user->user_login ); |
|
2028 | + do_action('retreive_password', $user->user_login); |
|
2029 | 2029 | |
2030 | 2030 | /** |
2031 | 2031 | * Fires before a new password is retrieved. |
@@ -2034,7 +2034,7 @@ discard block |
||
2034 | 2034 | * |
2035 | 2035 | * @param string $user_login The user login name. |
2036 | 2036 | */ |
2037 | - do_action( 'retrieve_password', $user->user_login ); |
|
2037 | + do_action('retrieve_password', $user->user_login); |
|
2038 | 2038 | |
2039 | 2039 | /** |
2040 | 2040 | * Filter whether to allow a password to be reset. |
@@ -2044,16 +2044,16 @@ discard block |
||
2044 | 2044 | * @param bool $allow Whether to allow the password to be reset. Default true. |
2045 | 2045 | * @param int $user_data->ID The ID of the user attempting to reset a password. |
2046 | 2046 | */ |
2047 | - $allow = apply_filters( 'allow_password_reset', true, $user->ID ); |
|
2047 | + $allow = apply_filters('allow_password_reset', true, $user->ID); |
|
2048 | 2048 | |
2049 | - if ( ! $allow ) { |
|
2050 | - return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) ); |
|
2051 | - } elseif ( is_wp_error( $allow ) ) { |
|
2049 | + if ( ! $allow) { |
|
2050 | + return new WP_Error('no_password_reset', __('Password reset is not allowed for this user')); |
|
2051 | + } elseif (is_wp_error($allow)) { |
|
2052 | 2052 | return $allow; |
2053 | 2053 | } |
2054 | 2054 | |
2055 | 2055 | // Generate something random for a password reset key. |
2056 | - $key = wp_generate_password( 20, false ); |
|
2056 | + $key = wp_generate_password(20, false); |
|
2057 | 2057 | |
2058 | 2058 | /** |
2059 | 2059 | * Fires when a password reset key is generated. |
@@ -2063,17 +2063,17 @@ discard block |
||
2063 | 2063 | * @param string $user_login The username for the user. |
2064 | 2064 | * @param string $key The generated password reset key. |
2065 | 2065 | */ |
2066 | - do_action( 'retrieve_password_key', $user->user_login, $key ); |
|
2066 | + do_action('retrieve_password_key', $user->user_login, $key); |
|
2067 | 2067 | |
2068 | 2068 | // Now insert the key, hashed, into the DB. |
2069 | - if ( empty( $wp_hasher ) ) { |
|
2070 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
2071 | - $wp_hasher = new PasswordHash( 8, true ); |
|
2069 | + if (empty($wp_hasher)) { |
|
2070 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
2071 | + $wp_hasher = new PasswordHash(8, true); |
|
2072 | 2072 | } |
2073 | - $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); |
|
2074 | - $key_saved = $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); |
|
2075 | - if ( false === $key_saved ) { |
|
2076 | - return new WP_Error( 'no_password_key_update', __( 'Could not save password reset key to database.' ) ); |
|
2073 | + $hashed = time().':'.$wp_hasher->HashPassword($key); |
|
2074 | + $key_saved = $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login)); |
|
2075 | + if (false === $key_saved) { |
|
2076 | + return new WP_Error('no_password_key_update', __('Could not save password reset key to database.')); |
|
2077 | 2077 | } |
2078 | 2078 | |
2079 | 2079 | return $key; |
@@ -2101,19 +2101,19 @@ discard block |
||
2101 | 2101 | |
2102 | 2102 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
2103 | 2103 | |
2104 | - if ( empty( $key ) || !is_string( $key ) ) |
|
2104 | + if (empty($key) || ! is_string($key)) |
|
2105 | 2105 | return new WP_Error('invalid_key', __('Invalid key')); |
2106 | 2106 | |
2107 | - if ( empty($login) || !is_string($login) ) |
|
2107 | + if (empty($login) || ! is_string($login)) |
|
2108 | 2108 | return new WP_Error('invalid_key', __('Invalid key')); |
2109 | 2109 | |
2110 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
|
2111 | - if ( ! $row ) |
|
2110 | + $row = $wpdb->get_row($wpdb->prepare("SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login)); |
|
2111 | + if ( ! $row) |
|
2112 | 2112 | return new WP_Error('invalid_key', __('Invalid key')); |
2113 | 2113 | |
2114 | - if ( empty( $wp_hasher ) ) { |
|
2115 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
2116 | - $wp_hasher = new PasswordHash( 8, true ); |
|
2114 | + if (empty($wp_hasher)) { |
|
2115 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
2116 | + $wp_hasher = new PasswordHash(8, true); |
|
2117 | 2117 | } |
2118 | 2118 | |
2119 | 2119 | /** |
@@ -2123,31 +2123,31 @@ discard block |
||
2123 | 2123 | * |
2124 | 2124 | * @param int $expiration The expiration time in seconds. |
2125 | 2125 | */ |
2126 | - $expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS ); |
|
2126 | + $expiration_duration = apply_filters('password_reset_expiration', DAY_IN_SECONDS); |
|
2127 | 2127 | |
2128 | - if ( false !== strpos( $row->user_activation_key, ':' ) ) { |
|
2129 | - list( $pass_request_time, $pass_key ) = explode( ':', $row->user_activation_key, 2 ); |
|
2128 | + if (false !== strpos($row->user_activation_key, ':')) { |
|
2129 | + list($pass_request_time, $pass_key) = explode(':', $row->user_activation_key, 2); |
|
2130 | 2130 | $expiration_time = $pass_request_time + $expiration_duration; |
2131 | 2131 | } else { |
2132 | 2132 | $pass_key = $row->user_activation_key; |
2133 | 2133 | $expiration_time = false; |
2134 | 2134 | } |
2135 | 2135 | |
2136 | - if ( ! $pass_key ) { |
|
2137 | - return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
|
2136 | + if ( ! $pass_key) { |
|
2137 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
2138 | 2138 | } |
2139 | 2139 | |
2140 | - $hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key ); |
|
2140 | + $hash_is_correct = $wp_hasher->CheckPassword($key, $pass_key); |
|
2141 | 2141 | |
2142 | - if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { |
|
2143 | - return get_userdata( $row->ID ); |
|
2144 | - } elseif ( $hash_is_correct && $expiration_time ) { |
|
2142 | + if ($hash_is_correct && $expiration_time && time() < $expiration_time) { |
|
2143 | + return get_userdata($row->ID); |
|
2144 | + } elseif ($hash_is_correct && $expiration_time) { |
|
2145 | 2145 | // Key has an expiration time that's passed |
2146 | - return new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
2146 | + return new WP_Error('expired_key', __('Invalid key')); |
|
2147 | 2147 | } |
2148 | 2148 | |
2149 | - if ( hash_equals( $row->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) { |
|
2150 | - $return = new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
2149 | + if (hash_equals($row->user_activation_key, $key) || ($hash_is_correct && ! $expiration_time)) { |
|
2150 | + $return = new WP_Error('expired_key', __('Invalid key')); |
|
2151 | 2151 | $user_id = $row->ID; |
2152 | 2152 | |
2153 | 2153 | /** |
@@ -2161,10 +2161,10 @@ discard block |
||
2161 | 2161 | * Return a WP_User object to validate the key. |
2162 | 2162 | * @param int $user_id The matched user ID. |
2163 | 2163 | */ |
2164 | - return apply_filters( 'password_reset_key_expired', $return, $user_id ); |
|
2164 | + return apply_filters('password_reset_key_expired', $return, $user_id); |
|
2165 | 2165 | } |
2166 | 2166 | |
2167 | - return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
|
2167 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
2168 | 2168 | } |
2169 | 2169 | |
2170 | 2170 | /** |
@@ -2175,7 +2175,7 @@ discard block |
||
2175 | 2175 | * @param object $user The user |
2176 | 2176 | * @param string $new_pass New password for the user in plaintext |
2177 | 2177 | */ |
2178 | -function reset_password( $user, $new_pass ) { |
|
2178 | +function reset_password($user, $new_pass) { |
|
2179 | 2179 | /** |
2180 | 2180 | * Fires before the user's password is reset. |
2181 | 2181 | * |
@@ -2184,10 +2184,10 @@ discard block |
||
2184 | 2184 | * @param object $user The user. |
2185 | 2185 | * @param string $new_pass New user password. |
2186 | 2186 | */ |
2187 | - do_action( 'password_reset', $user, $new_pass ); |
|
2187 | + do_action('password_reset', $user, $new_pass); |
|
2188 | 2188 | |
2189 | - wp_set_password( $new_pass, $user->ID ); |
|
2190 | - update_user_option( $user->ID, 'default_password_nag', false, true ); |
|
2189 | + wp_set_password($new_pass, $user->ID); |
|
2190 | + update_user_option($user->ID, 'default_password_nag', false, true); |
|
2191 | 2191 | |
2192 | 2192 | /** |
2193 | 2193 | * Fires after the user's password is reset. |
@@ -2197,7 +2197,7 @@ discard block |
||
2197 | 2197 | * @param object $user The user. |
2198 | 2198 | * @param string $new_pass New user password. |
2199 | 2199 | */ |
2200 | - do_action( 'after_password_reset', $user, $new_pass ); |
|
2200 | + do_action('after_password_reset', $user, $new_pass); |
|
2201 | 2201 | } |
2202 | 2202 | |
2203 | 2203 | /** |
@@ -2209,10 +2209,10 @@ discard block |
||
2209 | 2209 | * @param string $user_email User's email address to send password and add |
2210 | 2210 | * @return int|WP_Error Either user's ID or error on failure. |
2211 | 2211 | */ |
2212 | -function register_new_user( $user_login, $user_email ) { |
|
2212 | +function register_new_user($user_login, $user_email) { |
|
2213 | 2213 | $errors = new WP_Error(); |
2214 | 2214 | |
2215 | - $sanitized_user_login = sanitize_user( $user_login ); |
|
2215 | + $sanitized_user_login = sanitize_user($user_login); |
|
2216 | 2216 | /** |
2217 | 2217 | * Filter the email address of a user being registered. |
2218 | 2218 | * |
@@ -2220,33 +2220,33 @@ discard block |
||
2220 | 2220 | * |
2221 | 2221 | * @param string $user_email The email address of the new user. |
2222 | 2222 | */ |
2223 | - $user_email = apply_filters( 'user_registration_email', $user_email ); |
|
2223 | + $user_email = apply_filters('user_registration_email', $user_email); |
|
2224 | 2224 | |
2225 | 2225 | // Check the username |
2226 | - if ( $sanitized_user_login == '' ) { |
|
2227 | - $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); |
|
2228 | - } elseif ( ! validate_username( $user_login ) ) { |
|
2229 | - $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
|
2226 | + if ($sanitized_user_login == '') { |
|
2227 | + $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); |
|
2228 | + } elseif ( ! validate_username($user_login)) { |
|
2229 | + $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); |
|
2230 | 2230 | $sanitized_user_login = ''; |
2231 | - } elseif ( username_exists( $sanitized_user_login ) ) { |
|
2232 | - $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); |
|
2231 | + } elseif (username_exists($sanitized_user_login)) { |
|
2232 | + $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); |
|
2233 | 2233 | |
2234 | 2234 | } else { |
2235 | 2235 | /** This filter is documented in wp-includes/user.php */ |
2236 | - $illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) ); |
|
2237 | - if ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) { |
|
2238 | - $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
|
2236 | + $illegal_user_logins = array_map('strtolower', (array) apply_filters('illegal_user_logins', array())); |
|
2237 | + if (in_array(strtolower($sanitized_user_login), $illegal_user_logins)) { |
|
2238 | + $errors->add('invalid_username', __('<strong>ERROR</strong>: Sorry, that username is not allowed.')); |
|
2239 | 2239 | } |
2240 | 2240 | } |
2241 | 2241 | |
2242 | 2242 | // Check the email address |
2243 | - if ( $user_email == '' ) { |
|
2244 | - $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) ); |
|
2245 | - } elseif ( ! is_email( $user_email ) ) { |
|
2246 | - $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); |
|
2243 | + if ($user_email == '') { |
|
2244 | + $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your email address.')); |
|
2245 | + } elseif ( ! is_email($user_email)) { |
|
2246 | + $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); |
|
2247 | 2247 | $user_email = ''; |
2248 | - } elseif ( email_exists( $user_email ) ) { |
|
2249 | - $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); |
|
2248 | + } elseif (email_exists($user_email)) { |
|
2249 | + $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); |
|
2250 | 2250 | } |
2251 | 2251 | |
2252 | 2252 | /** |
@@ -2260,7 +2260,7 @@ discard block |
||
2260 | 2260 | * e.g., an empty field, an invalid username or email, |
2261 | 2261 | * or an existing username or email. |
2262 | 2262 | */ |
2263 | - do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
|
2263 | + do_action('register_post', $sanitized_user_login, $user_email, $errors); |
|
2264 | 2264 | |
2265 | 2265 | /** |
2266 | 2266 | * Filter the errors encountered when a new user is being registered. |
@@ -2278,19 +2278,19 @@ discard block |
||
2278 | 2278 | * @param string $sanitized_user_login User's username after it has been sanitized. |
2279 | 2279 | * @param string $user_email User's email. |
2280 | 2280 | */ |
2281 | - $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
|
2281 | + $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); |
|
2282 | 2282 | |
2283 | - if ( $errors->get_error_code() ) |
|
2283 | + if ($errors->get_error_code()) |
|
2284 | 2284 | return $errors; |
2285 | 2285 | |
2286 | - $user_pass = wp_generate_password( 12, false ); |
|
2287 | - $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
|
2288 | - if ( ! $user_id || is_wp_error( $user_id ) ) { |
|
2289 | - $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); |
|
2286 | + $user_pass = wp_generate_password(12, false); |
|
2287 | + $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); |
|
2288 | + if ( ! $user_id || is_wp_error($user_id)) { |
|
2289 | + $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); |
|
2290 | 2290 | return $errors; |
2291 | 2291 | } |
2292 | 2292 | |
2293 | - update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. |
|
2293 | + update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. |
|
2294 | 2294 | |
2295 | 2295 | /** |
2296 | 2296 | * Fires after a new user registration has been recorded. |
@@ -2299,7 +2299,7 @@ discard block |
||
2299 | 2299 | * |
2300 | 2300 | * @param int $user_id ID of the newly registered user. |
2301 | 2301 | */ |
2302 | - do_action( 'register_new_user', $user_id ); |
|
2302 | + do_action('register_new_user', $user_id); |
|
2303 | 2303 | |
2304 | 2304 | return $user_id; |
2305 | 2305 | } |
@@ -2315,8 +2315,8 @@ discard block |
||
2315 | 2315 | * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty string |
2316 | 2316 | * (admin only), or 'both' (admin and user). Default 'both'. |
2317 | 2317 | */ |
2318 | -function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { |
|
2319 | - wp_new_user_notification( $user_id, null, $notify ); |
|
2318 | +function wp_send_new_user_notifications($user_id, $notify = 'both') { |
|
2319 | + wp_new_user_notification($user_id, null, $notify); |
|
2320 | 2320 | } |
2321 | 2321 | |
2322 | 2322 | /** |
@@ -2327,8 +2327,8 @@ discard block |
||
2327 | 2327 | * @return string Token. |
2328 | 2328 | */ |
2329 | 2329 | function wp_get_session_token() { |
2330 | - $cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
2331 | - return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; |
|
2330 | + $cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
2331 | + return ! empty($cookie['token']) ? $cookie['token'] : ''; |
|
2332 | 2332 | } |
2333 | 2333 | |
2334 | 2334 | /** |
@@ -2338,7 +2338,7 @@ discard block |
||
2338 | 2338 | * @return array Array of sessions. |
2339 | 2339 | */ |
2340 | 2340 | function wp_get_all_sessions() { |
2341 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2341 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
2342 | 2342 | return $manager->get_all(); |
2343 | 2343 | } |
2344 | 2344 | |
@@ -2349,9 +2349,9 @@ discard block |
||
2349 | 2349 | */ |
2350 | 2350 | function wp_destroy_current_session() { |
2351 | 2351 | $token = wp_get_session_token(); |
2352 | - if ( $token ) { |
|
2353 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2354 | - $manager->destroy( $token ); |
|
2352 | + if ($token) { |
|
2353 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
2354 | + $manager->destroy($token); |
|
2355 | 2355 | } |
2356 | 2356 | } |
2357 | 2357 | |
@@ -2362,9 +2362,9 @@ discard block |
||
2362 | 2362 | */ |
2363 | 2363 | function wp_destroy_other_sessions() { |
2364 | 2364 | $token = wp_get_session_token(); |
2365 | - if ( $token ) { |
|
2366 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2367 | - $manager->destroy_others( $token ); |
|
2365 | + if ($token) { |
|
2366 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
2367 | + $manager->destroy_others($token); |
|
2368 | 2368 | } |
2369 | 2369 | } |
2370 | 2370 | |
@@ -2374,7 +2374,7 @@ discard block |
||
2374 | 2374 | * @since 4.0.0 |
2375 | 2375 | */ |
2376 | 2376 | function wp_destroy_all_sessions() { |
2377 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
2377 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
2378 | 2378 | $manager->destroy_all(); |
2379 | 2379 | } |
2380 | 2380 | |
@@ -2390,19 +2390,19 @@ discard block |
||
2390 | 2390 | function wp_get_users_with_no_role() { |
2391 | 2391 | global $wpdb; |
2392 | 2392 | |
2393 | - if ( is_multisite() ) { |
|
2393 | + if (is_multisite()) { |
|
2394 | 2394 | return array(); |
2395 | 2395 | } |
2396 | 2396 | |
2397 | 2397 | $prefix = $wpdb->get_blog_prefix(); |
2398 | - $regex = implode( '|', wp_roles()->get_names() ); |
|
2399 | - $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); |
|
2400 | - $users = $wpdb->get_col( $wpdb->prepare( " |
|
2398 | + $regex = implode('|', wp_roles()->get_names()); |
|
2399 | + $regex = preg_replace('/[^a-zA-Z_\|-]/', '', $regex); |
|
2400 | + $users = $wpdb->get_col($wpdb->prepare(" |
|
2401 | 2401 | SELECT user_id |
2402 | 2402 | FROM $wpdb->usermeta |
2403 | 2403 | WHERE meta_key = '{$prefix}capabilities' |
2404 | 2404 | AND meta_value NOT REGEXP %s |
2405 | - ", $regex ) ); |
|
2405 | + ", $regex)); |
|
2406 | 2406 | |
2407 | 2407 | return $users; |
2408 | 2408 | } |
@@ -2429,27 +2429,27 @@ discard block |
||
2429 | 2429 | function _wp_get_current_user() { |
2430 | 2430 | global $current_user; |
2431 | 2431 | |
2432 | - if ( ! empty( $current_user ) ) { |
|
2433 | - if ( $current_user instanceof WP_User ) { |
|
2432 | + if ( ! empty($current_user)) { |
|
2433 | + if ($current_user instanceof WP_User) { |
|
2434 | 2434 | return $current_user; |
2435 | 2435 | } |
2436 | 2436 | |
2437 | 2437 | // Upgrade stdClass to WP_User |
2438 | - if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
|
2438 | + if (is_object($current_user) && isset($current_user->ID)) { |
|
2439 | 2439 | $cur_id = $current_user->ID; |
2440 | 2440 | $current_user = null; |
2441 | - wp_set_current_user( $cur_id ); |
|
2441 | + wp_set_current_user($cur_id); |
|
2442 | 2442 | return $current_user; |
2443 | 2443 | } |
2444 | 2444 | |
2445 | 2445 | // $current_user has a junk value. Force to WP_User with ID 0. |
2446 | 2446 | $current_user = null; |
2447 | - wp_set_current_user( 0 ); |
|
2447 | + wp_set_current_user(0); |
|
2448 | 2448 | return $current_user; |
2449 | 2449 | } |
2450 | 2450 | |
2451 | - if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) { |
|
2452 | - wp_set_current_user( 0 ); |
|
2451 | + if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) { |
|
2452 | + wp_set_current_user(0); |
|
2453 | 2453 | return $current_user; |
2454 | 2454 | } |
2455 | 2455 | |
@@ -2466,13 +2466,13 @@ discard block |
||
2466 | 2466 | * |
2467 | 2467 | * @param int|bool $user_id User ID if one has been determined, false otherwise. |
2468 | 2468 | */ |
2469 | - $user_id = apply_filters( 'determine_current_user', false ); |
|
2470 | - if ( ! $user_id ) { |
|
2471 | - wp_set_current_user( 0 ); |
|
2469 | + $user_id = apply_filters('determine_current_user', false); |
|
2470 | + if ( ! $user_id) { |
|
2471 | + wp_set_current_user(0); |
|
2472 | 2472 | return $current_user; |
2473 | 2473 | } |
2474 | 2474 | |
2475 | - wp_set_current_user( $user_id ); |
|
2475 | + wp_set_current_user($user_id); |
|
2476 | 2476 | |
2477 | 2477 | return $current_user; |
2478 | 2478 | } |
@@ -27,18 +27,22 @@ discard block |
||
27 | 27 | */ |
28 | 28 | function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
29 | 29 | if ( empty($credentials) ) { |
30 | - if ( ! empty($_POST['log']) ) |
|
31 | - $credentials['user_login'] = $_POST['log']; |
|
32 | - if ( ! empty($_POST['pwd']) ) |
|
33 | - $credentials['user_password'] = $_POST['pwd']; |
|
34 | - if ( ! empty($_POST['rememberme']) ) |
|
35 | - $credentials['remember'] = $_POST['rememberme']; |
|
30 | + if ( ! empty($_POST['log']) ) { |
|
31 | + $credentials['user_login'] = $_POST['log']; |
|
32 | + } |
|
33 | + if ( ! empty($_POST['pwd']) ) { |
|
34 | + $credentials['user_password'] = $_POST['pwd']; |
|
35 | + } |
|
36 | + if ( ! empty($_POST['rememberme']) ) { |
|
37 | + $credentials['remember'] = $_POST['rememberme']; |
|
38 | + } |
|
36 | 39 | } |
37 | 40 | |
38 | - if ( !empty($credentials['remember']) ) |
|
39 | - $credentials['remember'] = true; |
|
40 | - else |
|
41 | - $credentials['remember'] = false; |
|
41 | + if ( !empty($credentials['remember']) ) { |
|
42 | + $credentials['remember'] = true; |
|
43 | + } else { |
|
44 | + $credentials['remember'] = false; |
|
45 | + } |
|
42 | 46 | |
43 | 47 | /** |
44 | 48 | * Fires before the user is authenticated. |
@@ -55,8 +59,9 @@ discard block |
||
55 | 59 | */ |
56 | 60 | do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
57 | 61 | |
58 | - if ( '' === $secure_cookie ) |
|
59 | - $secure_cookie = is_ssl(); |
|
62 | + if ( '' === $secure_cookie ) { |
|
63 | + $secure_cookie = is_ssl(); |
|
64 | + } |
|
60 | 65 | |
61 | 66 | /** |
62 | 67 | * Filter whether to use a secure sign-on cookie. |
@@ -119,16 +124,19 @@ discard block |
||
119 | 124 | } |
120 | 125 | |
121 | 126 | if ( empty($username) || empty($password) ) { |
122 | - if ( is_wp_error( $user ) ) |
|
123 | - return $user; |
|
127 | + if ( is_wp_error( $user ) ) { |
|
128 | + return $user; |
|
129 | + } |
|
124 | 130 | |
125 | 131 | $error = new WP_Error(); |
126 | 132 | |
127 | - if ( empty($username) ) |
|
128 | - $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
133 | + if ( empty($username) ) { |
|
134 | + $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
135 | + } |
|
129 | 136 | |
130 | - if ( empty($password) ) |
|
131 | - $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
137 | + if ( empty($password) ) { |
|
138 | + $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
139 | + } |
|
132 | 140 | |
133 | 141 | return $error; |
134 | 142 | } |
@@ -154,8 +162,9 @@ discard block |
||
154 | 162 | * @param string $password Password to check against the user. |
155 | 163 | */ |
156 | 164 | $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
157 | - if ( is_wp_error($user) ) |
|
158 | - return $user; |
|
165 | + if ( is_wp_error($user) ) { |
|
166 | + return $user; |
|
167 | + } |
|
159 | 168 | |
160 | 169 | if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
161 | 170 | return new WP_Error( 'incorrect_password', |
@@ -264,18 +273,21 @@ discard block |
||
264 | 273 | |
265 | 274 | if ( empty($username) && empty($password) ) { |
266 | 275 | $user_id = wp_validate_auth_cookie(); |
267 | - if ( $user_id ) |
|
268 | - return new WP_User($user_id); |
|
276 | + if ( $user_id ) { |
|
277 | + return new WP_User($user_id); |
|
278 | + } |
|
269 | 279 | |
270 | 280 | global $auth_secure_cookie; |
271 | 281 | |
272 | - if ( $auth_secure_cookie ) |
|
273 | - $auth_cookie = SECURE_AUTH_COOKIE; |
|
274 | - else |
|
275 | - $auth_cookie = AUTH_COOKIE; |
|
282 | + if ( $auth_secure_cookie ) { |
|
283 | + $auth_cookie = SECURE_AUTH_COOKIE; |
|
284 | + } else { |
|
285 | + $auth_cookie = AUTH_COOKIE; |
|
286 | + } |
|
276 | 287 | |
277 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
278 | - return new WP_Error('expired_session', __('Please log in again.')); |
|
288 | + if ( !empty($_COOKIE[$auth_cookie]) ) { |
|
289 | + return new WP_Error('expired_session', __('Please log in again.')); |
|
290 | + } |
|
279 | 291 | |
280 | 292 | // If the cookie is not set, be silent. |
281 | 293 | } |
@@ -304,8 +316,9 @@ discard block |
||
304 | 316 | */ |
305 | 317 | $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
306 | 318 | |
307 | - if ( $spammed ) |
|
308 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
319 | + if ( $spammed ) { |
|
320 | + return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
321 | + } |
|
309 | 322 | } |
310 | 323 | return $user; |
311 | 324 | } |
@@ -390,8 +403,9 @@ discard block |
||
390 | 403 | global $wpdb; |
391 | 404 | |
392 | 405 | $count = array(); |
393 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
394 | - return $count; |
|
406 | + if ( empty( $users ) || ! is_array( $users ) ) { |
|
407 | + return $count; |
|
408 | + } |
|
395 | 409 | |
396 | 410 | $userlist = implode( ',', array_map( 'absint', $users ) ); |
397 | 411 | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
@@ -402,8 +416,9 @@ discard block |
||
402 | 416 | } |
403 | 417 | |
404 | 418 | foreach ( $users as $id ) { |
405 | - if ( ! isset( $count[ $id ] ) ) |
|
406 | - $count[ $id ] = 0; |
|
419 | + if ( ! isset( $count[ $id ] ) ) { |
|
420 | + $count[ $id ] = 0; |
|
421 | + } |
|
407 | 422 | } |
408 | 423 | |
409 | 424 | return $count; |
@@ -421,8 +436,9 @@ discard block |
||
421 | 436 | * @return int The current user's ID |
422 | 437 | */ |
423 | 438 | function get_current_user_id() { |
424 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
425 | - return 0; |
|
439 | + if ( ! function_exists( 'wp_get_current_user' ) ) { |
|
440 | + return 0; |
|
441 | + } |
|
426 | 442 | $user = wp_get_current_user(); |
427 | 443 | return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
428 | 444 | } |
@@ -449,22 +465,28 @@ discard block |
||
449 | 465 | function get_user_option( $option, $user = 0, $deprecated = '' ) { |
450 | 466 | global $wpdb; |
451 | 467 | |
452 | - if ( !empty( $deprecated ) ) |
|
453 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
468 | + if ( !empty( $deprecated ) ) { |
|
469 | + _deprecated_argument( __FUNCTION__, '3.0' ); |
|
470 | + } |
|
454 | 471 | |
455 | - if ( empty( $user ) ) |
|
456 | - $user = get_current_user_id(); |
|
472 | + if ( empty( $user ) ) { |
|
473 | + $user = get_current_user_id(); |
|
474 | + } |
|
457 | 475 | |
458 | - if ( ! $user = get_userdata( $user ) ) |
|
459 | - return false; |
|
476 | + if ( ! $user = get_userdata( $user ) ) { |
|
477 | + return false; |
|
478 | + } |
|
460 | 479 | |
461 | 480 | $prefix = $wpdb->get_blog_prefix(); |
462 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
481 | + if ( $user->has_prop( $prefix . $option ) ) { |
|
482 | + // Blog specific |
|
463 | 483 | $result = $user->get( $prefix . $option ); |
464 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
484 | + } elseif ( $user->has_prop( $option ) ) { |
|
485 | + // User specific and cross-blog |
|
465 | 486 | $result = $user->get( $option ); |
466 | - else |
|
467 | - $result = false; |
|
487 | + } else { |
|
488 | + $result = false; |
|
489 | + } |
|
468 | 490 | |
469 | 491 | /** |
470 | 492 | * Filter a specific user option value. |
@@ -504,8 +526,9 @@ discard block |
||
504 | 526 | function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
505 | 527 | global $wpdb; |
506 | 528 | |
507 | - if ( !$global ) |
|
508 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
529 | + if ( !$global ) { |
|
530 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
531 | + } |
|
509 | 532 | |
510 | 533 | return update_user_meta( $user_id, $option_name, $newvalue ); |
511 | 534 | } |
@@ -530,8 +553,9 @@ discard block |
||
530 | 553 | function delete_user_option( $user_id, $option_name, $global = false ) { |
531 | 554 | global $wpdb; |
532 | 555 | |
533 | - if ( !$global ) |
|
534 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
556 | + if ( !$global ) { |
|
557 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
558 | + } |
|
535 | 559 | return delete_user_meta( $user_id, $option_name ); |
536 | 560 | } |
537 | 561 | |
@@ -575,12 +599,14 @@ discard block |
||
575 | 599 | $user_id = (int) $user_id; |
576 | 600 | |
577 | 601 | // Logged out users can't have blogs |
578 | - if ( empty( $user_id ) ) |
|
579 | - return array(); |
|
602 | + if ( empty( $user_id ) ) { |
|
603 | + return array(); |
|
604 | + } |
|
580 | 605 | |
581 | 606 | $keys = get_user_meta( $user_id ); |
582 | - if ( empty( $keys ) ) |
|
583 | - return array(); |
|
607 | + if ( empty( $keys ) ) { |
|
608 | + return array(); |
|
609 | + } |
|
584 | 610 | |
585 | 611 | if ( ! is_multisite() ) { |
586 | 612 | $blog_id = get_current_blog_id(); |
@@ -621,13 +647,16 @@ discard block |
||
621 | 647 | $keys = array_keys( $keys ); |
622 | 648 | |
623 | 649 | foreach ( $keys as $key ) { |
624 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
625 | - continue; |
|
626 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
627 | - continue; |
|
650 | + if ( 'capabilities' !== substr( $key, -12 ) ) { |
|
651 | + continue; |
|
652 | + } |
|
653 | + if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { |
|
654 | + continue; |
|
655 | + } |
|
628 | 656 | $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
629 | - if ( ! is_numeric( $blog_id ) ) |
|
630 | - continue; |
|
657 | + if ( ! is_numeric( $blog_id ) ) { |
|
658 | + continue; |
|
659 | + } |
|
631 | 660 | |
632 | 661 | $blog_id = (int) $blog_id; |
633 | 662 | $blog = get_blog_details( $blog_id ); |
@@ -861,8 +890,9 @@ discard block |
||
861 | 890 | |
862 | 891 | foreach ( $users_of_blog as $caps_meta ) { |
863 | 892 | $b_roles = maybe_unserialize($caps_meta); |
864 | - if ( ! is_array( $b_roles ) ) |
|
865 | - continue; |
|
893 | + if ( ! is_array( $b_roles ) ) { |
|
894 | + continue; |
|
895 | + } |
|
866 | 896 | if ( empty( $b_roles ) ) { |
867 | 897 | $avail_roles['none']++; |
868 | 898 | } |
@@ -910,8 +940,9 @@ discard block |
||
910 | 940 | function setup_userdata($for_user_id = '') { |
911 | 941 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
912 | 942 | |
913 | - if ( '' == $for_user_id ) |
|
914 | - $for_user_id = get_current_user_id(); |
|
943 | + if ( '' == $for_user_id ) { |
|
944 | + $for_user_id = get_current_user_id(); |
|
945 | + } |
|
915 | 946 | $user = get_userdata( $for_user_id ); |
916 | 947 | |
917 | 948 | if ( ! $user ) { |
@@ -1116,14 +1147,17 @@ discard block |
||
1116 | 1147 | */ |
1117 | 1148 | function sanitize_user_field($field, $value, $user_id, $context) { |
1118 | 1149 | $int_fields = array('ID'); |
1119 | - if ( in_array($field, $int_fields) ) |
|
1120 | - $value = (int) $value; |
|
1150 | + if ( in_array($field, $int_fields) ) { |
|
1151 | + $value = (int) $value; |
|
1152 | + } |
|
1121 | 1153 | |
1122 | - if ( 'raw' == $context ) |
|
1123 | - return $value; |
|
1154 | + if ( 'raw' == $context ) { |
|
1155 | + return $value; |
|
1156 | + } |
|
1124 | 1157 | |
1125 | - if ( !is_string($value) && !is_numeric($value) ) |
|
1126 | - return $value; |
|
1158 | + if ( !is_string($value) && !is_numeric($value) ) { |
|
1159 | + return $value; |
|
1160 | + } |
|
1127 | 1161 | |
1128 | 1162 | $prefixed = false !== strpos( $field, 'user_' ); |
1129 | 1163 | |
@@ -1148,10 +1182,13 @@ discard block |
||
1148 | 1182 | $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
1149 | 1183 | } |
1150 | 1184 | |
1151 | - if ( 'description' == $field ) |
|
1152 | - $value = esc_html( $value ); // textarea_escaped? |
|
1153 | - else |
|
1154 | - $value = esc_attr($value); |
|
1185 | + if ( 'description' == $field ) { |
|
1186 | + $value = esc_html( $value ); |
|
1187 | + } |
|
1188 | + // textarea_escaped? |
|
1189 | + else { |
|
1190 | + $value = esc_attr($value); |
|
1191 | + } |
|
1155 | 1192 | } elseif ( 'db' == $context ) { |
1156 | 1193 | if ( $prefixed ) { |
1157 | 1194 | /** This filter is documented in wp-includes/post.php */ |
@@ -1194,8 +1231,9 @@ discard block |
||
1194 | 1231 | } |
1195 | 1232 | } |
1196 | 1233 | |
1197 | - if ( 'user_url' == $field ) |
|
1198 | - $value = esc_url($value); |
|
1234 | + if ( 'user_url' == $field ) { |
|
1235 | + $value = esc_url($value); |
|
1236 | + } |
|
1199 | 1237 | |
1200 | 1238 | if ( 'attribute' == $context ) { |
1201 | 1239 | $value = esc_attr( $value ); |
@@ -1237,11 +1275,13 @@ discard block |
||
1237 | 1275 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
1238 | 1276 | */ |
1239 | 1277 | function clean_user_cache( $user ) { |
1240 | - if ( is_numeric( $user ) ) |
|
1241 | - $user = new WP_User( $user ); |
|
1278 | + if ( is_numeric( $user ) ) { |
|
1279 | + $user = new WP_User( $user ); |
|
1280 | + } |
|
1242 | 1281 | |
1243 | - if ( ! $user->exists() ) |
|
1244 | - return; |
|
1282 | + if ( ! $user->exists() ) { |
|
1283 | + return; |
|
1284 | + } |
|
1245 | 1285 | |
1246 | 1286 | wp_cache_delete( $user->ID, 'users' ); |
1247 | 1287 | wp_cache_delete( $user->user_login, 'userlogins' ); |
@@ -2101,15 +2141,18 @@ discard block |
||
2101 | 2141 | |
2102 | 2142 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
2103 | 2143 | |
2104 | - if ( empty( $key ) || !is_string( $key ) ) |
|
2105 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
2144 | + if ( empty( $key ) || !is_string( $key ) ) { |
|
2145 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
2146 | + } |
|
2106 | 2147 | |
2107 | - if ( empty($login) || !is_string($login) ) |
|
2108 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
2148 | + if ( empty($login) || !is_string($login) ) { |
|
2149 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
2150 | + } |
|
2109 | 2151 | |
2110 | 2152 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
2111 | - if ( ! $row ) |
|
2112 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
2153 | + if ( ! $row ) { |
|
2154 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
2155 | + } |
|
2113 | 2156 | |
2114 | 2157 | if ( empty( $wp_hasher ) ) { |
2115 | 2158 | require_once ABSPATH . WPINC . '/class-phpass.php'; |
@@ -2280,8 +2323,9 @@ discard block |
||
2280 | 2323 | */ |
2281 | 2324 | $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
2282 | 2325 | |
2283 | - if ( $errors->get_error_code() ) |
|
2284 | - return $errors; |
|
2326 | + if ( $errors->get_error_code() ) { |
|
2327 | + return $errors; |
|
2328 | + } |
|
2285 | 2329 | |
2286 | 2330 | $user_pass = wp_generate_password( 12, false ); |
2287 | 2331 | $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * |
550 | 550 | * @global array $wp_registered_widget_controls |
551 | 551 | * |
552 | - * @param int|string $id Widget ID. |
|
552 | + * @param boolean|string $id Widget ID. |
|
553 | 553 | * @param string $name Name attribute for the widget. |
554 | 554 | * @param callable $form_callback Form callback. |
555 | 555 | * @param array $options Optional. Widget control options. See {@see wp_register_widget_control()}. |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @global array $wp_registered_sidebars |
608 | 608 | * @global array $wp_registered_widgets |
609 | 609 | * |
610 | - * @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
|
610 | + * @param integer $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
|
611 | 611 | * @return bool True, if widget sidebar was found and called. False if not found or not called. |
612 | 612 | */ |
613 | 613 | function dynamic_sidebar( $index = 1 ) { |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | * |
845 | 845 | * @since 2.8.0 |
846 | 846 | * |
847 | - * @param string|int $index Sidebar name, id or number to check. |
|
847 | + * @param string $index Sidebar name, id or number to check. |
|
848 | 848 | * @return bool true if the sidebar is in use, false otherwise. |
849 | 849 | */ |
850 | 850 | function is_active_sidebar( $index ) { |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Core Widgets API |
|
4 | - * |
|
5 | - * This API is used for creating dynamic sidebar without hardcoding functionality into |
|
6 | - * themes |
|
7 | - * |
|
8 | - * Includes both internal WordPress routines and theme-use routines. |
|
9 | - * |
|
10 | - * This functionality was found in a plugin before the WordPress 2.2 release, which |
|
11 | - * included it in the core from that point on. |
|
12 | - * |
|
13 | - * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
|
14 | - * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
|
15 | - * |
|
16 | - * @package WordPress |
|
17 | - * @subpackage Widgets |
|
18 | - * @since 2.2.0 |
|
19 | - */ |
|
3 | + * Core Widgets API |
|
4 | + * |
|
5 | + * This API is used for creating dynamic sidebar without hardcoding functionality into |
|
6 | + * themes |
|
7 | + * |
|
8 | + * Includes both internal WordPress routines and theme-use routines. |
|
9 | + * |
|
10 | + * This functionality was found in a plugin before the WordPress 2.2 release, which |
|
11 | + * included it in the core from that point on. |
|
12 | + * |
|
13 | + * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
|
14 | + * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
|
15 | + * |
|
16 | + * @package WordPress |
|
17 | + * @subpackage Widgets |
|
18 | + * @since 2.2.0 |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | // |
22 | 22 | // Global Variables |
@@ -159,34 +159,34 @@ discard block |
||
159 | 159 | * Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'. |
160 | 160 | * } |
161 | 161 | */ |
162 | -function register_sidebars( $number = 1, $args = array() ) { |
|
162 | +function register_sidebars($number = 1, $args = array()) { |
|
163 | 163 | global $wp_registered_sidebars; |
164 | 164 | $number = (int) $number; |
165 | 165 | |
166 | - if ( is_string($args) ) |
|
166 | + if (is_string($args)) |
|
167 | 167 | parse_str($args, $args); |
168 | 168 | |
169 | - for ( $i = 1; $i <= $number; $i++ ) { |
|
169 | + for ($i = 1; $i <= $number; $i++) { |
|
170 | 170 | $_args = $args; |
171 | 171 | |
172 | - if ( $number > 1 ) |
|
172 | + if ($number > 1) |
|
173 | 173 | $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
174 | 174 | else |
175 | 175 | $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
176 | 176 | |
177 | 177 | // Custom specified ID's are suffixed if they exist already. |
178 | 178 | // Automatically generated sidebar names need to be suffixed regardless starting at -0 |
179 | - if ( isset($args['id']) ) { |
|
179 | + if (isset($args['id'])) { |
|
180 | 180 | $_args['id'] = $args['id']; |
181 | 181 | $n = 2; // Start at -2 for conflicting custom ID's |
182 | - while ( is_registered_sidebar( $_args['id'] ) ) { |
|
183 | - $_args['id'] = $args['id'] . '-' . $n++; |
|
182 | + while (is_registered_sidebar($_args['id'])) { |
|
183 | + $_args['id'] = $args['id'].'-'.$n++; |
|
184 | 184 | } |
185 | 185 | } else { |
186 | - $n = count( $wp_registered_sidebars ); |
|
186 | + $n = count($wp_registered_sidebars); |
|
187 | 187 | do { |
188 | - $_args['id'] = 'sidebar-' . ++$n; |
|
189 | - } while ( is_registered_sidebar( $_args['id'] ) ); |
|
188 | + $_args['id'] = 'sidebar-'.++$n; |
|
189 | + } while (is_registered_sidebar($_args['id'])); |
|
190 | 190 | } |
191 | 191 | register_sidebar($_args); |
192 | 192 | } |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | |
239 | 239 | $i = count($wp_registered_sidebars) + 1; |
240 | 240 | |
241 | - $id_is_empty = empty( $args['id'] ); |
|
241 | + $id_is_empty = empty($args['id']); |
|
242 | 242 | |
243 | 243 | $defaults = array( |
244 | - 'name' => sprintf(__('Sidebar %d'), $i ), |
|
244 | + 'name' => sprintf(__('Sidebar %d'), $i), |
|
245 | 245 | 'id' => "sidebar-$i", |
246 | 246 | 'description' => '', |
247 | 247 | 'class' => '', |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | 'after_title' => "</h2>\n", |
252 | 252 | ); |
253 | 253 | |
254 | - $sidebar = wp_parse_args( $args, $defaults ); |
|
254 | + $sidebar = wp_parse_args($args, $defaults); |
|
255 | 255 | |
256 | - if ( $id_is_empty ) { |
|
256 | + if ($id_is_empty) { |
|
257 | 257 | /* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */ |
258 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' ); |
|
258 | + _doing_it_wrong(__FUNCTION__, sprintf(__('No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.'), '<code>id</code>', $sidebar['name'], $sidebar['id']), '4.2.0'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | $wp_registered_sidebars[$sidebar['id']] = $sidebar; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @param array $sidebar Parsed arguments for the registered sidebar. |
271 | 271 | */ |
272 | - do_action( 'register_sidebar', $sidebar ); |
|
272 | + do_action('register_sidebar', $sidebar); |
|
273 | 273 | |
274 | 274 | return $sidebar['id']; |
275 | 275 | } |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @param string $name The ID of the sidebar when it was added. |
285 | 285 | */ |
286 | -function unregister_sidebar( $name ) { |
|
286 | +function unregister_sidebar($name) { |
|
287 | 287 | global $wp_registered_sidebars; |
288 | 288 | |
289 | - unset( $wp_registered_sidebars[ $name ] ); |
|
289 | + unset($wp_registered_sidebars[$name]); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | * @param string|int $sidebar_id The ID of the sidebar when it was registered. |
300 | 300 | * @return bool True if the sidebar is registered, false otherwise. |
301 | 301 | */ |
302 | -function is_registered_sidebar( $sidebar_id ) { |
|
302 | +function is_registered_sidebar($sidebar_id) { |
|
303 | 303 | global $wp_registered_sidebars; |
304 | 304 | |
305 | - return isset( $wp_registered_sidebars[ $sidebar_id ] ); |
|
305 | + return isset($wp_registered_sidebars[$sidebar_id]); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -332,20 +332,20 @@ discard block |
||
332 | 332 | * panel and/or theme. |
333 | 333 | * } |
334 | 334 | */ |
335 | -function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) { |
|
335 | +function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) { |
|
336 | 336 | global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; |
337 | 337 | |
338 | 338 | $id = strtolower($id); |
339 | 339 | |
340 | - if ( empty($output_callback) ) { |
|
340 | + if (empty($output_callback)) { |
|
341 | 341 | unset($wp_registered_widgets[$id]); |
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
345 | 345 | $id_base = _get_widget_id_base($id); |
346 | - if ( in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback) ) { |
|
347 | - unset( $wp_registered_widget_controls[ $id ] ); |
|
348 | - unset( $wp_registered_widget_updates[ $id_base ] ); |
|
346 | + if (in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && ! is_callable($output_callback)) { |
|
347 | + unset($wp_registered_widget_controls[$id]); |
|
348 | + unset($wp_registered_widget_updates[$id_base]); |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | ); |
360 | 360 | $widget = array_merge($widget, $options); |
361 | 361 | |
362 | - if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) { |
|
362 | + if (is_callable($output_callback) && ( ! isset($wp_registered_widgets[$id]) || did_action('widgets_init'))) { |
|
363 | 363 | |
364 | 364 | /** |
365 | 365 | * Fires once for each registered widget. |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @param array $widget An array of default widget arguments. |
370 | 370 | */ |
371 | - do_action( 'wp_register_sidebar_widget', $widget ); |
|
371 | + do_action('wp_register_sidebar_widget', $widget); |
|
372 | 372 | $wp_registered_widgets[$id] = $widget; |
373 | 373 | } |
374 | 374 | } |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | * @param int|string $id Widget ID. |
388 | 388 | * @return string|void Widget description, if available. |
389 | 389 | */ |
390 | -function wp_widget_description( $id ) { |
|
391 | - if ( !is_scalar($id) ) |
|
390 | +function wp_widget_description($id) { |
|
391 | + if ( ! is_scalar($id)) |
|
392 | 392 | return; |
393 | 393 | |
394 | 394 | global $wp_registered_widgets; |
395 | 395 | |
396 | - if ( isset($wp_registered_widgets[$id]['description']) ) |
|
397 | - return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
396 | + if (isset($wp_registered_widgets[$id]['description'])) |
|
397 | + return esc_html($wp_registered_widgets[$id]['description']); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | * @param string $id sidebar ID. |
411 | 411 | * @return string|void Sidebar description, if available. |
412 | 412 | */ |
413 | -function wp_sidebar_description( $id ) { |
|
414 | - if ( !is_scalar($id) ) |
|
413 | +function wp_sidebar_description($id) { |
|
414 | + if ( ! is_scalar($id)) |
|
415 | 415 | return; |
416 | 416 | |
417 | 417 | global $wp_registered_sidebars; |
418 | 418 | |
419 | - if ( isset($wp_registered_sidebars[$id]['description']) ) |
|
420 | - return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
419 | + if (isset($wp_registered_sidebars[$id]['description'])) |
|
420 | + return esc_html($wp_registered_sidebars[$id]['description']); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @param int $id The widget ID. |
438 | 438 | */ |
439 | - do_action( 'wp_unregister_sidebar_widget', $id ); |
|
439 | + do_action('wp_unregister_sidebar_widget', $id); |
|
440 | 440 | |
441 | 441 | wp_register_sidebar_widget($id, '', ''); |
442 | 442 | wp_unregister_widget_control($id); |
@@ -467,27 +467,27 @@ discard block |
||
467 | 467 | * text widget. The widget id will end up looking like `{$id_base}-{$unique_number}`. |
468 | 468 | * } |
469 | 469 | */ |
470 | -function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) { |
|
470 | +function wp_register_widget_control($id, $name, $control_callback, $options = array()) { |
|
471 | 471 | global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks; |
472 | 472 | |
473 | 473 | $id = strtolower($id); |
474 | 474 | $id_base = _get_widget_id_base($id); |
475 | 475 | |
476 | - if ( empty($control_callback) ) { |
|
476 | + if (empty($control_callback)) { |
|
477 | 477 | unset($wp_registered_widget_controls[$id]); |
478 | 478 | unset($wp_registered_widget_updates[$id_base]); |
479 | 479 | return; |
480 | 480 | } |
481 | 481 | |
482 | - if ( in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($control_callback) ) { |
|
483 | - unset( $wp_registered_widgets[ $id ] ); |
|
482 | + if (in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && ! is_callable($control_callback)) { |
|
483 | + unset($wp_registered_widgets[$id]); |
|
484 | 484 | return; |
485 | 485 | } |
486 | 486 | |
487 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
487 | + if (isset($wp_registered_widget_controls[$id]) && ! did_action('widgets_init')) |
|
488 | 488 | return; |
489 | 489 | |
490 | - $defaults = array('width' => 250, 'height' => 200 ); // height is never used |
|
490 | + $defaults = array('width' => 250, 'height' => 200); // height is never used |
|
491 | 491 | $options = wp_parse_args($options, $defaults); |
492 | 492 | $options['width'] = (int) $options['width']; |
493 | 493 | $options['height'] = (int) $options['height']; |
@@ -502,10 +502,10 @@ discard block |
||
502 | 502 | |
503 | 503 | $wp_registered_widget_controls[$id] = $widget; |
504 | 504 | |
505 | - if ( isset($wp_registered_widget_updates[$id_base]) ) |
|
505 | + if (isset($wp_registered_widget_updates[$id_base])) |
|
506 | 506 | return; |
507 | 507 | |
508 | - if ( isset($widget['params'][0]['number']) ) |
|
508 | + if (isset($widget['params'][0]['number'])) |
|
509 | 509 | $widget['params'][0]['number'] = -1; |
510 | 510 | |
511 | 511 | unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); |
@@ -524,11 +524,11 @@ discard block |
||
524 | 524 | * @param array $options Optional. Widget control options. See {@see wp_register_widget_control()}. |
525 | 525 | * Default empty array. |
526 | 526 | */ |
527 | -function _register_widget_update_callback( $id_base, $update_callback, $options = array() ) { |
|
527 | +function _register_widget_update_callback($id_base, $update_callback, $options = array()) { |
|
528 | 528 | global $wp_registered_widget_updates; |
529 | 529 | |
530 | - if ( isset($wp_registered_widget_updates[$id_base]) ) { |
|
531 | - if ( empty($update_callback) ) |
|
530 | + if (isset($wp_registered_widget_updates[$id_base])) { |
|
531 | + if (empty($update_callback)) |
|
532 | 532 | unset($wp_registered_widget_updates[$id_base]); |
533 | 533 | return; |
534 | 534 | } |
@@ -560,15 +560,15 @@ discard block |
||
560 | 560 | |
561 | 561 | $id = strtolower($id); |
562 | 562 | |
563 | - if ( empty($form_callback) ) { |
|
563 | + if (empty($form_callback)) { |
|
564 | 564 | unset($wp_registered_widget_controls[$id]); |
565 | 565 | return; |
566 | 566 | } |
567 | 567 | |
568 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
568 | + if (isset($wp_registered_widget_controls[$id]) && ! did_action('widgets_init')) |
|
569 | 569 | return; |
570 | 570 | |
571 | - $defaults = array('width' => 250, 'height' => 200 ); |
|
571 | + $defaults = array('width' => 250, 'height' => 200); |
|
572 | 572 | $options = wp_parse_args($options, $defaults); |
573 | 573 | $options['width'] = (int) $options['width']; |
574 | 574 | $options['height'] = (int) $options['height']; |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | * @param int|string $id Widget ID. |
593 | 593 | */ |
594 | 594 | function wp_unregister_widget_control($id) { |
595 | - wp_register_widget_control( $id, '', '' ); |
|
595 | + wp_register_widget_control($id, '', ''); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | * @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
611 | 611 | * @return bool True, if widget sidebar was found and called. False if not found or not called. |
612 | 612 | */ |
613 | -function dynamic_sidebar( $index = 1 ) { |
|
613 | +function dynamic_sidebar($index = 1) { |
|
614 | 614 | global $wp_registered_sidebars, $wp_registered_widgets; |
615 | 615 | |
616 | - if ( is_int( $index ) ) { |
|
616 | + if (is_int($index)) { |
|
617 | 617 | $index = "sidebar-$index"; |
618 | 618 | } else { |
619 | - $index = sanitize_title( $index ); |
|
620 | - foreach ( (array) $wp_registered_sidebars as $key => $value ) { |
|
621 | - if ( sanitize_title( $value['name'] ) == $index ) { |
|
619 | + $index = sanitize_title($index); |
|
620 | + foreach ((array) $wp_registered_sidebars as $key => $value) { |
|
621 | + if (sanitize_title($value['name']) == $index) { |
|
622 | 622 | $index = $key; |
623 | 623 | break; |
624 | 624 | } |
@@ -626,13 +626,13 @@ discard block |
||
626 | 626 | } |
627 | 627 | |
628 | 628 | $sidebars_widgets = wp_get_sidebars_widgets(); |
629 | - if ( empty( $wp_registered_sidebars[ $index ] ) || empty( $sidebars_widgets[ $index ] ) || ! is_array( $sidebars_widgets[ $index ] ) ) { |
|
629 | + if (empty($wp_registered_sidebars[$index]) || empty($sidebars_widgets[$index]) || ! is_array($sidebars_widgets[$index])) { |
|
630 | 630 | /** This action is documented in wp-includes/widget.php */ |
631 | - do_action( 'dynamic_sidebar_before', $index, false ); |
|
631 | + do_action('dynamic_sidebar_before', $index, false); |
|
632 | 632 | /** This action is documented in wp-includes/widget.php */ |
633 | - do_action( 'dynamic_sidebar_after', $index, false ); |
|
633 | + do_action('dynamic_sidebar_after', $index, false); |
|
634 | 634 | /** This filter is documented in wp-includes/widget.php */ |
635 | - return apply_filters( 'dynamic_sidebar_has_widgets', false, $index ); |
|
635 | + return apply_filters('dynamic_sidebar_has_widgets', false, $index); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -647,26 +647,26 @@ discard block |
||
647 | 647 | * @param bool $has_widgets Whether the sidebar is populated with widgets. |
648 | 648 | * Default true. |
649 | 649 | */ |
650 | - do_action( 'dynamic_sidebar_before', $index, true ); |
|
650 | + do_action('dynamic_sidebar_before', $index, true); |
|
651 | 651 | $sidebar = $wp_registered_sidebars[$index]; |
652 | 652 | |
653 | 653 | $did_one = false; |
654 | - foreach ( (array) $sidebars_widgets[$index] as $id ) { |
|
654 | + foreach ((array) $sidebars_widgets[$index] as $id) { |
|
655 | 655 | |
656 | - if ( !isset($wp_registered_widgets[$id]) ) continue; |
|
656 | + if ( ! isset($wp_registered_widgets[$id])) continue; |
|
657 | 657 | |
658 | 658 | $params = array_merge( |
659 | - array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
|
659 | + array(array_merge($sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']))), |
|
660 | 660 | (array) $wp_registered_widgets[$id]['params'] |
661 | 661 | ); |
662 | 662 | |
663 | 663 | // Substitute HTML id and class attributes into before_widget |
664 | 664 | $classname_ = ''; |
665 | - foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
|
666 | - if ( is_string($cn) ) |
|
667 | - $classname_ .= '_' . $cn; |
|
668 | - elseif ( is_object($cn) ) |
|
669 | - $classname_ .= '_' . get_class($cn); |
|
665 | + foreach ((array) $wp_registered_widgets[$id]['classname'] as $cn) { |
|
666 | + if (is_string($cn)) |
|
667 | + $classname_ .= '_'.$cn; |
|
668 | + elseif (is_object($cn)) |
|
669 | + $classname_ .= '_'.get_class($cn); |
|
670 | 670 | } |
671 | 671 | $classname_ = ltrim($classname_, '_'); |
672 | 672 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | * } |
704 | 704 | * } |
705 | 705 | */ |
706 | - $params = apply_filters( 'dynamic_sidebar_params', $params ); |
|
706 | + $params = apply_filters('dynamic_sidebar_params', $params); |
|
707 | 707 | |
708 | 708 | $callback = $wp_registered_widgets[$id]['callback']; |
709 | 709 | |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | * with an array containing the widget object, see $callback. |
733 | 733 | * } |
734 | 734 | */ |
735 | - do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); |
|
735 | + do_action('dynamic_sidebar', $wp_registered_widgets[$id]); |
|
736 | 736 | |
737 | - if ( is_callable($callback) ) { |
|
737 | + if (is_callable($callback)) { |
|
738 | 738 | call_user_func_array($callback, $params); |
739 | 739 | $did_one = true; |
740 | 740 | } |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | * @param bool $has_widgets Whether the sidebar is populated with widgets. |
753 | 753 | * Default true. |
754 | 754 | */ |
755 | - do_action( 'dynamic_sidebar_after', $index, true ); |
|
755 | + do_action('dynamic_sidebar_after', $index, true); |
|
756 | 756 | |
757 | 757 | /** |
758 | 758 | * Filter whether a sidebar has widgets. |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | * Default false. |
767 | 767 | * @param int|string $index Index, name, or ID of the dynamic sidebar. |
768 | 768 | */ |
769 | - return apply_filters( 'dynamic_sidebar_has_widgets', $did_one, $index ); |
|
769 | + return apply_filters('dynamic_sidebar_has_widgets', $did_one, $index); |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | /** |
@@ -792,21 +792,21 @@ discard block |
||
792 | 792 | * @param bool $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'. Default true. |
793 | 793 | * @return string|false False if widget is not active or id of sidebar in which the widget is active. |
794 | 794 | */ |
795 | -function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) { |
|
795 | +function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true) { |
|
796 | 796 | global $wp_registered_widgets; |
797 | 797 | |
798 | 798 | $sidebars_widgets = wp_get_sidebars_widgets(); |
799 | 799 | |
800 | - if ( is_array($sidebars_widgets) ) { |
|
801 | - foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
|
802 | - if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) { |
|
800 | + if (is_array($sidebars_widgets)) { |
|
801 | + foreach ($sidebars_widgets as $sidebar => $widgets) { |
|
802 | + if ($skip_inactive && ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16))) { |
|
803 | 803 | continue; |
804 | 804 | } |
805 | 805 | |
806 | - if ( is_array($widgets) ) { |
|
807 | - foreach ( $widgets as $widget ) { |
|
808 | - if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) { |
|
809 | - if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) |
|
806 | + if (is_array($widgets)) { |
|
807 | + foreach ($widgets as $widget) { |
|
808 | + if (($callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback) || ($id_base && _get_widget_id_base($widget) == $id_base)) { |
|
809 | + if ( ! $widget_id || $widget_id == $wp_registered_widgets[$widget]['id']) |
|
810 | 810 | return $sidebar; |
811 | 811 | } |
812 | 812 | } |
@@ -829,10 +829,10 @@ discard block |
||
829 | 829 | function is_dynamic_sidebar() { |
830 | 830 | global $wp_registered_widgets, $wp_registered_sidebars; |
831 | 831 | $sidebars_widgets = get_option('sidebars_widgets'); |
832 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
|
833 | - if ( ! empty( $sidebars_widgets[ $index ] ) ) { |
|
834 | - foreach ( (array) $sidebars_widgets[$index] as $widget ) |
|
835 | - if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
832 | + foreach ((array) $wp_registered_sidebars as $index => $sidebar) { |
|
833 | + if ( ! empty($sidebars_widgets[$index])) { |
|
834 | + foreach ((array) $sidebars_widgets[$index] as $widget) |
|
835 | + if (array_key_exists($widget, $wp_registered_widgets)) |
|
836 | 836 | return true; |
837 | 837 | } |
838 | 838 | } |
@@ -847,10 +847,10 @@ discard block |
||
847 | 847 | * @param string|int $index Sidebar name, id or number to check. |
848 | 848 | * @return bool true if the sidebar is in use, false otherwise. |
849 | 849 | */ |
850 | -function is_active_sidebar( $index ) { |
|
851 | - $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); |
|
850 | +function is_active_sidebar($index) { |
|
851 | + $index = (is_int($index)) ? "sidebar-$index" : sanitize_title($index); |
|
852 | 852 | $sidebars_widgets = wp_get_sidebars_widgets(); |
853 | - $is_active_sidebar = ! empty( $sidebars_widgets[$index] ); |
|
853 | + $is_active_sidebar = ! empty($sidebars_widgets[$index]); |
|
854 | 854 | |
855 | 855 | /** |
856 | 856 | * Filter whether a dynamic sidebar is considered "active". |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | * In other words, whether the sidebar contains any widgets. |
862 | 862 | * @param int|string $index Index, name, or ID of the dynamic sidebar. |
863 | 863 | */ |
864 | - return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index ); |
|
864 | + return apply_filters('is_active_sidebar', $is_active_sidebar, $index); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | // |
@@ -883,16 +883,16 @@ discard block |
||
883 | 883 | * @param bool $deprecated Not used (argument deprecated). |
884 | 884 | * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
885 | 885 | */ |
886 | -function wp_get_sidebars_widgets( $deprecated = true ) { |
|
887 | - if ( $deprecated !== true ) |
|
888 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
886 | +function wp_get_sidebars_widgets($deprecated = true) { |
|
887 | + if ($deprecated !== true) |
|
888 | + _deprecated_argument(__FUNCTION__, '2.8.1'); |
|
889 | 889 | |
890 | 890 | global $_wp_sidebars_widgets, $sidebars_widgets; |
891 | 891 | |
892 | 892 | // If loading from front page, consult $_wp_sidebars_widgets rather than options |
893 | 893 | // to see if wp_convert_widget_settings() has made manipulations in memory. |
894 | - if ( !is_admin() ) { |
|
895 | - if ( empty($_wp_sidebars_widgets) ) |
|
894 | + if ( ! is_admin()) { |
|
895 | + if (empty($_wp_sidebars_widgets)) |
|
896 | 896 | $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
897 | 897 | |
898 | 898 | $sidebars_widgets = $_wp_sidebars_widgets; |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | $sidebars_widgets = get_option('sidebars_widgets', array()); |
901 | 901 | } |
902 | 902 | |
903 | - if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) |
|
903 | + if (is_array($sidebars_widgets) && isset($sidebars_widgets['array_version'])) |
|
904 | 904 | unset($sidebars_widgets['array_version']); |
905 | 905 | |
906 | 906 | /** |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * |
911 | 911 | * @param array $sidebars_widgets An associative array of sidebars and their widgets. |
912 | 912 | */ |
913 | - return apply_filters( 'sidebars_widgets', $sidebars_widgets ); |
|
913 | + return apply_filters('sidebars_widgets', $sidebars_widgets); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
@@ -921,10 +921,10 @@ discard block |
||
921 | 921 | * |
922 | 922 | * @param array $sidebars_widgets Sidebar widgets and their settings. |
923 | 923 | */ |
924 | -function wp_set_sidebars_widgets( $sidebars_widgets ) { |
|
925 | - if ( !isset( $sidebars_widgets['array_version'] ) ) |
|
924 | +function wp_set_sidebars_widgets($sidebars_widgets) { |
|
925 | + if ( ! isset($sidebars_widgets['array_version'])) |
|
926 | 926 | $sidebars_widgets['array_version'] = 3; |
927 | - update_option( 'sidebars_widgets', $sidebars_widgets ); |
|
927 | + update_option('sidebars_widgets', $sidebars_widgets); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | /** |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | |
943 | 943 | $defaults = array(); |
944 | 944 | |
945 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) |
|
945 | + foreach ((array) $wp_registered_sidebars as $index => $sidebar) |
|
946 | 946 | $defaults[$index] = array(); |
947 | 947 | |
948 | 948 | return $defaults; |
@@ -963,35 +963,35 @@ discard block |
||
963 | 963 | function wp_convert_widget_settings($base_name, $option_name, $settings) { |
964 | 964 | // This test may need expanding. |
965 | 965 | $single = $changed = false; |
966 | - if ( empty($settings) ) { |
|
966 | + if (empty($settings)) { |
|
967 | 967 | $single = true; |
968 | 968 | } else { |
969 | - foreach ( array_keys($settings) as $number ) { |
|
970 | - if ( 'number' == $number ) |
|
969 | + foreach (array_keys($settings) as $number) { |
|
970 | + if ('number' == $number) |
|
971 | 971 | continue; |
972 | - if ( !is_numeric($number) ) { |
|
972 | + if ( ! is_numeric($number)) { |
|
973 | 973 | $single = true; |
974 | 974 | break; |
975 | 975 | } |
976 | 976 | } |
977 | 977 | } |
978 | 978 | |
979 | - if ( $single ) { |
|
980 | - $settings = array( 2 => $settings ); |
|
979 | + if ($single) { |
|
980 | + $settings = array(2 => $settings); |
|
981 | 981 | |
982 | 982 | // If loading from the front page, update sidebar in memory but don't save to options |
983 | - if ( is_admin() ) { |
|
983 | + if (is_admin()) { |
|
984 | 984 | $sidebars_widgets = get_option('sidebars_widgets'); |
985 | 985 | } else { |
986 | - if ( empty($GLOBALS['_wp_sidebars_widgets']) ) |
|
986 | + if (empty($GLOBALS['_wp_sidebars_widgets'])) |
|
987 | 987 | $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
988 | 988 | $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; |
989 | 989 | } |
990 | 990 | |
991 | - foreach ( (array) $sidebars_widgets as $index => $sidebar ) { |
|
992 | - if ( is_array($sidebar) ) { |
|
993 | - foreach ( $sidebar as $i => $name ) { |
|
994 | - if ( $base_name == $name ) { |
|
991 | + foreach ((array) $sidebars_widgets as $index => $sidebar) { |
|
992 | + if (is_array($sidebar)) { |
|
993 | + foreach ($sidebar as $i => $name) { |
|
994 | + if ($base_name == $name) { |
|
995 | 995 | $sidebars_widgets[$index][$i] = "$name-2"; |
996 | 996 | $changed = true; |
997 | 997 | break 2; |
@@ -1000,13 +1000,13 @@ discard block |
||
1000 | 1000 | } |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - if ( is_admin() && $changed ) |
|
1003 | + if (is_admin() && $changed) |
|
1004 | 1004 | update_option('sidebars_widgets', $sidebars_widgets); |
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | $settings['_multiwidget'] = 1; |
1008 | - if ( is_admin() ) |
|
1009 | - update_option( $option_name, $settings ); |
|
1008 | + if (is_admin()) |
|
1009 | + update_option($option_name, $settings); |
|
1010 | 1010 | |
1011 | 1011 | return $settings; |
1012 | 1012 | } |
@@ -1033,11 +1033,11 @@ discard block |
||
1033 | 1033 | * Default `</h2>`. |
1034 | 1034 | * } |
1035 | 1035 | */ |
1036 | -function the_widget( $widget, $instance = array(), $args = array() ) { |
|
1036 | +function the_widget($widget, $instance = array(), $args = array()) { |
|
1037 | 1037 | global $wp_widget_factory; |
1038 | 1038 | |
1039 | 1039 | $widget_obj = $wp_widget_factory->widgets[$widget]; |
1040 | - if ( ! ( $widget_obj instanceof WP_Widget ) ) { |
|
1040 | + if ( ! ($widget_obj instanceof WP_Widget)) { |
|
1041 | 1041 | return; |
1042 | 1042 | } |
1043 | 1043 | |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | 'before_title' => '<h2 class="widgettitle">', |
1048 | 1048 | 'after_title' => '</h2>', |
1049 | 1049 | ); |
1050 | - $args = wp_parse_args( $args, $default_args ); |
|
1051 | - $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] ); |
|
1050 | + $args = wp_parse_args($args, $default_args); |
|
1051 | + $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']); |
|
1052 | 1052 | |
1053 | 1053 | $instance = wp_parse_args($instance); |
1054 | 1054 | |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | * @param array $instance The current widget instance's settings. |
1062 | 1062 | * @param array $args An array of the widget's sidebar arguments. |
1063 | 1063 | */ |
1064 | - do_action( 'the_widget', $widget, $instance, $args ); |
|
1064 | + do_action('the_widget', $widget, $instance, $args); |
|
1065 | 1065 | |
1066 | 1066 | $widget_obj->_set(-1); |
1067 | 1067 | $widget_obj->widget($args, $instance); |
@@ -1075,8 +1075,8 @@ discard block |
||
1075 | 1075 | * @param string $id Widget ID. |
1076 | 1076 | * @return string Widget ID base. |
1077 | 1077 | */ |
1078 | -function _get_widget_id_base( $id ) { |
|
1079 | - return preg_replace( '/-[0-9]+$/', '', $id ); |
|
1078 | +function _get_widget_id_base($id) { |
|
1079 | + return preg_replace('/-[0-9]+$/', '', $id); |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | /** |
@@ -1090,7 +1090,7 @@ discard block |
||
1090 | 1090 | function _wp_sidebars_changed() { |
1091 | 1091 | global $sidebars_widgets; |
1092 | 1092 | |
1093 | - if ( ! is_array( $sidebars_widgets ) ) |
|
1093 | + if ( ! is_array($sidebars_widgets)) |
|
1094 | 1094 | $sidebars_widgets = wp_get_sidebars_widgets(); |
1095 | 1095 | |
1096 | 1096 | retrieve_widgets(true); |
@@ -1109,78 +1109,78 @@ discard block |
||
1109 | 1109 | * of 'customize' defers updates for the Customizer. |
1110 | 1110 | * @return array|void |
1111 | 1111 | */ |
1112 | -function retrieve_widgets( $theme_changed = false ) { |
|
1112 | +function retrieve_widgets($theme_changed = false) { |
|
1113 | 1113 | global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; |
1114 | 1114 | |
1115 | - $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); |
|
1115 | + $registered_sidebar_keys = array_keys($wp_registered_sidebars); |
|
1116 | 1116 | $orphaned = 0; |
1117 | 1117 | |
1118 | - $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); |
|
1119 | - if ( is_array( $old_sidebars_widgets ) ) { |
|
1118 | + $old_sidebars_widgets = get_theme_mod('sidebars_widgets'); |
|
1119 | + if (is_array($old_sidebars_widgets)) { |
|
1120 | 1120 | // time() that sidebars were stored is in $old_sidebars_widgets['time'] |
1121 | 1121 | $_sidebars_widgets = $old_sidebars_widgets['data']; |
1122 | 1122 | |
1123 | - if ( 'customize' !== $theme_changed ) { |
|
1124 | - remove_theme_mod( 'sidebars_widgets' ); |
|
1123 | + if ('customize' !== $theme_changed) { |
|
1124 | + remove_theme_mod('sidebars_widgets'); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | - foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
|
1128 | - if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) { |
|
1127 | + foreach ($_sidebars_widgets as $sidebar => $widgets) { |
|
1128 | + if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) { |
|
1129 | 1129 | continue; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | - if ( !in_array( $sidebar, $registered_sidebar_keys ) ) { |
|
1133 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets; |
|
1134 | - unset( $_sidebars_widgets[$sidebar] ); |
|
1132 | + if ( ! in_array($sidebar, $registered_sidebar_keys)) { |
|
1133 | + $_sidebars_widgets['orphaned_widgets_'.++$orphaned] = $widgets; |
|
1134 | + unset($_sidebars_widgets[$sidebar]); |
|
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } else { |
1138 | - if ( empty( $sidebars_widgets ) ) |
|
1138 | + if (empty($sidebars_widgets)) |
|
1139 | 1139 | return; |
1140 | 1140 | |
1141 | - unset( $sidebars_widgets['array_version'] ); |
|
1141 | + unset($sidebars_widgets['array_version']); |
|
1142 | 1142 | |
1143 | 1143 | $old = array_keys($sidebars_widgets); |
1144 | 1144 | sort($old); |
1145 | 1145 | sort($registered_sidebar_keys); |
1146 | 1146 | |
1147 | - if ( $old == $registered_sidebar_keys ) |
|
1147 | + if ($old == $registered_sidebar_keys) |
|
1148 | 1148 | return; |
1149 | 1149 | |
1150 | 1150 | $_sidebars_widgets = array( |
1151 | - 'wp_inactive_widgets' => !empty( $sidebars_widgets['wp_inactive_widgets'] ) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
|
1151 | + 'wp_inactive_widgets' => ! empty($sidebars_widgets['wp_inactive_widgets']) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
|
1152 | 1152 | ); |
1153 | 1153 | |
1154 | - unset( $sidebars_widgets['wp_inactive_widgets'] ); |
|
1154 | + unset($sidebars_widgets['wp_inactive_widgets']); |
|
1155 | 1155 | |
1156 | - foreach ( $wp_registered_sidebars as $id => $settings ) { |
|
1157 | - if ( $theme_changed ) { |
|
1158 | - $_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); |
|
1156 | + foreach ($wp_registered_sidebars as $id => $settings) { |
|
1157 | + if ($theme_changed) { |
|
1158 | + $_sidebars_widgets[$id] = array_shift($sidebars_widgets); |
|
1159 | 1159 | } else { |
1160 | 1160 | // no theme change, grab only sidebars that are currently registered |
1161 | - if ( isset( $sidebars_widgets[$id] ) ) { |
|
1161 | + if (isset($sidebars_widgets[$id])) { |
|
1162 | 1162 | $_sidebars_widgets[$id] = $sidebars_widgets[$id]; |
1163 | - unset( $sidebars_widgets[$id] ); |
|
1163 | + unset($sidebars_widgets[$id]); |
|
1164 | 1164 | } |
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - foreach ( $sidebars_widgets as $val ) { |
|
1169 | - if ( is_array($val) && ! empty( $val ) ) |
|
1170 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
1168 | + foreach ($sidebars_widgets as $val) { |
|
1169 | + if (is_array($val) && ! empty($val)) |
|
1170 | + $_sidebars_widgets['orphaned_widgets_'.++$orphaned] = $val; |
|
1171 | 1171 | } |
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | // discard invalid, theme-specific widgets from sidebars |
1175 | 1175 | $shown_widgets = array(); |
1176 | 1176 | |
1177 | - foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
|
1178 | - if ( !is_array($widgets) ) |
|
1177 | + foreach ($_sidebars_widgets as $sidebar => $widgets) { |
|
1178 | + if ( ! is_array($widgets)) |
|
1179 | 1179 | continue; |
1180 | 1180 | |
1181 | 1181 | $_widgets = array(); |
1182 | - foreach ( $widgets as $widget ) { |
|
1183 | - if ( isset($wp_registered_widgets[$widget]) ) |
|
1182 | + foreach ($widgets as $widget) { |
|
1183 | + if (isset($wp_registered_widgets[$widget])) |
|
1184 | 1184 | $_widgets[] = $widget; |
1185 | 1185 | } |
1186 | 1186 | |
@@ -1193,21 +1193,21 @@ discard block |
||
1193 | 1193 | |
1194 | 1194 | // find hidden/lost multi-widget instances |
1195 | 1195 | $lost_widgets = array(); |
1196 | - foreach ( $wp_registered_widgets as $key => $val ) { |
|
1197 | - if ( in_array($key, $shown_widgets, true) ) |
|
1196 | + foreach ($wp_registered_widgets as $key => $val) { |
|
1197 | + if (in_array($key, $shown_widgets, true)) |
|
1198 | 1198 | continue; |
1199 | 1199 | |
1200 | 1200 | $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key); |
1201 | 1201 | |
1202 | - if ( 2 > (int) $number ) |
|
1202 | + if (2 > (int) $number) |
|
1203 | 1203 | continue; |
1204 | 1204 | |
1205 | 1205 | $lost_widgets[] = $key; |
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); |
1209 | - if ( 'customize' !== $theme_changed ) { |
|
1210 | - wp_set_sidebars_widgets( $sidebars_widgets ); |
|
1209 | + if ('customize' !== $theme_changed) { |
|
1210 | + wp_set_sidebars_widgets($sidebars_widgets); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | return $sidebars_widgets; |
@@ -1221,88 +1221,88 @@ discard block |
||
1221 | 1221 | * @param string|array|object $rss RSS url. |
1222 | 1222 | * @param array $args Widget arguments. |
1223 | 1223 | */ |
1224 | -function wp_widget_rss_output( $rss, $args = array() ) { |
|
1225 | - if ( is_string( $rss ) ) { |
|
1224 | +function wp_widget_rss_output($rss, $args = array()) { |
|
1225 | + if (is_string($rss)) { |
|
1226 | 1226 | $rss = fetch_feed($rss); |
1227 | - } elseif ( is_array($rss) && isset($rss['url']) ) { |
|
1227 | + } elseif (is_array($rss) && isset($rss['url'])) { |
|
1228 | 1228 | $args = $rss; |
1229 | 1229 | $rss = fetch_feed($rss['url']); |
1230 | - } elseif ( !is_object($rss) ) { |
|
1230 | + } elseif ( ! is_object($rss)) { |
|
1231 | 1231 | return; |
1232 | 1232 | } |
1233 | 1233 | |
1234 | - if ( is_wp_error($rss) ) { |
|
1235 | - if ( is_admin() || current_user_can('manage_options') ) |
|
1236 | - echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; |
|
1234 | + if (is_wp_error($rss)) { |
|
1235 | + if (is_admin() || current_user_can('manage_options')) |
|
1236 | + echo '<p>'.sprintf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()).'</p>'; |
|
1237 | 1237 | return; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | - $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); |
|
1241 | - $args = wp_parse_args( $args, $default_args ); |
|
1240 | + $default_args = array('show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0); |
|
1241 | + $args = wp_parse_args($args, $default_args); |
|
1242 | 1242 | |
1243 | 1243 | $items = (int) $args['items']; |
1244 | - if ( $items < 1 || 20 < $items ) |
|
1244 | + if ($items < 1 || 20 < $items) |
|
1245 | 1245 | $items = 10; |
1246 | 1246 | $show_summary = (int) $args['show_summary']; |
1247 | 1247 | $show_author = (int) $args['show_author']; |
1248 | 1248 | $show_date = (int) $args['show_date']; |
1249 | 1249 | |
1250 | - if ( !$rss->get_item_quantity() ) { |
|
1251 | - echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; |
|
1250 | + if ( ! $rss->get_item_quantity()) { |
|
1251 | + echo '<ul><li>'.__('An error has occurred, which probably means the feed is down. Try again later.').'</li></ul>'; |
|
1252 | 1252 | $rss->__destruct(); |
1253 | 1253 | unset($rss); |
1254 | 1254 | return; |
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | echo '<ul>'; |
1258 | - foreach ( $rss->get_items( 0, $items ) as $item ) { |
|
1258 | + foreach ($rss->get_items(0, $items) as $item) { |
|
1259 | 1259 | $link = $item->get_link(); |
1260 | - while ( stristr( $link, 'http' ) != $link ) { |
|
1261 | - $link = substr( $link, 1 ); |
|
1260 | + while (stristr($link, 'http') != $link) { |
|
1261 | + $link = substr($link, 1); |
|
1262 | 1262 | } |
1263 | - $link = esc_url( strip_tags( $link ) ); |
|
1263 | + $link = esc_url(strip_tags($link)); |
|
1264 | 1264 | |
1265 | - $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); |
|
1266 | - if ( empty( $title ) ) { |
|
1267 | - $title = __( 'Untitled' ); |
|
1265 | + $title = esc_html(trim(strip_tags($item->get_title()))); |
|
1266 | + if (empty($title)) { |
|
1267 | + $title = __('Untitled'); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | - $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); |
|
1271 | - $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); |
|
1270 | + $desc = @html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset')); |
|
1271 | + $desc = esc_attr(wp_trim_words($desc, 55, ' […]')); |
|
1272 | 1272 | |
1273 | 1273 | $summary = ''; |
1274 | - if ( $show_summary ) { |
|
1274 | + if ($show_summary) { |
|
1275 | 1275 | $summary = $desc; |
1276 | 1276 | |
1277 | 1277 | // Change existing [...] to […]. |
1278 | - if ( '[...]' == substr( $summary, -5 ) ) { |
|
1279 | - $summary = substr( $summary, 0, -5 ) . '[…]'; |
|
1278 | + if ('[...]' == substr($summary, -5)) { |
|
1279 | + $summary = substr($summary, 0, -5).'[…]'; |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | - $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; |
|
1282 | + $summary = '<div class="rssSummary">'.esc_html($summary).'</div>'; |
|
1283 | 1283 | } |
1284 | 1284 | |
1285 | 1285 | $date = ''; |
1286 | - if ( $show_date ) { |
|
1287 | - $date = $item->get_date( 'U' ); |
|
1286 | + if ($show_date) { |
|
1287 | + $date = $item->get_date('U'); |
|
1288 | 1288 | |
1289 | - if ( $date ) { |
|
1290 | - $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; |
|
1289 | + if ($date) { |
|
1290 | + $date = ' <span class="rss-date">'.date_i18n(get_option('date_format'), $date).'</span>'; |
|
1291 | 1291 | } |
1292 | 1292 | } |
1293 | 1293 | |
1294 | 1294 | $author = ''; |
1295 | - if ( $show_author ) { |
|
1295 | + if ($show_author) { |
|
1296 | 1296 | $author = $item->get_author(); |
1297 | - if ( is_object($author) ) { |
|
1297 | + if (is_object($author)) { |
|
1298 | 1298 | $author = $author->get_name(); |
1299 | - $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; |
|
1299 | + $author = ' <cite>'.esc_html(strip_tags($author)).'</cite>'; |
|
1300 | 1300 | } |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - if ( $link == '' ) { |
|
1303 | + if ($link == '') { |
|
1304 | 1304 | echo "<li>$title{$date}{$summary}{$author}</li>"; |
1305 | - } elseif ( $show_summary ) { |
|
1305 | + } elseif ($show_summary) { |
|
1306 | 1306 | echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; |
1307 | 1307 | } else { |
1308 | 1308 | echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; |
@@ -1325,59 +1325,59 @@ discard block |
||
1325 | 1325 | * @param array|string $args Values for input fields. |
1326 | 1326 | * @param array $inputs Override default display options. |
1327 | 1327 | */ |
1328 | -function wp_widget_rss_form( $args, $inputs = null ) { |
|
1329 | - $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); |
|
1330 | - $inputs = wp_parse_args( $inputs, $default_inputs ); |
|
1328 | +function wp_widget_rss_form($args, $inputs = null) { |
|
1329 | + $default_inputs = array('url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true); |
|
1330 | + $inputs = wp_parse_args($inputs, $default_inputs); |
|
1331 | 1331 | |
1332 | - $args['title'] = isset( $args['title'] ) ? $args['title'] : ''; |
|
1333 | - $args['url'] = isset( $args['url'] ) ? $args['url'] : ''; |
|
1334 | - $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0; |
|
1332 | + $args['title'] = isset($args['title']) ? $args['title'] : ''; |
|
1333 | + $args['url'] = isset($args['url']) ? $args['url'] : ''; |
|
1334 | + $args['items'] = isset($args['items']) ? (int) $args['items'] : 0; |
|
1335 | 1335 | |
1336 | - if ( $args['items'] < 1 || 20 < $args['items'] ) { |
|
1336 | + if ($args['items'] < 1 || 20 < $args['items']) { |
|
1337 | 1337 | $args['items'] = 10; |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; |
|
1341 | - $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; |
|
1342 | - $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; |
|
1340 | + $args['show_summary'] = isset($args['show_summary']) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; |
|
1341 | + $args['show_author'] = isset($args['show_author']) ? (int) $args['show_author'] : (int) $inputs['show_author']; |
|
1342 | + $args['show_date'] = isset($args['show_date']) ? (int) $args['show_date'] : (int) $inputs['show_date']; |
|
1343 | 1343 | |
1344 | - if ( ! empty( $args['error'] ) ) { |
|
1345 | - echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>'; |
|
1344 | + if ( ! empty($args['error'])) { |
|
1345 | + echo '<p class="widget-error"><strong>'.sprintf(__('RSS Error: %s'), $args['error']).'</strong></p>'; |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | - $esc_number = esc_attr( $args['number'] ); |
|
1349 | - if ( $inputs['url'] ) : |
|
1348 | + $esc_number = esc_attr($args['number']); |
|
1349 | + if ($inputs['url']) : |
|
1350 | 1350 | ?> |
1351 | - <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label> |
|
1352 | - <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p> |
|
1353 | -<?php endif; if ( $inputs['title'] ) : ?> |
|
1354 | - <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label> |
|
1355 | - <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr( $args['title'] ); ?>" /></p> |
|
1356 | -<?php endif; if ( $inputs['items'] ) : ?> |
|
1357 | - <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e( 'How many items would you like to display?' ); ?></label> |
|
1351 | + <p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label> |
|
1352 | + <input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url($args['url']); ?>" /></p> |
|
1353 | +<?php endif; if ($inputs['title']) : ?> |
|
1354 | + <p><label for="rss-title-<?php echo $esc_number; ?>"><?php _e('Give the feed a title (optional):'); ?></label> |
|
1355 | + <input class="widefat" id="rss-title-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][title]" type="text" value="<?php echo esc_attr($args['title']); ?>" /></p> |
|
1356 | +<?php endif; if ($inputs['items']) : ?> |
|
1357 | + <p><label for="rss-items-<?php echo $esc_number; ?>"><?php _e('How many items would you like to display?'); ?></label> |
|
1358 | 1358 | <select id="rss-items-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][items]"> |
1359 | 1359 | <?php |
1360 | - for ( $i = 1; $i <= 20; ++$i ) { |
|
1361 | - echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>"; |
|
1360 | + for ($i = 1; $i <= 20; ++$i) { |
|
1361 | + echo "<option value='$i' ".selected($args['items'], $i, false).">$i</option>"; |
|
1362 | 1362 | } |
1363 | 1363 | ?> |
1364 | 1364 | </select></p> |
1365 | -<?php endif; if ( $inputs['show_summary'] ) : ?> |
|
1366 | - <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked( $args['show_summary'] ); ?> /> |
|
1367 | - <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e( 'Display item content?' ); ?></label></p> |
|
1368 | -<?php endif; if ( $inputs['show_author'] ) : ?> |
|
1369 | - <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked( $args['show_author'] ); ?> /> |
|
1370 | - <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e( 'Display item author if available?' ); ?></label></p> |
|
1371 | -<?php endif; if ( $inputs['show_date'] ) : ?> |
|
1372 | - <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/> |
|
1373 | - <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p> |
|
1365 | +<?php endif; if ($inputs['show_summary']) : ?> |
|
1366 | + <p><input id="rss-show-summary-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_summary]" type="checkbox" value="1" <?php checked($args['show_summary']); ?> /> |
|
1367 | + <label for="rss-show-summary-<?php echo $esc_number; ?>"><?php _e('Display item content?'); ?></label></p> |
|
1368 | +<?php endif; if ($inputs['show_author']) : ?> |
|
1369 | + <p><input id="rss-show-author-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_author]" type="checkbox" value="1" <?php checked($args['show_author']); ?> /> |
|
1370 | + <label for="rss-show-author-<?php echo $esc_number; ?>"><?php _e('Display item author if available?'); ?></label></p> |
|
1371 | +<?php endif; if ($inputs['show_date']) : ?> |
|
1372 | + <p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked($args['show_date']); ?>/> |
|
1373 | + <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e('Display item date?'); ?></label></p> |
|
1374 | 1374 | <?php |
1375 | 1375 | endif; |
1376 | - foreach ( array_keys($default_inputs) as $input ) : |
|
1377 | - if ( 'hidden' === $inputs[$input] ) : |
|
1378 | - $id = str_replace( '_', '-', $input ); |
|
1376 | + foreach (array_keys($default_inputs) as $input) : |
|
1377 | + if ('hidden' === $inputs[$input]) : |
|
1378 | + $id = str_replace('_', '-', $input); |
|
1379 | 1379 | ?> |
1380 | - <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" /> |
|
1380 | + <input type="hidden" id="rss-<?php echo esc_attr($id); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr($input); ?>]" value="<?php echo esc_attr($args[$input]); ?>" /> |
|
1381 | 1381 | <?php |
1382 | 1382 | endif; |
1383 | 1383 | endforeach; |
@@ -1399,25 +1399,25 @@ discard block |
||
1399 | 1399 | * @param bool $check_feed Optional, default is true. Whether to check feed for errors. |
1400 | 1400 | * @return array |
1401 | 1401 | */ |
1402 | -function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
|
1402 | +function wp_widget_rss_process($widget_rss, $check_feed = true) { |
|
1403 | 1403 | $items = (int) $widget_rss['items']; |
1404 | - if ( $items < 1 || 20 < $items ) |
|
1404 | + if ($items < 1 || 20 < $items) |
|
1405 | 1405 | $items = 10; |
1406 | - $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); |
|
1407 | - $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; |
|
1408 | - $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; |
|
1409 | - $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0; |
|
1410 | - $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; |
|
1406 | + $url = esc_url_raw(strip_tags($widget_rss['url'])); |
|
1407 | + $title = isset($widget_rss['title']) ? trim(strip_tags($widget_rss['title'])) : ''; |
|
1408 | + $show_summary = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0; |
|
1409 | + $show_author = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] : 0; |
|
1410 | + $show_date = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0; |
|
1411 | 1411 | |
1412 | - if ( $check_feed ) { |
|
1412 | + if ($check_feed) { |
|
1413 | 1413 | $rss = fetch_feed($url); |
1414 | 1414 | $error = false; |
1415 | 1415 | $link = ''; |
1416 | - if ( is_wp_error($rss) ) { |
|
1416 | + if (is_wp_error($rss)) { |
|
1417 | 1417 | $error = $rss->get_error_message(); |
1418 | 1418 | } else { |
1419 | 1419 | $link = esc_url(strip_tags($rss->get_permalink())); |
1420 | - while ( stristr($link, 'http') != $link ) |
|
1420 | + while (stristr($link, 'http') != $link) |
|
1421 | 1421 | $link = substr($link, 1); |
1422 | 1422 | |
1423 | 1423 | $rss->__destruct(); |
@@ -1425,7 +1425,7 @@ discard block |
||
1425 | 1425 | } |
1426 | 1426 | } |
1427 | 1427 | |
1428 | - return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); |
|
1428 | + return compact('title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date'); |
|
1429 | 1429 | } |
1430 | 1430 | |
1431 | 1431 | /** |
@@ -1437,7 +1437,7 @@ discard block |
||
1437 | 1437 | * @since 2.2.0 |
1438 | 1438 | */ |
1439 | 1439 | function wp_widgets_init() { |
1440 | - if ( !is_blog_installed() ) |
|
1440 | + if ( ! is_blog_installed()) |
|
1441 | 1441 | return; |
1442 | 1442 | |
1443 | 1443 | register_widget('WP_Widget_Pages'); |
@@ -1446,7 +1446,7 @@ discard block |
||
1446 | 1446 | |
1447 | 1447 | register_widget('WP_Widget_Archives'); |
1448 | 1448 | |
1449 | - if ( get_option( 'link_manager_enabled' ) ) |
|
1449 | + if (get_option('link_manager_enabled')) |
|
1450 | 1450 | register_widget('WP_Widget_Links'); |
1451 | 1451 | |
1452 | 1452 | register_widget('WP_Widget_Meta'); |
@@ -1472,5 +1472,5 @@ discard block |
||
1472 | 1472 | * |
1473 | 1473 | * @since 2.2.0 |
1474 | 1474 | */ |
1475 | - do_action( 'widgets_init' ); |
|
1475 | + do_action('widgets_init'); |
|
1476 | 1476 | } |
@@ -163,16 +163,18 @@ discard block |
||
163 | 163 | global $wp_registered_sidebars; |
164 | 164 | $number = (int) $number; |
165 | 165 | |
166 | - if ( is_string($args) ) |
|
167 | - parse_str($args, $args); |
|
166 | + if ( is_string($args) ) { |
|
167 | + parse_str($args, $args); |
|
168 | + } |
|
168 | 169 | |
169 | 170 | for ( $i = 1; $i <= $number; $i++ ) { |
170 | 171 | $_args = $args; |
171 | 172 | |
172 | - if ( $number > 1 ) |
|
173 | - $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
|
174 | - else |
|
175 | - $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
|
173 | + if ( $number > 1 ) { |
|
174 | + $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
|
175 | + } else { |
|
176 | + $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
|
177 | + } |
|
176 | 178 | |
177 | 179 | // Custom specified ID's are suffixed if they exist already. |
178 | 180 | // Automatically generated sidebar names need to be suffixed regardless starting at -0 |
@@ -388,14 +390,16 @@ discard block |
||
388 | 390 | * @return string|void Widget description, if available. |
389 | 391 | */ |
390 | 392 | function wp_widget_description( $id ) { |
391 | - if ( !is_scalar($id) ) |
|
392 | - return; |
|
393 | + if ( !is_scalar($id) ) { |
|
394 | + return; |
|
395 | + } |
|
393 | 396 | |
394 | 397 | global $wp_registered_widgets; |
395 | 398 | |
396 | - if ( isset($wp_registered_widgets[$id]['description']) ) |
|
397 | - return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
398 | -} |
|
399 | + if ( isset($wp_registered_widgets[$id]['description']) ) { |
|
400 | + return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
401 | + } |
|
402 | + } |
|
399 | 403 | |
400 | 404 | /** |
401 | 405 | * Retrieve description for a sidebar. |
@@ -411,14 +415,16 @@ discard block |
||
411 | 415 | * @return string|void Sidebar description, if available. |
412 | 416 | */ |
413 | 417 | function wp_sidebar_description( $id ) { |
414 | - if ( !is_scalar($id) ) |
|
415 | - return; |
|
418 | + if ( !is_scalar($id) ) { |
|
419 | + return; |
|
420 | + } |
|
416 | 421 | |
417 | 422 | global $wp_registered_sidebars; |
418 | 423 | |
419 | - if ( isset($wp_registered_sidebars[$id]['description']) ) |
|
420 | - return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
421 | -} |
|
424 | + if ( isset($wp_registered_sidebars[$id]['description']) ) { |
|
425 | + return esc_html( $wp_registered_sidebars[$id]['description'] ); |
|
426 | + } |
|
427 | + } |
|
422 | 428 | |
423 | 429 | /** |
424 | 430 | * Remove widget from sidebar. |
@@ -484,8 +490,9 @@ discard block |
||
484 | 490 | return; |
485 | 491 | } |
486 | 492 | |
487 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
488 | - return; |
|
493 | + if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) { |
|
494 | + return; |
|
495 | + } |
|
489 | 496 | |
490 | 497 | $defaults = array('width' => 250, 'height' => 200 ); // height is never used |
491 | 498 | $options = wp_parse_args($options, $defaults); |
@@ -502,11 +509,13 @@ discard block |
||
502 | 509 | |
503 | 510 | $wp_registered_widget_controls[$id] = $widget; |
504 | 511 | |
505 | - if ( isset($wp_registered_widget_updates[$id_base]) ) |
|
506 | - return; |
|
512 | + if ( isset($wp_registered_widget_updates[$id_base]) ) { |
|
513 | + return; |
|
514 | + } |
|
507 | 515 | |
508 | - if ( isset($widget['params'][0]['number']) ) |
|
509 | - $widget['params'][0]['number'] = -1; |
|
516 | + if ( isset($widget['params'][0]['number']) ) { |
|
517 | + $widget['params'][0]['number'] = -1; |
|
518 | + } |
|
510 | 519 | |
511 | 520 | unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); |
512 | 521 | $wp_registered_widget_updates[$id_base] = $widget; |
@@ -528,8 +537,9 @@ discard block |
||
528 | 537 | global $wp_registered_widget_updates; |
529 | 538 | |
530 | 539 | if ( isset($wp_registered_widget_updates[$id_base]) ) { |
531 | - if ( empty($update_callback) ) |
|
532 | - unset($wp_registered_widget_updates[$id_base]); |
|
540 | + if ( empty($update_callback) ) { |
|
541 | + unset($wp_registered_widget_updates[$id_base]); |
|
542 | + } |
|
533 | 543 | return; |
534 | 544 | } |
535 | 545 | |
@@ -565,8 +575,9 @@ discard block |
||
565 | 575 | return; |
566 | 576 | } |
567 | 577 | |
568 | - if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
569 | - return; |
|
578 | + if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) { |
|
579 | + return; |
|
580 | + } |
|
570 | 581 | |
571 | 582 | $defaults = array('width' => 250, 'height' => 200 ); |
572 | 583 | $options = wp_parse_args($options, $defaults); |
@@ -653,7 +664,9 @@ discard block |
||
653 | 664 | $did_one = false; |
654 | 665 | foreach ( (array) $sidebars_widgets[$index] as $id ) { |
655 | 666 | |
656 | - if ( !isset($wp_registered_widgets[$id]) ) continue; |
|
667 | + if ( !isset($wp_registered_widgets[$id]) ) { |
|
668 | + continue; |
|
669 | + } |
|
657 | 670 | |
658 | 671 | $params = array_merge( |
659 | 672 | array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
@@ -663,10 +676,11 @@ discard block |
||
663 | 676 | // Substitute HTML id and class attributes into before_widget |
664 | 677 | $classname_ = ''; |
665 | 678 | foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
666 | - if ( is_string($cn) ) |
|
667 | - $classname_ .= '_' . $cn; |
|
668 | - elseif ( is_object($cn) ) |
|
669 | - $classname_ .= '_' . get_class($cn); |
|
679 | + if ( is_string($cn) ) { |
|
680 | + $classname_ .= '_' . $cn; |
|
681 | + } elseif ( is_object($cn) ) { |
|
682 | + $classname_ .= '_' . get_class($cn); |
|
683 | + } |
|
670 | 684 | } |
671 | 685 | $classname_ = ltrim($classname_, '_'); |
672 | 686 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
@@ -806,8 +820,9 @@ discard block |
||
806 | 820 | if ( is_array($widgets) ) { |
807 | 821 | foreach ( $widgets as $widget ) { |
808 | 822 | if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) { |
809 | - if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) |
|
810 | - return $sidebar; |
|
823 | + if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) { |
|
824 | + return $sidebar; |
|
825 | + } |
|
811 | 826 | } |
812 | 827 | } |
813 | 828 | } |
@@ -831,9 +846,10 @@ discard block |
||
831 | 846 | $sidebars_widgets = get_option('sidebars_widgets'); |
832 | 847 | foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
833 | 848 | if ( ! empty( $sidebars_widgets[ $index ] ) ) { |
834 | - foreach ( (array) $sidebars_widgets[$index] as $widget ) |
|
835 | - if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
849 | + foreach ( (array) $sidebars_widgets[$index] as $widget ) { |
|
850 | + if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
836 | 851 | return true; |
852 | + } |
|
837 | 853 | } |
838 | 854 | } |
839 | 855 | return false; |
@@ -884,24 +900,27 @@ discard block |
||
884 | 900 | * @return array Upgraded list of widgets to version 3 array format when called from the admin. |
885 | 901 | */ |
886 | 902 | function wp_get_sidebars_widgets( $deprecated = true ) { |
887 | - if ( $deprecated !== true ) |
|
888 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
903 | + if ( $deprecated !== true ) { |
|
904 | + _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
905 | + } |
|
889 | 906 | |
890 | 907 | global $_wp_sidebars_widgets, $sidebars_widgets; |
891 | 908 | |
892 | 909 | // If loading from front page, consult $_wp_sidebars_widgets rather than options |
893 | 910 | // to see if wp_convert_widget_settings() has made manipulations in memory. |
894 | 911 | if ( !is_admin() ) { |
895 | - if ( empty($_wp_sidebars_widgets) ) |
|
896 | - $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
|
912 | + if ( empty($_wp_sidebars_widgets) ) { |
|
913 | + $_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
|
914 | + } |
|
897 | 915 | |
898 | 916 | $sidebars_widgets = $_wp_sidebars_widgets; |
899 | 917 | } else { |
900 | 918 | $sidebars_widgets = get_option('sidebars_widgets', array()); |
901 | 919 | } |
902 | 920 | |
903 | - if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) |
|
904 | - unset($sidebars_widgets['array_version']); |
|
921 | + if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) { |
|
922 | + unset($sidebars_widgets['array_version']); |
|
923 | + } |
|
905 | 924 | |
906 | 925 | /** |
907 | 926 | * Filter the list of sidebars and their widgets. |
@@ -922,8 +941,9 @@ discard block |
||
922 | 941 | * @param array $sidebars_widgets Sidebar widgets and their settings. |
923 | 942 | */ |
924 | 943 | function wp_set_sidebars_widgets( $sidebars_widgets ) { |
925 | - if ( !isset( $sidebars_widgets['array_version'] ) ) |
|
926 | - $sidebars_widgets['array_version'] = 3; |
|
944 | + if ( !isset( $sidebars_widgets['array_version'] ) ) { |
|
945 | + $sidebars_widgets['array_version'] = 3; |
|
946 | + } |
|
927 | 947 | update_option( 'sidebars_widgets', $sidebars_widgets ); |
928 | 948 | } |
929 | 949 | |
@@ -942,8 +962,9 @@ discard block |
||
942 | 962 | |
943 | 963 | $defaults = array(); |
944 | 964 | |
945 | - foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) |
|
946 | - $defaults[$index] = array(); |
|
965 | + foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) { |
|
966 | + $defaults[$index] = array(); |
|
967 | + } |
|
947 | 968 | |
948 | 969 | return $defaults; |
949 | 970 | } |
@@ -967,8 +988,9 @@ discard block |
||
967 | 988 | $single = true; |
968 | 989 | } else { |
969 | 990 | foreach ( array_keys($settings) as $number ) { |
970 | - if ( 'number' == $number ) |
|
971 | - continue; |
|
991 | + if ( 'number' == $number ) { |
|
992 | + continue; |
|
993 | + } |
|
972 | 994 | if ( !is_numeric($number) ) { |
973 | 995 | $single = true; |
974 | 996 | break; |
@@ -983,8 +1005,9 @@ discard block |
||
983 | 1005 | if ( is_admin() ) { |
984 | 1006 | $sidebars_widgets = get_option('sidebars_widgets'); |
985 | 1007 | } else { |
986 | - if ( empty($GLOBALS['_wp_sidebars_widgets']) ) |
|
987 | - $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
|
1008 | + if ( empty($GLOBALS['_wp_sidebars_widgets']) ) { |
|
1009 | + $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
|
1010 | + } |
|
988 | 1011 | $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; |
989 | 1012 | } |
990 | 1013 | |
@@ -1000,13 +1023,15 @@ discard block |
||
1000 | 1023 | } |
1001 | 1024 | } |
1002 | 1025 | |
1003 | - if ( is_admin() && $changed ) |
|
1004 | - update_option('sidebars_widgets', $sidebars_widgets); |
|
1026 | + if ( is_admin() && $changed ) { |
|
1027 | + update_option('sidebars_widgets', $sidebars_widgets); |
|
1028 | + } |
|
1005 | 1029 | } |
1006 | 1030 | |
1007 | 1031 | $settings['_multiwidget'] = 1; |
1008 | - if ( is_admin() ) |
|
1009 | - update_option( $option_name, $settings ); |
|
1032 | + if ( is_admin() ) { |
|
1033 | + update_option( $option_name, $settings ); |
|
1034 | + } |
|
1010 | 1035 | |
1011 | 1036 | return $settings; |
1012 | 1037 | } |
@@ -1090,8 +1115,9 @@ discard block |
||
1090 | 1115 | function _wp_sidebars_changed() { |
1091 | 1116 | global $sidebars_widgets; |
1092 | 1117 | |
1093 | - if ( ! is_array( $sidebars_widgets ) ) |
|
1094 | - $sidebars_widgets = wp_get_sidebars_widgets(); |
|
1118 | + if ( ! is_array( $sidebars_widgets ) ) { |
|
1119 | + $sidebars_widgets = wp_get_sidebars_widgets(); |
|
1120 | + } |
|
1095 | 1121 | |
1096 | 1122 | retrieve_widgets(true); |
1097 | 1123 | } |
@@ -1135,8 +1161,9 @@ discard block |
||
1135 | 1161 | } |
1136 | 1162 | } |
1137 | 1163 | } else { |
1138 | - if ( empty( $sidebars_widgets ) ) |
|
1139 | - return; |
|
1164 | + if ( empty( $sidebars_widgets ) ) { |
|
1165 | + return; |
|
1166 | + } |
|
1140 | 1167 | |
1141 | 1168 | unset( $sidebars_widgets['array_version'] ); |
1142 | 1169 | |
@@ -1144,8 +1171,9 @@ discard block |
||
1144 | 1171 | sort($old); |
1145 | 1172 | sort($registered_sidebar_keys); |
1146 | 1173 | |
1147 | - if ( $old == $registered_sidebar_keys ) |
|
1148 | - return; |
|
1174 | + if ( $old == $registered_sidebar_keys ) { |
|
1175 | + return; |
|
1176 | + } |
|
1149 | 1177 | |
1150 | 1178 | $_sidebars_widgets = array( |
1151 | 1179 | 'wp_inactive_widgets' => !empty( $sidebars_widgets['wp_inactive_widgets'] ) ? $sidebars_widgets['wp_inactive_widgets'] : array() |
@@ -1166,8 +1194,9 @@ discard block |
||
1166 | 1194 | } |
1167 | 1195 | |
1168 | 1196 | foreach ( $sidebars_widgets as $val ) { |
1169 | - if ( is_array($val) && ! empty( $val ) ) |
|
1170 | - $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
1197 | + if ( is_array($val) && ! empty( $val ) ) { |
|
1198 | + $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val; |
|
1199 | + } |
|
1171 | 1200 | } |
1172 | 1201 | } |
1173 | 1202 | |
@@ -1175,13 +1204,15 @@ discard block |
||
1175 | 1204 | $shown_widgets = array(); |
1176 | 1205 | |
1177 | 1206 | foreach ( $_sidebars_widgets as $sidebar => $widgets ) { |
1178 | - if ( !is_array($widgets) ) |
|
1179 | - continue; |
|
1207 | + if ( !is_array($widgets) ) { |
|
1208 | + continue; |
|
1209 | + } |
|
1180 | 1210 | |
1181 | 1211 | $_widgets = array(); |
1182 | 1212 | foreach ( $widgets as $widget ) { |
1183 | - if ( isset($wp_registered_widgets[$widget]) ) |
|
1184 | - $_widgets[] = $widget; |
|
1213 | + if ( isset($wp_registered_widgets[$widget]) ) { |
|
1214 | + $_widgets[] = $widget; |
|
1215 | + } |
|
1185 | 1216 | } |
1186 | 1217 | |
1187 | 1218 | $_sidebars_widgets[$sidebar] = $_widgets; |
@@ -1194,13 +1225,15 @@ discard block |
||
1194 | 1225 | // find hidden/lost multi-widget instances |
1195 | 1226 | $lost_widgets = array(); |
1196 | 1227 | foreach ( $wp_registered_widgets as $key => $val ) { |
1197 | - if ( in_array($key, $shown_widgets, true) ) |
|
1198 | - continue; |
|
1228 | + if ( in_array($key, $shown_widgets, true) ) { |
|
1229 | + continue; |
|
1230 | + } |
|
1199 | 1231 | |
1200 | 1232 | $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key); |
1201 | 1233 | |
1202 | - if ( 2 > (int) $number ) |
|
1203 | - continue; |
|
1234 | + if ( 2 > (int) $number ) { |
|
1235 | + continue; |
|
1236 | + } |
|
1204 | 1237 | |
1205 | 1238 | $lost_widgets[] = $key; |
1206 | 1239 | } |
@@ -1232,8 +1265,9 @@ discard block |
||
1232 | 1265 | } |
1233 | 1266 | |
1234 | 1267 | if ( is_wp_error($rss) ) { |
1235 | - if ( is_admin() || current_user_can('manage_options') ) |
|
1236 | - echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; |
|
1268 | + if ( is_admin() || current_user_can('manage_options') ) { |
|
1269 | + echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; |
|
1270 | + } |
|
1237 | 1271 | return; |
1238 | 1272 | } |
1239 | 1273 | |
@@ -1241,8 +1275,9 @@ discard block |
||
1241 | 1275 | $args = wp_parse_args( $args, $default_args ); |
1242 | 1276 | |
1243 | 1277 | $items = (int) $args['items']; |
1244 | - if ( $items < 1 || 20 < $items ) |
|
1245 | - $items = 10; |
|
1278 | + if ( $items < 1 || 20 < $items ) { |
|
1279 | + $items = 10; |
|
1280 | + } |
|
1246 | 1281 | $show_summary = (int) $args['show_summary']; |
1247 | 1282 | $show_author = (int) $args['show_author']; |
1248 | 1283 | $show_date = (int) $args['show_date']; |
@@ -1401,8 +1436,9 @@ discard block |
||
1401 | 1436 | */ |
1402 | 1437 | function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
1403 | 1438 | $items = (int) $widget_rss['items']; |
1404 | - if ( $items < 1 || 20 < $items ) |
|
1405 | - $items = 10; |
|
1439 | + if ( $items < 1 || 20 < $items ) { |
|
1440 | + $items = 10; |
|
1441 | + } |
|
1406 | 1442 | $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); |
1407 | 1443 | $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; |
1408 | 1444 | $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; |
@@ -1417,8 +1453,9 @@ discard block |
||
1417 | 1453 | $error = $rss->get_error_message(); |
1418 | 1454 | } else { |
1419 | 1455 | $link = esc_url(strip_tags($rss->get_permalink())); |
1420 | - while ( stristr($link, 'http') != $link ) |
|
1421 | - $link = substr($link, 1); |
|
1456 | + while ( stristr($link, 'http') != $link ) { |
|
1457 | + $link = substr($link, 1); |
|
1458 | + } |
|
1422 | 1459 | |
1423 | 1460 | $rss->__destruct(); |
1424 | 1461 | unset($rss); |
@@ -1437,8 +1474,9 @@ discard block |
||
1437 | 1474 | * @since 2.2.0 |
1438 | 1475 | */ |
1439 | 1476 | function wp_widgets_init() { |
1440 | - if ( !is_blog_installed() ) |
|
1441 | - return; |
|
1477 | + if ( !is_blog_installed() ) { |
|
1478 | + return; |
|
1479 | + } |
|
1442 | 1480 | |
1443 | 1481 | register_widget('WP_Widget_Pages'); |
1444 | 1482 | |
@@ -1446,8 +1484,9 @@ discard block |
||
1446 | 1484 | |
1447 | 1485 | register_widget('WP_Widget_Archives'); |
1448 | 1486 | |
1449 | - if ( get_option( 'link_manager_enabled' ) ) |
|
1450 | - register_widget('WP_Widget_Links'); |
|
1487 | + if ( get_option( 'link_manager_enabled' ) ) { |
|
1488 | + register_widget('WP_Widget_Links'); |
|
1489 | + } |
|
1451 | 1490 | |
1452 | 1491 | register_widget('WP_Widget_Meta'); |
1453 | 1492 |
@@ -156,6 +156,9 @@ discard block |
||
156 | 156 | unlink( $temp_file ); |
157 | 157 | } |
158 | 158 | |
159 | + /** |
|
160 | + * @param string $file |
|
161 | + */ |
|
159 | 162 | private function tempnam( $file ) { |
160 | 163 | $tempnam = tempnam( sys_get_temp_dir(), $file ); |
161 | 164 | $this->temp_files[] = $tempnam; |
@@ -235,6 +238,9 @@ discard block |
||
235 | 238 | return $res; |
236 | 239 | } |
237 | 240 | |
241 | + /** |
|
242 | + * @param string $output |
|
243 | + */ |
|
238 | 244 | public function wp_frontend( $dir, $output ) { |
239 | 245 | if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
240 | 246 | return false; |
@@ -255,6 +261,9 @@ discard block |
||
255 | 261 | ) ); |
256 | 262 | } |
257 | 263 | |
264 | + /** |
|
265 | + * @param string $output |
|
266 | + */ |
|
258 | 267 | public function wp_admin($dir, $output) { |
259 | 268 | $frontend_pot = $this->tempnam( 'frontend.pot' ); |
260 | 269 | if ( false === $frontend_pot ) { |
@@ -416,6 +425,7 @@ discard block |
||
416 | 425 | |
417 | 426 | /** |
418 | 427 | * Removes any trailing closing comment / PHP tags from the header value |
428 | + * @param string $str |
|
419 | 429 | */ |
420 | 430 | private function _cleanup_header_comment( $str ) { |
421 | 431 | return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) ); |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once dirname( __FILE__ ) . '/not-gettexted.php'; |
|
3 | -require_once dirname( __FILE__ ) . '/pot-ext-meta.php'; |
|
4 | -require_once dirname( __FILE__ ) . '/extract.php'; |
|
2 | +require_once dirname(__FILE__).'/not-gettexted.php'; |
|
3 | +require_once dirname(__FILE__).'/pot-ext-meta.php'; |
|
4 | +require_once dirname(__FILE__).'/extract.php'; |
|
5 | 5 | |
6 | -if ( !defined( 'STDERR' ) ) { |
|
7 | - define( 'STDERR', fopen( 'php://stderr', 'w' ) ); |
|
6 | +if ( ! defined('STDERR')) { |
|
7 | + define('STDERR', fopen('php://stderr', 'w')); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | ); |
149 | 149 | |
150 | 150 | public function __construct($deprecated = true) { |
151 | - $this->extractor = new StringExtractor( $this->rules ); |
|
151 | + $this->extractor = new StringExtractor($this->rules); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function __destruct() { |
155 | - foreach ( $this->temp_files as $temp_file ) |
|
156 | - unlink( $temp_file ); |
|
155 | + foreach ($this->temp_files as $temp_file) |
|
156 | + unlink($temp_file); |
|
157 | 157 | } |
158 | 158 | |
159 | - private function tempnam( $file ) { |
|
160 | - $tempnam = tempnam( sys_get_temp_dir(), $file ); |
|
159 | + private function tempnam($file) { |
|
160 | + $tempnam = tempnam(sys_get_temp_dir(), $file); |
|
161 | 161 | $this->temp_files[] = $tempnam; |
162 | 162 | return $tempnam; |
163 | 163 | } |
@@ -167,31 +167,31 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | private function xgettext($project, $dir, $output_file, $placeholders = array(), $excludes = array(), $includes = array()) { |
170 | - $meta = array_merge( $this->meta['default'], $this->meta[$project] ); |
|
171 | - $placeholders = array_merge( $meta, $placeholders ); |
|
172 | - $meta['output'] = $this->realpath_missing( $output_file ); |
|
173 | - $placeholders['year'] = date( 'Y' ); |
|
174 | - $placeholder_keys = array_map( create_function( '$x', 'return "{".$x."}";' ), array_keys( $placeholders ) ); |
|
175 | - $placeholder_values = array_values( $placeholders ); |
|
176 | - foreach($meta as $key => $value) { |
|
170 | + $meta = array_merge($this->meta['default'], $this->meta[$project]); |
|
171 | + $placeholders = array_merge($meta, $placeholders); |
|
172 | + $meta['output'] = $this->realpath_missing($output_file); |
|
173 | + $placeholders['year'] = date('Y'); |
|
174 | + $placeholder_keys = array_map(create_function('$x', 'return "{".$x."}";'), array_keys($placeholders)); |
|
175 | + $placeholder_values = array_values($placeholders); |
|
176 | + foreach ($meta as $key => $value) { |
|
177 | 177 | $meta[$key] = str_replace($placeholder_keys, $placeholder_values, $value); |
178 | 178 | } |
179 | 179 | |
180 | - $originals = $this->extractor->extract_from_directory( $dir, $excludes, $includes ); |
|
180 | + $originals = $this->extractor->extract_from_directory($dir, $excludes, $includes); |
|
181 | 181 | $pot = new PO; |
182 | 182 | $pot->entries = $originals->entries; |
183 | 183 | |
184 | - $pot->set_header( 'Project-Id-Version', $meta['package-name'].' '.$meta['package-version'] ); |
|
185 | - $pot->set_header( 'Report-Msgid-Bugs-To', $meta['msgid-bugs-address'] ); |
|
186 | - $pot->set_header( 'POT-Creation-Date', gmdate( 'Y-m-d H:i:s+00:00' ) ); |
|
187 | - $pot->set_header( 'MIME-Version', '1.0' ); |
|
188 | - $pot->set_header( 'Content-Type', 'text/plain; charset=UTF-8' ); |
|
189 | - $pot->set_header( 'Content-Transfer-Encoding', '8bit' ); |
|
190 | - $pot->set_header( 'PO-Revision-Date', date( 'Y') . '-MO-DA HO:MI+ZONE' ); |
|
191 | - $pot->set_header( 'Last-Translator', 'FULL NAME <EMAIL@ADDRESS>' ); |
|
192 | - $pot->set_header( 'Language-Team', 'LANGUAGE <[email protected]>' ); |
|
193 | - $pot->set_comment_before_headers( $meta['comments'] ); |
|
194 | - $pot->export_to_file( $output_file ); |
|
184 | + $pot->set_header('Project-Id-Version', $meta['package-name'].' '.$meta['package-version']); |
|
185 | + $pot->set_header('Report-Msgid-Bugs-To', $meta['msgid-bugs-address']); |
|
186 | + $pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00')); |
|
187 | + $pot->set_header('MIME-Version', '1.0'); |
|
188 | + $pot->set_header('Content-Type', 'text/plain; charset=UTF-8'); |
|
189 | + $pot->set_header('Content-Transfer-Encoding', '8bit'); |
|
190 | + $pot->set_header('PO-Revision-Date', date('Y').'-MO-DA HO:MI+ZONE'); |
|
191 | + $pot->set_header('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>'); |
|
192 | + $pot->set_header('Language-Team', 'LANGUAGE <[email protected]>'); |
|
193 | + $pot->set_comment_before_headers($meta['comments']); |
|
194 | + $pot->export_to_file($output_file); |
|
195 | 195 | return true; |
196 | 196 | } |
197 | 197 | |
@@ -202,185 +202,185 @@ discard block |
||
202 | 202 | 'default_output' => 'wordpress.pot', |
203 | 203 | 'includes' => array(), |
204 | 204 | 'excludes' => array_merge( |
205 | - array( 'wp-admin/includes/continents-cities\.php', 'wp-content/themes/twenty.*', ), |
|
205 | + array('wp-admin/includes/continents-cities\.php', 'wp-content/themes/twenty.*',), |
|
206 | 206 | $this->ms_files |
207 | 207 | ), |
208 | 208 | 'extract_not_gettexted' => false, |
209 | 209 | 'not_gettexted_files_filter' => false, |
210 | 210 | ); |
211 | - $args = array_merge( $defaults, $args ); |
|
212 | - extract( $args ); |
|
211 | + $args = array_merge($defaults, $args); |
|
212 | + extract($args); |
|
213 | 213 | $placeholders = array(); |
214 | - if ( $wp_version = $this->wp_version( $dir ) ) |
|
214 | + if ($wp_version = $this->wp_version($dir)) |
|
215 | 215 | $placeholders['version'] = $wp_version; |
216 | 216 | else |
217 | 217 | return false; |
218 | - $output = is_null( $output )? $default_output : $output; |
|
219 | - $res = $this->xgettext( $project, $dir, $output, $placeholders, $excludes, $includes ); |
|
220 | - if ( !$res ) return false; |
|
218 | + $output = is_null($output) ? $default_output : $output; |
|
219 | + $res = $this->xgettext($project, $dir, $output, $placeholders, $excludes, $includes); |
|
220 | + if ( ! $res) return false; |
|
221 | 221 | |
222 | - if ( $extract_not_gettexted ) { |
|
222 | + if ($extract_not_gettexted) { |
|
223 | 223 | $old_dir = getcwd(); |
224 | - $output = realpath( $output ); |
|
225 | - chdir( $dir ); |
|
224 | + $output = realpath($output); |
|
225 | + chdir($dir); |
|
226 | 226 | $php_files = NotGettexted::list_php_files('.'); |
227 | - $php_files = array_filter( $php_files, $not_gettexted_files_filter ); |
|
227 | + $php_files = array_filter($php_files, $not_gettexted_files_filter); |
|
228 | 228 | $not_gettexted = new NotGettexted; |
229 | - $res = $not_gettexted->command_extract( $output, $php_files ); |
|
230 | - chdir( $old_dir ); |
|
229 | + $res = $not_gettexted->command_extract($output, $php_files); |
|
230 | + chdir($old_dir); |
|
231 | 231 | /* Adding non-gettexted strings can repeat some phrases */ |
232 | - $output_shell = escapeshellarg( $output ); |
|
233 | - system( "msguniq --use-first $output_shell -o $output_shell" ); |
|
232 | + $output_shell = escapeshellarg($output); |
|
233 | + system("msguniq --use-first $output_shell -o $output_shell"); |
|
234 | 234 | } |
235 | 235 | return $res; |
236 | 236 | } |
237 | 237 | |
238 | - public function wp_frontend( $dir, $output ) { |
|
239 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
238 | + public function wp_frontend($dir, $output) { |
|
239 | + if ( ! file_exists("$dir/wp-admin/user/about.php")) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
243 | - $excludes = array( 'wp-admin/.*', 'wp-content/themes/.*', 'wp-includes/class-pop3\.php' ); |
|
243 | + $excludes = array('wp-admin/.*', 'wp-content/themes/.*', 'wp-includes/class-pop3\.php'); |
|
244 | 244 | |
245 | 245 | // Exclude Akismet all together for 3.9+. |
246 | - if ( file_exists( "$dir/wp-admin/css/about.css" ) ) { |
|
246 | + if (file_exists("$dir/wp-admin/css/about.css")) { |
|
247 | 247 | $excludes[] = 'wp-content/plugins/akismet/.*'; |
248 | 248 | } |
249 | 249 | |
250 | - return $this->wp_generic( $dir, array( |
|
250 | + return $this->wp_generic($dir, array( |
|
251 | 251 | 'project' => 'wp-frontend', 'output' => $output, |
252 | 252 | 'includes' => array(), |
253 | 253 | 'excludes' => $excludes, |
254 | 254 | 'default_output' => 'wordpress.pot', |
255 | - ) ); |
|
255 | + )); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public function wp_admin($dir, $output) { |
259 | - $frontend_pot = $this->tempnam( 'frontend.pot' ); |
|
260 | - if ( false === $frontend_pot ) { |
|
259 | + $frontend_pot = $this->tempnam('frontend.pot'); |
|
260 | + if (false === $frontend_pot) { |
|
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | |
264 | - $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
|
265 | - if ( ! $frontend_result ) { |
|
264 | + $frontend_result = $this->wp_frontend($dir, $frontend_pot); |
|
265 | + if ( ! $frontend_result) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - $network_admin_files = $this->get_wp_network_admin_files( $dir ); |
|
269 | + $network_admin_files = $this->get_wp_network_admin_files($dir); |
|
270 | 270 | |
271 | - $result = $this->wp_generic( $dir, array( |
|
271 | + $result = $this->wp_generic($dir, array( |
|
272 | 272 | 'project' => 'wp-admin', 'output' => $output, |
273 | - 'includes' => array( 'wp-admin/.*' ), |
|
274 | - 'excludes' => array_merge( array( 'wp-admin/includes/continents-cities\.php' ), $network_admin_files ), |
|
273 | + 'includes' => array('wp-admin/.*'), |
|
274 | + 'excludes' => array_merge(array('wp-admin/includes/continents-cities\.php'), $network_admin_files), |
|
275 | 275 | 'default_output' => 'wordpress-admin.pot', |
276 | - ) ); |
|
277 | - if ( ! $result ) { |
|
276 | + )); |
|
277 | + if ( ! $result) { |
|
278 | 278 | return false; |
279 | 279 | } |
280 | 280 | |
281 | 281 | $potextmeta = new PotExtMeta; |
282 | 282 | |
283 | - if ( ! file_exists( "$dir/wp-admin/css/about.css" ) ) { // < 3.9 |
|
284 | - $result = $potextmeta->append( "$dir/wp-content/plugins/akismet/akismet.php", $output ); |
|
285 | - if ( ! $result ) { |
|
283 | + if ( ! file_exists("$dir/wp-admin/css/about.css")) { // < 3.9 |
|
284 | + $result = $potextmeta->append("$dir/wp-content/plugins/akismet/akismet.php", $output); |
|
285 | + if ( ! $result) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | - $result = $potextmeta->append( "$dir/wp-content/plugins/hello.php", $output ); |
|
291 | - if ( ! $result ) { |
|
290 | + $result = $potextmeta->append("$dir/wp-content/plugins/hello.php", $output); |
|
291 | + if ( ! $result) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
295 | 295 | /* Adding non-gettexted strings can repeat some phrases */ |
296 | - $output_shell = escapeshellarg( $output ); |
|
297 | - system( "msguniq $output_shell -o $output_shell" ); |
|
296 | + $output_shell = escapeshellarg($output); |
|
297 | + system("msguniq $output_shell -o $output_shell"); |
|
298 | 298 | |
299 | - $common_pot = $this->tempnam( 'common.pot' ); |
|
300 | - if ( ! $common_pot ) { |
|
299 | + $common_pot = $this->tempnam('common.pot'); |
|
300 | + if ( ! $common_pot) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | - $admin_pot = realpath( is_null( $output ) ? 'wordpress-admin.pot' : $output ); |
|
304 | - system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot > $common_pot" ); |
|
305 | - system( "msgcat -u --use-first $admin_pot $common_pot -o $admin_pot" ); |
|
303 | + $admin_pot = realpath(is_null($output) ? 'wordpress-admin.pot' : $output); |
|
304 | + system("msgcat --more-than=1 --use-first $frontend_pot $admin_pot > $common_pot"); |
|
305 | + system("msgcat -u --use-first $admin_pot $common_pot -o $admin_pot"); |
|
306 | 306 | return true; |
307 | 307 | } |
308 | 308 | |
309 | 309 | public function wp_network_admin($dir, $output) { |
310 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
310 | + if ( ! file_exists("$dir/wp-admin/user/about.php")) return false; |
|
311 | 311 | |
312 | - $frontend_pot = $this->tempnam( 'frontend.pot' ); |
|
313 | - if ( false === $frontend_pot ) return false; |
|
312 | + $frontend_pot = $this->tempnam('frontend.pot'); |
|
313 | + if (false === $frontend_pot) return false; |
|
314 | 314 | |
315 | - $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
|
316 | - if ( ! $frontend_result ) |
|
315 | + $frontend_result = $this->wp_frontend($dir, $frontend_pot); |
|
316 | + if ( ! $frontend_result) |
|
317 | 317 | return false; |
318 | 318 | |
319 | - $admin_pot = $this->tempnam( 'admin.pot' ); |
|
320 | - if ( false === $admin_pot ) return false; |
|
319 | + $admin_pot = $this->tempnam('admin.pot'); |
|
320 | + if (false === $admin_pot) return false; |
|
321 | 321 | |
322 | - $admin_result = $this->wp_admin( $dir, $admin_pot ); |
|
323 | - if ( ! $admin_result ) |
|
322 | + $admin_result = $this->wp_admin($dir, $admin_pot); |
|
323 | + if ( ! $admin_result) |
|
324 | 324 | return false; |
325 | 325 | |
326 | - $result = $this->wp_generic( $dir, array( |
|
326 | + $result = $this->wp_generic($dir, array( |
|
327 | 327 | 'project' => 'wp-network-admin', 'output' => $output, |
328 | - 'includes' => $this->get_wp_network_admin_files( $dir ), |
|
328 | + 'includes' => $this->get_wp_network_admin_files($dir), |
|
329 | 329 | 'excludes' => array(), |
330 | 330 | 'default_output' => 'wordpress-admin-network.pot', |
331 | - ) ); |
|
331 | + )); |
|
332 | 332 | |
333 | - if ( ! $result ) { |
|
333 | + if ( ! $result) { |
|
334 | 334 | return false; |
335 | 335 | } |
336 | 336 | |
337 | - $common_pot = $this->tempnam( 'common.pot' ); |
|
338 | - if ( ! $common_pot ) |
|
337 | + $common_pot = $this->tempnam('common.pot'); |
|
338 | + if ( ! $common_pot) |
|
339 | 339 | return false; |
340 | 340 | |
341 | - $net_admin_pot = realpath( is_null( $output ) ? 'wordpress-network-admin.pot' : $output ); |
|
342 | - system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot" ); |
|
343 | - system( "msgcat -u --use-first $net_admin_pot $common_pot -o $net_admin_pot" ); |
|
341 | + $net_admin_pot = realpath(is_null($output) ? 'wordpress-network-admin.pot' : $output); |
|
342 | + system("msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot"); |
|
343 | + system("msgcat -u --use-first $net_admin_pot $common_pot -o $net_admin_pot"); |
|
344 | 344 | return true; |
345 | 345 | } |
346 | 346 | |
347 | - private function get_wp_network_admin_files( $dir ) { |
|
348 | - $wp_version = $this->wp_version( $dir ); |
|
347 | + private function get_wp_network_admin_files($dir) { |
|
348 | + $wp_version = $this->wp_version($dir); |
|
349 | 349 | |
350 | 350 | // https://core.trac.wordpress.org/ticket/19852 |
351 | - $files = array( 'wp-admin/network/.*', 'wp-admin/network.php' ); |
|
351 | + $files = array('wp-admin/network/.*', 'wp-admin/network.php'); |
|
352 | 352 | |
353 | 353 | // https://core.trac.wordpress.org/ticket/34910 |
354 | - if ( version_compare( $wp_version, '4.5-beta', '>=' ) ) { |
|
355 | - $files = array_merge( $files, array( |
|
354 | + if (version_compare($wp_version, '4.5-beta', '>=')) { |
|
355 | + $files = array_merge($files, array( |
|
356 | 356 | 'wp-admin/includes/class-wp-ms.*', |
357 | 357 | 'wp-admin/includes/network.php', |
358 | - ) ); |
|
358 | + )); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $files; |
362 | 362 | } |
363 | 363 | |
364 | - public function wp_tz( $dir, $output ) { |
|
365 | - return $this->wp_generic( $dir, array( |
|
364 | + public function wp_tz($dir, $output) { |
|
365 | + return $this->wp_generic($dir, array( |
|
366 | 366 | 'project' => 'wp-tz', 'output' => $output, |
367 | - 'includes' => array( 'wp-admin/includes/continents-cities\.php' ), |
|
367 | + 'includes' => array('wp-admin/includes/continents-cities\.php'), |
|
368 | 368 | 'excludes' => array(), |
369 | 369 | 'default_output' => 'wordpress-continents-cities.pot', |
370 | - ) ); |
|
370 | + )); |
|
371 | 371 | } |
372 | 372 | |
373 | - private function wp_version( $dir ) { |
|
373 | + private function wp_version($dir) { |
|
374 | 374 | $version_php = $dir.'/wp-includes/version.php'; |
375 | - if ( !is_readable( $version_php ) ) return false; |
|
376 | - return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches )? $matches[1] : false; |
|
375 | + if ( ! is_readable($version_php)) return false; |
|
376 | + return preg_match('/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents($version_php), $matches) ? $matches[1] : false; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | public function get_first_lines($filename, $lines = 30) { |
380 | 380 | $extf = fopen($filename, 'r'); |
381 | - if (!$extf) return false; |
|
381 | + if ( ! $extf) return false; |
|
382 | 382 | $first_lines = ''; |
383 | - foreach(range(1, $lines) as $x) { |
|
383 | + foreach (range(1, $lines) as $x) { |
|
384 | 384 | $line = fgets($extf); |
385 | 385 | if (feof($extf)) break; |
386 | 386 | if (false === $line) { |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | // PHP will close file handle, but we are good citizens. |
393 | - fclose( $extf ); |
|
393 | + fclose($extf); |
|
394 | 394 | |
395 | 395 | // Make sure we catch CR-only line endings. |
396 | - $first_lines = str_replace( "\r", "\n", $first_lines ); |
|
396 | + $first_lines = str_replace("\r", "\n", $first_lines); |
|
397 | 397 | |
398 | 398 | return $first_lines; |
399 | 399 | } |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | * - '<?php // Header: Value ?>' |
408 | 408 | * - '<?php /* Header: Value * / $foo='bar'; ?>' |
409 | 409 | */ |
410 | - if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $header, '/' ) . ':(.*)$/mi', $source, $matches ) ) { |
|
411 | - return $this->_cleanup_header_comment( $matches[1] ); |
|
410 | + if (preg_match('/^(?:[ \t]*<\?php)?[ \t\/*#@]*'.preg_quote($header, '/').':(.*)$/mi', $source, $matches)) { |
|
411 | + return $this->_cleanup_header_comment($matches[1]); |
|
412 | 412 | } else { |
413 | 413 | return false; |
414 | 414 | } |
@@ -417,12 +417,12 @@ discard block |
||
417 | 417 | /** |
418 | 418 | * Removes any trailing closing comment / PHP tags from the header value |
419 | 419 | */ |
420 | - private function _cleanup_header_comment( $str ) { |
|
421 | - return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) ); |
|
420 | + private function _cleanup_header_comment($str) { |
|
421 | + return trim(preg_replace('/\s*(?:\*\/|\?>).*/', '', $str)); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | public function generic($dir, $output) { |
425 | - $output = is_null($output)? "generic.pot" : $output; |
|
425 | + $output = is_null($output) ? "generic.pot" : $output; |
|
426 | 426 | return $this->xgettext('generic', $dir, $output, array()); |
427 | 427 | } |
428 | 428 | |
@@ -437,53 +437,53 @@ discard block |
||
437 | 437 | return $slug; |
438 | 438 | } |
439 | 439 | |
440 | - public function wp_plugin( $dir, $output, $slug = null, $args = array() ) { |
|
440 | + public function wp_plugin($dir, $output, $slug = null, $args = array()) { |
|
441 | 441 | $defaults = array( |
442 | 442 | 'excludes' => array(), |
443 | 443 | 'includes' => array(), |
444 | 444 | ); |
445 | - $args = array_merge( $defaults, $args ); |
|
445 | + $args = array_merge($defaults, $args); |
|
446 | 446 | $placeholders = array(); |
447 | 447 | // guess plugin slug |
448 | 448 | if (is_null($slug)) { |
449 | 449 | $slug = $this->guess_plugin_slug($dir); |
450 | 450 | } |
451 | 451 | |
452 | - $plugins_dir = @opendir( $dir ); |
|
452 | + $plugins_dir = @opendir($dir); |
|
453 | 453 | $plugin_files = array(); |
454 | - if ( $plugins_dir ) { |
|
455 | - while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
456 | - if ( '.' === substr( $file, 0, 1 ) ) { |
|
454 | + if ($plugins_dir) { |
|
455 | + while (($file = readdir($plugins_dir)) !== false) { |
|
456 | + if ('.' === substr($file, 0, 1)) { |
|
457 | 457 | continue; |
458 | 458 | } |
459 | 459 | |
460 | - if ( '.php' === substr( $file, -4 ) ) { |
|
460 | + if ('.php' === substr($file, -4)) { |
|
461 | 461 | $plugin_files[] = $file; |
462 | 462 | } |
463 | 463 | } |
464 | - closedir( $plugins_dir ); |
|
464 | + closedir($plugins_dir); |
|
465 | 465 | } |
466 | 466 | |
467 | - if ( empty( $plugin_files ) ) { |
|
467 | + if (empty($plugin_files)) { |
|
468 | 468 | return false; |
469 | 469 | } |
470 | 470 | |
471 | 471 | $main_file = ''; |
472 | - foreach ( $plugin_files as $plugin_file ) { |
|
473 | - if ( ! is_readable( "$dir/$plugin_file" ) ) { |
|
472 | + foreach ($plugin_files as $plugin_file) { |
|
473 | + if ( ! is_readable("$dir/$plugin_file")) { |
|
474 | 474 | continue; |
475 | 475 | } |
476 | 476 | |
477 | - $source = $this->get_first_lines( "$dir/$plugin_file", $this->max_header_lines ); |
|
477 | + $source = $this->get_first_lines("$dir/$plugin_file", $this->max_header_lines); |
|
478 | 478 | |
479 | 479 | // Stop when we find a file with a plugin name header in it. |
480 | - if ( $this->get_addon_header( 'Plugin Name', $source ) != false ) { |
|
480 | + if ($this->get_addon_header('Plugin Name', $source) != false) { |
|
481 | 481 | $main_file = "$dir/$plugin_file"; |
482 | 482 | break; |
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
486 | - if ( empty( $main_file ) ) { |
|
486 | + if (empty($main_file)) { |
|
487 | 487 | return false; |
488 | 488 | } |
489 | 489 | |
@@ -492,9 +492,9 @@ discard block |
||
492 | 492 | $placeholders['name'] = $this->get_addon_header('Plugin Name', $source); |
493 | 493 | $placeholders['slug'] = $slug; |
494 | 494 | |
495 | - $output = is_null($output)? "$slug.pot" : $output; |
|
496 | - $res = $this->xgettext( 'wp-plugin', $dir, $output, $placeholders, $args['excludes'], $args['includes'] ); |
|
497 | - if (!$res) return false; |
|
495 | + $output = is_null($output) ? "$slug.pot" : $output; |
|
496 | + $res = $this->xgettext('wp-plugin', $dir, $output, $placeholders, $args['excludes'], $args['includes']); |
|
497 | + if ( ! $res) return false; |
|
498 | 498 | $potextmeta = new PotExtMeta; |
499 | 499 | $res = $potextmeta->append($main_file, $output); |
500 | 500 | /* Adding non-gettexted strings can repeat some phrases */ |
@@ -517,37 +517,37 @@ discard block |
||
517 | 517 | $placeholders['name'] = $this->get_addon_header('Theme Name', $source); |
518 | 518 | $placeholders['slug'] = $slug; |
519 | 519 | |
520 | - $license = $this->get_addon_header( 'License', $source ); |
|
521 | - if ( $license ) |
|
520 | + $license = $this->get_addon_header('License', $source); |
|
521 | + if ($license) |
|
522 | 522 | $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
523 | 523 | else |
524 | 524 | $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
525 | 525 | |
526 | - $output = is_null($output)? "$slug.pot" : $output; |
|
526 | + $output = is_null($output) ? "$slug.pot" : $output; |
|
527 | 527 | $res = $this->xgettext('wp-theme', $dir, $output, $placeholders); |
528 | - if (! $res ) |
|
528 | + if ( ! $res) |
|
529 | 529 | return false; |
530 | 530 | $potextmeta = new PotExtMeta; |
531 | - $res = $potextmeta->append( $main_file, $output, array( 'Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI' ) ); |
|
532 | - if ( ! $res ) |
|
531 | + $res = $potextmeta->append($main_file, $output, array('Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI')); |
|
532 | + if ( ! $res) |
|
533 | 533 | return false; |
534 | 534 | // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4. |
535 | - $extract_templates = ! in_array( $slug, array( 'twentyten', 'twentyeleven', 'default', 'classic' ) ); |
|
536 | - if ( ! $extract_templates ) { |
|
537 | - $wp_dir = dirname( dirname( dirname( $dir ) ) ); |
|
538 | - $extract_templates = file_exists( "$wp_dir/wp-admin/user/about.php" ) || ! file_exists( "$wp_dir/wp-load.php" ); |
|
535 | + $extract_templates = ! in_array($slug, array('twentyten', 'twentyeleven', 'default', 'classic')); |
|
536 | + if ( ! $extract_templates) { |
|
537 | + $wp_dir = dirname(dirname(dirname($dir))); |
|
538 | + $extract_templates = file_exists("$wp_dir/wp-admin/user/about.php") || ! file_exists("$wp_dir/wp-load.php"); |
|
539 | 539 | } |
540 | - if ( $extract_templates ) { |
|
541 | - $res = $potextmeta->append( $dir, $output, array( 'Template Name' ) ); |
|
542 | - if ( ! $res ) |
|
540 | + if ($extract_templates) { |
|
541 | + $res = $potextmeta->append($dir, $output, array('Template Name')); |
|
542 | + if ( ! $res) |
|
543 | 543 | return false; |
544 | - $files = scandir( $dir ); |
|
545 | - foreach ( $files as $file ) { |
|
546 | - if ( '.' == $file[0] || 'CVS' == $file ) |
|
544 | + $files = scandir($dir); |
|
545 | + foreach ($files as $file) { |
|
546 | + if ('.' == $file[0] || 'CVS' == $file) |
|
547 | 547 | continue; |
548 | - if ( is_dir( $dir . '/' . $file ) ) { |
|
549 | - $res = $potextmeta->append( $dir . '/' . $file, $output, array( 'Template Name' ) ); |
|
550 | - if ( ! $res ) |
|
548 | + if (is_dir($dir.'/'.$file)) { |
|
549 | + $res = $potextmeta->append($dir.'/'.$file, $output, array('Template Name')); |
|
550 | + if ( ! $res) |
|
551 | 551 | return false; |
552 | 552 | } |
553 | 553 | } |
@@ -558,54 +558,54 @@ discard block |
||
558 | 558 | return $res; |
559 | 559 | } |
560 | 560 | |
561 | - public function glotpress( $dir, $output ) { |
|
562 | - $output = is_null( $output ) ? "glotpress.pot" : $output; |
|
563 | - return $this->xgettext( 'glotpress', $dir, $output ); |
|
561 | + public function glotpress($dir, $output) { |
|
562 | + $output = is_null($output) ? "glotpress.pot" : $output; |
|
563 | + return $this->xgettext('glotpress', $dir, $output); |
|
564 | 564 | } |
565 | 565 | |
566 | - public function wporg_bb_forums( $dir, $output ) { |
|
567 | - $output = is_null( $output ) ? 'wporg.pot' : $output; |
|
568 | - return $this->xgettext( 'wporg-bb-forums', $dir, $output, array(), array( |
|
566 | + public function wporg_bb_forums($dir, $output) { |
|
567 | + $output = is_null($output) ? 'wporg.pot' : $output; |
|
568 | + return $this->xgettext('wporg-bb-forums', $dir, $output, array(), array( |
|
569 | 569 | 'bb-plugins/elfakismet/.*', |
570 | 570 | 'bb-plugins/support-forum/.*', |
571 | 571 | 'themes/.*', |
572 | - ) ); |
|
572 | + )); |
|
573 | 573 | } |
574 | 574 | |
575 | - public function wporg_themes( $dir, $output ) { |
|
576 | - $output = is_null( $output ) ? 'wporg-themes.pot' : $output; |
|
577 | - return $this->xgettext( 'wporg', $dir, $output, array(), array(), array( |
|
575 | + public function wporg_themes($dir, $output) { |
|
576 | + $output = is_null($output) ? 'wporg-themes.pot' : $output; |
|
577 | + return $this->xgettext('wporg', $dir, $output, array(), array(), array( |
|
578 | 578 | 'plugins/theme-directory/.*', |
579 | 579 | 'themes/pub/wporg-themes/.*' |
580 | - ) ); |
|
580 | + )); |
|
581 | 581 | } |
582 | 582 | |
583 | - public function wporg_plugins( $dir, $output ) { |
|
584 | - $output = is_null( $output ) ? 'wporg-plugins.pot' : $output; |
|
585 | - return $this->xgettext( 'wporg', $dir, $output, array(), array( |
|
583 | + public function wporg_plugins($dir, $output) { |
|
584 | + $output = is_null($output) ? 'wporg-plugins.pot' : $output; |
|
585 | + return $this->xgettext('wporg', $dir, $output, array(), array( |
|
586 | 586 | 'plugins/svn-track/i18n-tools/.*' |
587 | 587 | ), array( |
588 | 588 | '.*\.php', |
589 | - ) ); |
|
589 | + )); |
|
590 | 590 | } |
591 | 591 | |
592 | - public function wporg_forums( $dir, $output ) { |
|
593 | - $output = is_null( $output ) ? 'wporg-forums.pot' : $output; |
|
594 | - return $this->xgettext( 'wporg', $dir, $output, array(), array(), array( |
|
592 | + public function wporg_forums($dir, $output) { |
|
593 | + $output = is_null($output) ? 'wporg-forums.pot' : $output; |
|
594 | + return $this->xgettext('wporg', $dir, $output, array(), array(), array( |
|
595 | 595 | '.*\.php', |
596 | - ) ); |
|
596 | + )); |
|
597 | 597 | } |
598 | 598 | |
599 | - public function wordcamporg( $dir, $output ) { |
|
600 | - $output = is_null( $output ) ? 'wordcamporg.pot' : $output; |
|
601 | - return $this->xgettext( 'wordcamporg', $dir, $output, array(), array(), array( |
|
599 | + public function wordcamporg($dir, $output) { |
|
600 | + $output = is_null($output) ? 'wordcamporg.pot' : $output; |
|
601 | + return $this->xgettext('wordcamporg', $dir, $output, array(), array(), array( |
|
602 | 602 | '.*\.php', |
603 | - ) ); |
|
603 | + )); |
|
604 | 604 | } |
605 | 605 | |
606 | - public function rosetta( $dir, $output ) { |
|
607 | - $output = is_null( $output )? 'rosetta.pot' : $output; |
|
608 | - return $this->xgettext( 'rosetta', $dir, $output, array(), array( |
|
606 | + public function rosetta($dir, $output) { |
|
607 | + $output = is_null($output) ? 'rosetta.pot' : $output; |
|
608 | + return $this->xgettext('rosetta', $dir, $output, array(), array( |
|
609 | 609 | 'mu-plugins/rosetta/i18n-tools/.*', |
610 | 610 | 'mu-plugins/rosetta/locales/.*', |
611 | 611 | ), array( |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | 'mu-plugins/rosetta/[^/]+\.php', |
616 | 616 | 'mu-plugins/rosetta/tmpl/.*\.php', |
617 | 617 | 'themes/rosetta/.*\.php', |
618 | - ) ); |
|
618 | + )); |
|
619 | 619 | } |
620 | 620 | } |
621 | 621 | |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | if ($included_files[0] == __FILE__) { |
626 | 626 | $makepot = new MakePOT; |
627 | 627 | if ((3 == count($argv) || 4 == count($argv)) && in_array($method = str_replace('-', '_', $argv[1]), get_class_methods($makepot))) { |
628 | - $res = call_user_func(array($makepot, $method), realpath($argv[2]), isset($argv[3])? $argv[3] : null); |
|
628 | + $res = call_user_func(array($makepot, $method), realpath($argv[2]), isset($argv[3]) ? $argv[3] : null); |
|
629 | 629 | if (false === $res) { |
630 | 630 | fwrite(STDERR, "Couldn't generate POT file!\n"); |
631 | 631 | } |
@@ -152,8 +152,9 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | public function __destruct() { |
155 | - foreach ( $this->temp_files as $temp_file ) |
|
156 | - unlink( $temp_file ); |
|
155 | + foreach ( $this->temp_files as $temp_file ) { |
|
156 | + unlink( $temp_file ); |
|
157 | + } |
|
157 | 158 | } |
158 | 159 | |
159 | 160 | private function tempnam( $file ) { |
@@ -211,13 +212,16 @@ discard block |
||
211 | 212 | $args = array_merge( $defaults, $args ); |
212 | 213 | extract( $args ); |
213 | 214 | $placeholders = array(); |
214 | - if ( $wp_version = $this->wp_version( $dir ) ) |
|
215 | - $placeholders['version'] = $wp_version; |
|
216 | - else |
|
217 | - return false; |
|
215 | + if ( $wp_version = $this->wp_version( $dir ) ) { |
|
216 | + $placeholders['version'] = $wp_version; |
|
217 | + } else { |
|
218 | + return false; |
|
219 | + } |
|
218 | 220 | $output = is_null( $output )? $default_output : $output; |
219 | 221 | $res = $this->xgettext( $project, $dir, $output, $placeholders, $excludes, $includes ); |
220 | - if ( !$res ) return false; |
|
222 | + if ( !$res ) { |
|
223 | + return false; |
|
224 | + } |
|
221 | 225 | |
222 | 226 | if ( $extract_not_gettexted ) { |
223 | 227 | $old_dir = getcwd(); |
@@ -307,21 +311,29 @@ discard block |
||
307 | 311 | } |
308 | 312 | |
309 | 313 | public function wp_network_admin($dir, $output) { |
310 | - if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) return false; |
|
314 | + if ( ! file_exists( "$dir/wp-admin/user/about.php" ) ) { |
|
315 | + return false; |
|
316 | + } |
|
311 | 317 | |
312 | 318 | $frontend_pot = $this->tempnam( 'frontend.pot' ); |
313 | - if ( false === $frontend_pot ) return false; |
|
319 | + if ( false === $frontend_pot ) { |
|
320 | + return false; |
|
321 | + } |
|
314 | 322 | |
315 | 323 | $frontend_result = $this->wp_frontend( $dir, $frontend_pot ); |
316 | - if ( ! $frontend_result ) |
|
317 | - return false; |
|
324 | + if ( ! $frontend_result ) { |
|
325 | + return false; |
|
326 | + } |
|
318 | 327 | |
319 | 328 | $admin_pot = $this->tempnam( 'admin.pot' ); |
320 | - if ( false === $admin_pot ) return false; |
|
329 | + if ( false === $admin_pot ) { |
|
330 | + return false; |
|
331 | + } |
|
321 | 332 | |
322 | 333 | $admin_result = $this->wp_admin( $dir, $admin_pot ); |
323 | - if ( ! $admin_result ) |
|
324 | - return false; |
|
334 | + if ( ! $admin_result ) { |
|
335 | + return false; |
|
336 | + } |
|
325 | 337 | |
326 | 338 | $result = $this->wp_generic( $dir, array( |
327 | 339 | 'project' => 'wp-network-admin', 'output' => $output, |
@@ -335,8 +347,9 @@ discard block |
||
335 | 347 | } |
336 | 348 | |
337 | 349 | $common_pot = $this->tempnam( 'common.pot' ); |
338 | - if ( ! $common_pot ) |
|
339 | - return false; |
|
350 | + if ( ! $common_pot ) { |
|
351 | + return false; |
|
352 | + } |
|
340 | 353 | |
341 | 354 | $net_admin_pot = realpath( is_null( $output ) ? 'wordpress-network-admin.pot' : $output ); |
342 | 355 | system( "msgcat --more-than=1 --use-first $frontend_pot $admin_pot $net_admin_pot > $common_pot" ); |
@@ -372,17 +385,23 @@ discard block |
||
372 | 385 | |
373 | 386 | private function wp_version( $dir ) { |
374 | 387 | $version_php = $dir.'/wp-includes/version.php'; |
375 | - if ( !is_readable( $version_php ) ) return false; |
|
388 | + if ( !is_readable( $version_php ) ) { |
|
389 | + return false; |
|
390 | + } |
|
376 | 391 | return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches )? $matches[1] : false; |
377 | 392 | } |
378 | 393 | |
379 | 394 | public function get_first_lines($filename, $lines = 30) { |
380 | 395 | $extf = fopen($filename, 'r'); |
381 | - if (!$extf) return false; |
|
396 | + if (!$extf) { |
|
397 | + return false; |
|
398 | + } |
|
382 | 399 | $first_lines = ''; |
383 | 400 | foreach(range(1, $lines) as $x) { |
384 | 401 | $line = fgets($extf); |
385 | - if (feof($extf)) break; |
|
402 | + if (feof($extf)) { |
|
403 | + break; |
|
404 | + } |
|
386 | 405 | if (false === $line) { |
387 | 406 | return false; |
388 | 407 | } |
@@ -494,7 +513,9 @@ discard block |
||
494 | 513 | |
495 | 514 | $output = is_null($output)? "$slug.pot" : $output; |
496 | 515 | $res = $this->xgettext( 'wp-plugin', $dir, $output, $placeholders, $args['excludes'], $args['includes'] ); |
497 | - if (!$res) return false; |
|
516 | + if (!$res) { |
|
517 | + return false; |
|
518 | + } |
|
498 | 519 | $potextmeta = new PotExtMeta; |
499 | 520 | $res = $potextmeta->append($main_file, $output); |
500 | 521 | /* Adding non-gettexted strings can repeat some phrases */ |
@@ -518,19 +539,22 @@ discard block |
||
518 | 539 | $placeholders['slug'] = $slug; |
519 | 540 | |
520 | 541 | $license = $this->get_addon_header( 'License', $source ); |
521 | - if ( $license ) |
|
522 | - $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
|
523 | - else |
|
524 | - $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
|
542 | + if ( $license ) { |
|
543 | + $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the {$license}."; |
|
544 | + } else { |
|
545 | + $this->meta['wp-theme']['comments'] = "Copyright (C) {year} {author}\nThis file is distributed under the same license as the {package-name} package."; |
|
546 | + } |
|
525 | 547 | |
526 | 548 | $output = is_null($output)? "$slug.pot" : $output; |
527 | 549 | $res = $this->xgettext('wp-theme', $dir, $output, $placeholders); |
528 | - if (! $res ) |
|
529 | - return false; |
|
550 | + if (! $res ) { |
|
551 | + return false; |
|
552 | + } |
|
530 | 553 | $potextmeta = new PotExtMeta; |
531 | 554 | $res = $potextmeta->append( $main_file, $output, array( 'Theme Name', 'Theme URI', 'Description', 'Author', 'Author URI' ) ); |
532 | - if ( ! $res ) |
|
533 | - return false; |
|
555 | + if ( ! $res ) { |
|
556 | + return false; |
|
557 | + } |
|
534 | 558 | // If we're dealing with a pre-3.4 default theme, don't extract page templates before 3.4. |
535 | 559 | $extract_templates = ! in_array( $slug, array( 'twentyten', 'twentyeleven', 'default', 'classic' ) ); |
536 | 560 | if ( ! $extract_templates ) { |
@@ -539,16 +563,19 @@ discard block |
||
539 | 563 | } |
540 | 564 | if ( $extract_templates ) { |
541 | 565 | $res = $potextmeta->append( $dir, $output, array( 'Template Name' ) ); |
542 | - if ( ! $res ) |
|
543 | - return false; |
|
566 | + if ( ! $res ) { |
|
567 | + return false; |
|
568 | + } |
|
544 | 569 | $files = scandir( $dir ); |
545 | 570 | foreach ( $files as $file ) { |
546 | - if ( '.' == $file[0] || 'CVS' == $file ) |
|
547 | - continue; |
|
571 | + if ( '.' == $file[0] || 'CVS' == $file ) { |
|
572 | + continue; |
|
573 | + } |
|
548 | 574 | if ( is_dir( $dir . '/' . $file ) ) { |
549 | 575 | $res = $potextmeta->append( $dir . '/' . $file, $output, array( 'Template Name' ) ); |
550 | - if ( ! $res ) |
|
551 | - return false; |
|
576 | + if ( ! $res ) { |
|
577 | + return false; |
|
578 | + } |
|
552 | 579 | } |
553 | 580 | } |
554 | 581 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | error_reporting(E_ALL); |
9 | 9 | |
10 | -require_once dirname( __FILE__ ) . '/makepot.php'; |
|
10 | +require_once dirname(__FILE__).'/makepot.php'; |
|
11 | 11 | |
12 | 12 | class AddTextdomain { |
13 | 13 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct() { |
21 | 21 | $makepot = new MakePOT; |
22 | - $this->funcs = array_keys( $makepot->rules ); |
|
22 | + $this->funcs = array_keys($makepot->rules); |
|
23 | 23 | $this->funcs[] = 'translate_nooped_plural'; |
24 | 24 | } |
25 | 25 | |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | * @param string $source_filename Filename with optional path. |
42 | 42 | * @param bool $inplace True to modifies the PHP file in place. False to print to standard output. |
43 | 43 | */ |
44 | - public function process_file( $domain, $source_filename, $inplace ) { |
|
45 | - $new_source = $this->process_string( $domain, file_get_contents( $source_filename ) ); |
|
44 | + public function process_file($domain, $source_filename, $inplace) { |
|
45 | + $new_source = $this->process_string($domain, file_get_contents($source_filename)); |
|
46 | 46 | |
47 | - if ( $inplace ) { |
|
48 | - $f = fopen( $source_filename, 'w' ); |
|
49 | - fwrite( $f, $new_source ); |
|
50 | - fclose( $f ); |
|
47 | + if ($inplace) { |
|
48 | + $f = fopen($source_filename, 'w'); |
|
49 | + fwrite($f, $new_source); |
|
50 | + fclose($f); |
|
51 | 51 | } else { |
52 | 52 | echo $new_source; |
53 | 53 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param string $string PHP code to parse. |
65 | 65 | * @return string Modified source. |
66 | 66 | */ |
67 | - public function process_string( $domain, $string ) { |
|
68 | - $tokens = token_get_all( $string ); |
|
69 | - return $this->process_tokens( $domain, $tokens ); |
|
67 | + public function process_string($domain, $string) { |
|
68 | + $tokens = token_get_all($string); |
|
69 | + return $this->process_tokens($domain, $tokens); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -79,16 +79,16 @@ discard block |
||
79 | 79 | * number in element 2. |
80 | 80 | * @return string Modified source. |
81 | 81 | */ |
82 | - public function process_tokens( $domain, $tokens ) { |
|
82 | + public function process_tokens($domain, $tokens) { |
|
83 | 83 | $this->modified_contents = ''; |
84 | - $domain = addslashes( $domain ); |
|
84 | + $domain = addslashes($domain); |
|
85 | 85 | |
86 | 86 | $in_func = false; |
87 | 87 | $args_started = false; |
88 | 88 | $parens_balance = 0; |
89 | 89 | $found_domain = false; |
90 | 90 | |
91 | - foreach($tokens as $index => $token) { |
|
91 | + foreach ($tokens as $index => $token) { |
|
92 | 92 | $string_success = false; |
93 | 93 | if (is_array($token)) { |
94 | 94 | list($id, $text) = $token; |
@@ -103,18 +103,18 @@ discard block |
||
103 | 103 | } |
104 | 104 | } |
105 | 105 | $token = $text; |
106 | - } elseif ('(' == $token){ |
|
106 | + } elseif ('(' == $token) { |
|
107 | 107 | $args_started = true; |
108 | 108 | ++$parens_balance; |
109 | 109 | } elseif (')' == $token) { |
110 | 110 | --$parens_balance; |
111 | 111 | if ($in_func && 0 == $parens_balance) { |
112 | - if ( ! $found_domain ) { |
|
112 | + if ( ! $found_domain) { |
|
113 | 113 | $token = ", '$domain'"; |
114 | - if ( T_WHITESPACE == $tokens[ $index - 1 ][0] ) { |
|
114 | + if (T_WHITESPACE == $tokens[$index - 1][0]) { |
|
115 | 115 | $token .= ' '; // Maintain code standards if previously present |
116 | 116 | // Remove previous whitespace token to account for it. |
117 | - $this->modified_contents = trim( $this->modified_contents ); |
|
117 | + $this->modified_contents = trim($this->modified_contents); |
|
118 | 118 | } |
119 | 119 | $token .= ')'; |
120 | 120 | } |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | if ($included_files[0] == __FILE__) { |
136 | 136 | $adddomain = new AddTextdomain(); |
137 | 137 | |
138 | - if (!isset($argv[1]) || !isset($argv[2])) { |
|
138 | + if ( ! isset($argv[1]) || ! isset($argv[2])) { |
|
139 | 139 | $adddomain->usage(); |
140 | 140 | } |
141 | 141 | |
142 | 142 | $inplace = false; |
143 | 143 | if ('-i' == $argv[1]) { |
144 | 144 | $inplace = true; |
145 | - if (!isset($argv[3])) $adddomain->usage(); |
|
145 | + if ( ! isset($argv[3])) $adddomain->usage(); |
|
146 | 146 | array_shift($argv); |
147 | 147 | } |
148 | 148 | |
149 | - if ( is_dir( $argv[2] ) ) { |
|
150 | - $directory = new RecursiveDirectoryIterator( $argv[2], RecursiveDirectoryIterator::SKIP_DOTS ); |
|
151 | - $files = new RecursiveIteratorIterator( $directory ); |
|
152 | - foreach ( $files as $file ) { |
|
153 | - if ( 'php' === $file->getExtension() ) { |
|
154 | - $adddomain->process_file( $argv[1], $file->getPathname(), $inplace ); |
|
149 | + if (is_dir($argv[2])) { |
|
150 | + $directory = new RecursiveDirectoryIterator($argv[2], RecursiveDirectoryIterator::SKIP_DOTS); |
|
151 | + $files = new RecursiveIteratorIterator($directory); |
|
152 | + foreach ($files as $file) { |
|
153 | + if ('php' === $file->getExtension()) { |
|
154 | + $adddomain->process_file($argv[1], $file->getPathname(), $inplace); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | } else { |
158 | - $adddomain->process_file( $argv[1], $argv[2], $inplace ); |
|
158 | + $adddomain->process_file($argv[1], $argv[2], $inplace); |
|
159 | 159 | } |
160 | 160 | } |
@@ -142,7 +142,9 @@ |
||
142 | 142 | $inplace = false; |
143 | 143 | if ('-i' == $argv[1]) { |
144 | 144 | $inplace = true; |
145 | - if (!isset($argv[3])) $adddomain->usage(); |
|
145 | + if (!isset($argv[3])) { |
|
146 | + $adddomain->usage(); |
|
147 | + } |
|
146 | 148 | array_shift($argv); |
147 | 149 | } |
148 | 150 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Tests for add-textdomain.php |
|
4 | - * |
|
5 | - * @package wordpress-i18n |
|
6 | - * @subpackage tools |
|
7 | - */ |
|
3 | + * Tests for add-textdomain.php |
|
4 | + * |
|
5 | + * @package wordpress-i18n |
|
6 | + * @subpackage tools |
|
7 | + */ |
|
8 | 8 | error_reporting( E_ALL ); |
9 | 9 | require_once dirname( dirname( __FILE__ ) ) . '/add-textdomain.php'; |
10 | 10 |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | * @package wordpress-i18n |
6 | 6 | * @subpackage tools |
7 | 7 | */ |
8 | -error_reporting( E_ALL ); |
|
9 | -require_once dirname( dirname( __FILE__ ) ) . '/add-textdomain.php'; |
|
8 | +error_reporting(E_ALL); |
|
9 | +require_once dirname(dirname(__FILE__)).'/add-textdomain.php'; |
|
10 | 10 | |
11 | 11 | class AddTextDomainTest extends PHPUnit_Framework_TestCase { |
12 | 12 | |
@@ -17,30 +17,30 @@ discard block |
||
17 | 17 | |
18 | 18 | function test_add() { |
19 | 19 | // Copy to a new file, so that we don't corrupt the old one. |
20 | - copy( 'data/add-textdomain-0.php', 'data/add-textdomain-0-work.php' ); |
|
21 | - $this->atd->process_file( 'test-domain', 'data/add-textdomain-0-work.php', true ); |
|
22 | - $this->assertEquals( file_get_contents( 'data/add-textdomain-0-result.php' ), file_get_contents( 'data/add-textdomain-0-work.php' ) ); |
|
23 | - unlink( 'data/add-textdomain-0-work.php' ); |
|
20 | + copy('data/add-textdomain-0.php', 'data/add-textdomain-0-work.php'); |
|
21 | + $this->atd->process_file('test-domain', 'data/add-textdomain-0-work.php', true); |
|
22 | + $this->assertEquals(file_get_contents('data/add-textdomain-0-result.php'), file_get_contents('data/add-textdomain-0-work.php')); |
|
23 | + unlink('data/add-textdomain-0-work.php'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @dataProvider data_textdomain_sources |
28 | 28 | */ |
29 | - function test_basic_add_textdomain( $source, $expected ) { |
|
30 | - $tokens = token_get_all( $source ); |
|
31 | - $result = $this->atd->process_tokens( 'foo', $tokens ); |
|
32 | - $this->assertEquals( $expected, $result ); |
|
29 | + function test_basic_add_textdomain($source, $expected) { |
|
30 | + $tokens = token_get_all($source); |
|
31 | + $result = $this->atd->process_tokens('foo', $tokens); |
|
32 | + $this->assertEquals($expected, $result); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | function data_textdomain_sources() { |
36 | 36 | return array( |
37 | - array( "<?php __('string'); ?>", "<?php __('string', 'foo'); ?>" ), // Simple single quotes |
|
38 | - array( '<?php __("string"); ?>', "<?php __(\"string\", 'foo'); ?>" ), // Simple double quotes |
|
39 | - array( "<?php __( 'string' ); ?>", "<?php __( 'string', 'foo' ); ?>" ), // Simple single quotes CS |
|
40 | - array( '<?php __( "string" ); ?>', "<?php __( \"string\", 'foo' ); ?>" ), // Simple double quotes CS |
|
41 | - array( "<?php __( 'string', 'string2' ); ?>", "<?php __( 'string', 'string2', 'foo' ); ?>" ), // Multiple string args |
|
42 | - array( '<?php __( \'string\', $var ); ?>', '<?php __( \'string\', $var, \'foo\' ); ?>' ), // Multiple string / var args |
|
43 | - array( "<?php __( 'string', 'foo' ); ?>", "<?php __( 'string', 'foo' ); ?>" ), // Existing textdomain |
|
37 | + array("<?php __('string'); ?>", "<?php __('string', 'foo'); ?>"), // Simple single quotes |
|
38 | + array('<?php __("string"); ?>', "<?php __(\"string\", 'foo'); ?>"), // Simple double quotes |
|
39 | + array("<?php __( 'string' ); ?>", "<?php __( 'string', 'foo' ); ?>"), // Simple single quotes CS |
|
40 | + array('<?php __( "string" ); ?>', "<?php __( \"string\", 'foo' ); ?>"), // Simple double quotes CS |
|
41 | + array("<?php __( 'string', 'string2' ); ?>", "<?php __( 'string', 'string2', 'foo' ); ?>"), // Multiple string args |
|
42 | + array('<?php __( \'string\', $var ); ?>', '<?php __( \'string\', $var, \'foo\' ); ?>'), // Multiple string / var args |
|
43 | + array("<?php __( 'string', 'foo' ); ?>", "<?php __( 'string', 'foo' ); ?>"), // Existing textdomain |
|
44 | 44 | ); |
45 | 45 | } |
46 | 46 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once dirname( dirname( __FILE__ ) ) . '/extract.php'; |
|
3 | +require_once dirname(dirname(__FILE__)).'/extract.php'; |
|
4 | 4 | |
5 | 5 | class ExtractTest extends PHPUnit_Framework_TestCase { |
6 | 6 | |
@@ -12,126 +12,126 @@ discard block |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | function test_with_just_a_string() { |
15 | - $expected = new Translation_Entry( array( 'singular' => 'baba', 'references' => array('baba.php:1') ) ); |
|
16 | - $result = $this->extractor->extract_from_code('<?php __("baba"); ?>', 'baba.php' ); |
|
17 | - $this->assertEquals( $expected, $result->entries['baba'] ); |
|
15 | + $expected = new Translation_Entry(array('singular' => 'baba', 'references' => array('baba.php:1'))); |
|
16 | + $result = $this->extractor->extract_from_code('<?php __("baba"); ?>', 'baba.php'); |
|
17 | + $this->assertEquals($expected, $result->entries['baba']); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function test_entry_from_call_simple() { |
21 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba') ), 'baba.php' ); |
|
22 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba' ) ) ); |
|
21 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array('baba')), 'baba.php'); |
|
22 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => 'baba'))); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | function test_entry_from_call_nonexisting_function() { |
26 | - $entry = $this->extractor->entry_from_call( array( 'name' => 'f', 'args' => array('baba') ), 'baba.php' ); |
|
27 | - $this->assertEquals( $entry, null ); |
|
26 | + $entry = $this->extractor->entry_from_call(array('name' => 'f', 'args' => array('baba')), 'baba.php'); |
|
27 | + $this->assertEquals($entry, null); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | function test_entry_from_call_too_few_args() { |
31 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array() ), 'baba.php' ); |
|
32 | - $this->assertEquals( $entry, null ); |
|
31 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array()), 'baba.php'); |
|
32 | + $this->assertEquals($entry, null); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | function test_entry_from_call_non_expected_null_arg() { |
36 | - $this->extractor->rules = array( '_nx' => array( 'singular', 'plural', 'context' ) ); |
|
37 | - $entry = $this->extractor->entry_from_call( array( 'name' => '_nx', 'args' => array('%s baba', null, 'noun') ), 'baba.php' ); |
|
38 | - $this->assertEquals( $entry, null ); |
|
36 | + $this->extractor->rules = array('_nx' => array('singular', 'plural', 'context')); |
|
37 | + $entry = $this->extractor->entry_from_call(array('name' => '_nx', 'args' => array('%s baba', null, 'noun')), 'baba.php'); |
|
38 | + $this->assertEquals($entry, null); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | function test_entry_from_call_more_args_should_be_ok() { |
42 | - $this->extractor->rules = array( '__' => array('string') ); |
|
43 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba', 5, 'pijo', null) ), 'baba.php' ); |
|
44 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba' ) ) ); |
|
42 | + $this->extractor->rules = array('__' => array('string')); |
|
43 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array('baba', 5, 'pijo', null)), 'baba.php'); |
|
44 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => 'baba'))); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
48 | 48 | function test_entry_from_call_context() { |
49 | - $this->extractor->rules = array( '_x' => array( 'string', 'context' ) ); |
|
50 | - $entry = $this->extractor->entry_from_call( array( 'name' => '_x', 'args' => array('baba', 'noun') ), 'baba.php' ); |
|
51 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'context' => 'noun' ) ) ); |
|
49 | + $this->extractor->rules = array('_x' => array('string', 'context')); |
|
50 | + $entry = $this->extractor->entry_from_call(array('name' => '_x', 'args' => array('baba', 'noun')), 'baba.php'); |
|
51 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => 'baba', 'context' => 'noun'))); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | function test_entry_from_call_plural() { |
55 | - $this->extractor->rules = array( '_n' => array( 'singular', 'plural' ) ); |
|
56 | - $entry = $this->extractor->entry_from_call( array( 'name' => '_n', 'args' => array('%s baba', '%s babas') ), 'baba.php' ); |
|
57 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '%s baba', 'plural' => '%s babas' ) ) ); |
|
55 | + $this->extractor->rules = array('_n' => array('singular', 'plural')); |
|
56 | + $entry = $this->extractor->entry_from_call(array('name' => '_n', 'args' => array('%s baba', '%s babas')), 'baba.php'); |
|
57 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => '%s baba', 'plural' => '%s babas'))); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function test_entry_from_call_plural_and_context() { |
61 | - $this->extractor->rules = array( '_nx' => array( 'singular', 'plural', 'context' ) ); |
|
62 | - $entry = $this->extractor->entry_from_call( array( 'name' => '_nx', 'args' => array('%s baba', '%s babas', 'noun') ), 'baba.php' ); |
|
63 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '%s baba', 'plural' => '%s babas', 'context' => 'noun' ) ) ); |
|
61 | + $this->extractor->rules = array('_nx' => array('singular', 'plural', 'context')); |
|
62 | + $entry = $this->extractor->entry_from_call(array('name' => '_nx', 'args' => array('%s baba', '%s babas', 'noun')), 'baba.php'); |
|
63 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => '%s baba', 'plural' => '%s babas', 'context' => 'noun'))); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function test_entry_from_call_extracted_comment() { |
67 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba'), 'comment' => 'translators: give me back my pants!' ), 'baba.php' ); |
|
68 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'extracted_comments' => "translators: give me back my pants!\n" ) ) ); |
|
67 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array('baba'), 'comment' => 'translators: give me back my pants!'), 'baba.php'); |
|
68 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => 'baba', 'extracted_comments' => "translators: give me back my pants!\n"))); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | function test_entry_from_call_line_number() { |
72 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('baba'), 'line' => 10 ), 'baba.php' ); |
|
73 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => 'baba', 'references' => array('baba.php:10') ) ) ); |
|
72 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array('baba'), 'line' => 10), 'baba.php'); |
|
73 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => 'baba', 'references' => array('baba.php:10')))); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | function test_entry_from_call_zero() { |
77 | - $entry = $this->extractor->entry_from_call( array( 'name' => '__', 'args' => array('0') ), 'baba.php' ); |
|
78 | - $this->assertEquals( $entry, new Translation_Entry( array( 'singular' => '0' ) ) ); |
|
77 | + $entry = $this->extractor->entry_from_call(array('name' => '__', 'args' => array('0')), 'baba.php'); |
|
78 | + $this->assertEquals($entry, new Translation_Entry(array('singular' => '0'))); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | function test_entry_from_call_multiple() { |
82 | - $this->extractor->rules = array( 'c' => array( 'string', 'singular', 'plural' ) ); |
|
83 | - $entries = $this->extractor->entry_from_call( array( 'name' => 'c', 'args' => array('baba', 'dyado', 'dyados') ), 'baba.php' ); |
|
84 | - $this->assertEquals( array( |
|
85 | - new Translation_Entry( array( 'singular' => 'baba' ) ), new Translation_Entry( array( 'singular' => 'dyado', 'plural' => 'dyados' ) ) ), $entries ); |
|
82 | + $this->extractor->rules = array('c' => array('string', 'singular', 'plural')); |
|
83 | + $entries = $this->extractor->entry_from_call(array('name' => 'c', 'args' => array('baba', 'dyado', 'dyados')), 'baba.php'); |
|
84 | + $this->assertEquals(array( |
|
85 | + new Translation_Entry(array('singular' => 'baba')), new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados')) ), $entries); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | function test_entry_from_call_multiple_first_plural_then_two_strings() { |
89 | - $this->extractor->rules = array( 'c' => array( 'singular', 'plural', null, 'string', 'string' ) ); |
|
90 | - $entries = $this->extractor->entry_from_call( array( 'name' => 'c', 'args' => array('dyado', 'dyados', 'baba', 'foo', 'bar') ), 'baba.php' ); |
|
91 | - $this->assertEquals( array( |
|
92 | - new Translation_Entry( array( 'singular' => 'dyado', 'plural' => 'dyados' ) ), |
|
93 | - new Translation_Entry( array( 'singular' => 'foo' ) ), |
|
94 | - new Translation_Entry( array( 'singular' => 'bar' ) ) ), $entries ); |
|
89 | + $this->extractor->rules = array('c' => array('singular', 'plural', null, 'string', 'string')); |
|
90 | + $entries = $this->extractor->entry_from_call(array('name' => 'c', 'args' => array('dyado', 'dyados', 'baba', 'foo', 'bar')), 'baba.php'); |
|
91 | + $this->assertEquals(array( |
|
92 | + new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados')), |
|
93 | + new Translation_Entry(array('singular' => 'foo')), |
|
94 | + new Translation_Entry(array('singular' => 'bar')) ), $entries); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | function test_find_function_calls_one_arg_literal() { |
98 | - $this->assertEquals( array( array( 'name' => '__', 'args' => array( 'baba' ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '<?php __("baba"); ?>' ) ); |
|
98 | + $this->assertEquals(array(array('name' => '__', 'args' => array('baba'), 'line' => 1)), $this->extractor->find_function_calls(array('__'), '<?php __("baba"); ?>')); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | function test_find_function_calls_one_arg_zero() { |
102 | - $this->assertEquals( array( array( 'name' => '__', 'args' => array( '0' ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '<?php __("0"); ?>' ) ); |
|
102 | + $this->assertEquals(array(array('name' => '__', 'args' => array('0'), 'line' => 1)), $this->extractor->find_function_calls(array('__'), '<?php __("0"); ?>')); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | function test_find_function_calls_one_arg_non_literal() { |
106 | - $this->assertEquals( array( array( 'name' => '__', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('__'), '<?php __("baba" . "dudu"); ?>' ) ); |
|
106 | + $this->assertEquals(array(array('name' => '__', 'args' => array(null), 'line' => 1)), $this->extractor->find_function_calls(array('__'), '<?php __("baba" . "dudu"); ?>')); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | function test_find_function_calls_shouldnt_be_mistaken_by_a_class() { |
110 | - $this->assertEquals( array(), $this->extractor->find_function_calls( array('__'), '<?php class __ { }; ("dyado");' ) ); |
|
110 | + $this->assertEquals(array(), $this->extractor->find_function_calls(array('__'), '<?php class __ { }; ("dyado");')); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | function test_find_function_calls_2_args_bad_literal() { |
114 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f(5, "baba" ); ' ) ); |
|
114 | + $this->assertEquals(array(array('name' => 'f', 'args' => array(null, "baba"), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f(5, "baba" ); ')); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | function test_find_function_calls_2_args_bad_literal_bad() { |
118 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba", null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f(5, "baba", 5 ); ' ) ); |
|
118 | + $this->assertEquals(array(array('name' => 'f', 'args' => array(null, "baba", null), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f(5, "baba", 5 ); ')); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | function test_find_function_calls_1_arg_bad_concat() { |
122 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( "baba" . "baba" ); ' ) ); |
|
122 | + $this->assertEquals(array(array('name' => 'f', 'args' => array(null), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f( "baba" . "baba" ); ')); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | function test_find_function_calls_1_arg_bad_function_call() { |
126 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( g( "baba" ) ); ' ) ); |
|
126 | + $this->assertEquals(array(array('name' => 'f', 'args' => array(null), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f( g( "baba" ) ); ')); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function test_find_function_calls_2_arg_literal_bad() { |
130 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( "baba", null ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( "baba", null ); ' ) ); |
|
130 | + $this->assertEquals(array(array('name' => 'f', 'args' => array("baba", null), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f( "baba", null ); ')); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | function test_find_function_calls_2_arg_bad_with_parens_literal() { |
134 | - $this->assertEquals( array( array( 'name' => 'f', 'args' => array( null, "baba" ), 'line' => 1 ) ), $this->extractor->find_function_calls( array('f'), '<?php f( g( "dyado", "chicho", "lelya "), "baba" ); ' ) ); |
|
134 | + $this->assertEquals(array(array('name' => 'f', 'args' => array(null, "baba"), 'line' => 1)), $this->extractor->find_function_calls(array('f'), '<?php f( g( "dyado", "chicho", "lelya "), "baba" ); ')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | */ |
140 | 140 | function test_find_function_calls_with_comment() { |
141 | 141 | $this->assertEquals( |
142 | - array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), |
|
143 | - $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ' ) |
|
142 | + array(array('name' => 'f', 'args' => array('baba'), 'line' => 1, 'comment' => 'translators: let your ears fly!')), |
|
143 | + $this->extractor->find_function_calls(array('f'), '<?php /* translators: let your ears fly! */ f( "baba" ); ') |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | */ |
150 | 150 | function test_find_function_calls_with_not_immediate_comment() { |
151 | 151 | $this->assertEquals( |
152 | - array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), |
|
153 | - $this->extractor->find_function_calls( array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ' ) |
|
152 | + array(array('name' => 'f', 'args' => array('baba'), 'line' => 1, 'comment' => 'translators: let your ears fly!')), |
|
153 | + $this->extractor->find_function_calls(array('f'), '<?php /* translators: let your ears fly! */ $foo = g ( f( "baba" ) ); ') |
|
154 | 154 | ); |
155 | 155 | } |
156 | 156 | |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | */ |
160 | 160 | function test_find_function_calls_with_not_immediate_comment_include_only_latest() { |
161 | 161 | $this->assertEquals( |
162 | - array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'translators: let your ears fly!' ) ), |
|
163 | - $this->extractor->find_function_calls( array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ' ) |
|
162 | + array(array('name' => 'f', 'args' => array('baba'), 'line' => 1, 'comment' => 'translators: let your ears fly!')), |
|
163 | + $this->extractor->find_function_calls(array('f'), '<?php /* translators: boo */ /* translators: let your ears fly! */ /* baba */ $foo = g ( f( "baba" ) ); ') |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @group comment |
169 | 169 | */ |
170 | 170 | function test_find_function_calls_with_multi_line_comment() { |
171 | - $this->assertEquals( array( array( |
|
172 | - 'name' => '__', 'args' => array( 'on' ), 'line' => 6, |
|
171 | + $this->assertEquals(array(array( |
|
172 | + 'name' => '__', 'args' => array('on'), 'line' => 6, |
|
173 | 173 | 'comment' => "Translators: If there are characters in your language that are not supported by Lato, translate this to 'off'. Do not translate into your own language." |
174 | - ) ), |
|
175 | - $this->extractor->find_function_calls( array( '__' ), |
|
174 | + )), |
|
175 | + $this->extractor->find_function_calls(array('__'), |
|
176 | 176 | "<?php |
177 | 177 | /* |
178 | 178 | * Translators: If there are characters in your language that are not supported |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | * @group comment |
188 | 188 | */ |
189 | 189 | function test_find_function_calls_with_c_style_comment() { |
190 | - $this->assertEquals( array( array( |
|
191 | - 'name' => '__', 'args' => array( 'on' ), 'line' => 3, |
|
190 | + $this->assertEquals(array(array( |
|
191 | + 'name' => '__', 'args' => array('on'), 'line' => 3, |
|
192 | 192 | 'comment' => 'translators: let your ears fly!' |
193 | - ) ), |
|
194 | - $this->extractor->find_function_calls( array( '__' ), |
|
193 | + )), |
|
194 | + $this->extractor->find_function_calls(array('__'), |
|
195 | 195 | "<?php |
196 | 196 | // translators: let your ears fly! |
197 | 197 | __( 'on' );" |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | * @group comment |
204 | 204 | */ |
205 | 205 | function test_find_function_calls_with_url_in_comment() { |
206 | - $this->assertEquals( array( array( |
|
207 | - 'name' => '__', 'args' => array( 'F j, Y g:i a' ), 'line' => 3, |
|
206 | + $this->assertEquals(array(array( |
|
207 | + 'name' => '__', 'args' => array('F j, Y g:i a'), 'line' => 3, |
|
208 | 208 | 'comment' => 'translators: localized date and time format, see http://php.net/date' |
209 | - ) ), |
|
210 | - $this->extractor->find_function_calls( array( '__' ), |
|
209 | + )), |
|
210 | + $this->extractor->find_function_calls(array('__'), |
|
211 | 211 | "<?php |
212 | 212 | /* translators: localized date and time format, see http://php.net/date */ |
213 | 213 | __( 'F j, Y g:i a' );" |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | function test_comment_prefix_should_be_case_insensitive() { |
222 | 222 | $this->assertEquals( |
223 | - array( array( 'name' => 'f', 'args' => array( 'baba' ), 'line' => 1, 'comment' => 'Translators: let your ears fly!' ) ), |
|
224 | - $this->extractor->find_function_calls( array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ' ) |
|
223 | + array(array('name' => 'f', 'args' => array('baba'), 'line' => 1, 'comment' => 'Translators: let your ears fly!')), |
|
224 | + $this->extractor->find_function_calls(array('f'), '<?php /* Translators: let your ears fly! */ f( "baba" ); ') |
|
225 | 225 | ); |
226 | 226 | } |
227 | 227 | } |