Completed
Push — master ( d99bf9...491baf )
by Stephen
13:47
created
src/wp-includes/rest-api/class-wp-rest-request.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -483,7 +483,7 @@
 block discarded – undo
483 483
 	 * @since 4.4.0
484 484
 	 * @access public
485 485
 	 *
486
-	 * @param array $params Parameter map of key to value.
486
+	 * @param string[] $params Parameter map of key to value.
487 487
 	 */
488 488
 	public function set_url_params( $params ) {
489 489
 		$this->params['URL'] = $params;
Please login to merge, or discard this patch.
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @param string $route      Optional. Request route. Default empty.
119 119
 	 * @param array  $attributes Optional. Request attributes. Default empty array.
120 120
 	 */
121
-	public function __construct( $method = '', $route = '', $attributes = array() ) {
121
+	public function __construct($method = '', $route = '', $attributes = array()) {
122 122
 		$this->params = array(
123 123
 			'URL'   => array(),
124 124
 			'GET'   => array(),
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 			'defaults' => array(),
132 132
 		);
133 133
 
134
-		$this->set_method( $method );
135
-		$this->set_route( $route );
136
-		$this->set_attributes( $attributes );
134
+		$this->set_method($method);
135
+		$this->set_route($route);
136
+		$this->set_attributes($attributes);
137 137
 	}
138 138
 
139 139
 	/**
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @param string $method HTTP method.
158 158
 	 */
159
-	public function set_method( $method ) {
160
-		$this->method = strtoupper( $method );
159
+	public function set_method($method) {
160
+		$this->method = strtoupper($method);
161 161
 	}
162 162
 
163 163
 	/**
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
 	 * @param string $key Header name.
193 193
 	 * @return string Canonicalized name.
194 194
 	 */
195
-	public static function canonicalize_header_name( $key ) {
196
-		$key = strtolower( $key );
197
-		$key = str_replace( '-', '_', $key );
195
+	public static function canonicalize_header_name($key) {
196
+		$key = strtolower($key);
197
+		$key = str_replace('-', '_', $key);
198 198
 
199 199
 		return $key;
200 200
 	}
@@ -212,14 +212,14 @@  discard block
 block discarded – undo
212 212
 	 * @param string $key Header name, will be canonicalized to lowercase.
213 213
 	 * @return string|null String value if set, null otherwise.
214 214
 	 */
215
-	public function get_header( $key ) {
216
-		$key = $this->canonicalize_header_name( $key );
215
+	public function get_header($key) {
216
+		$key = $this->canonicalize_header_name($key);
217 217
 
218
-		if ( ! isset( $this->headers[ $key ] ) ) {
218
+		if ( ! isset($this->headers[$key])) {
219 219
 			return null;
220 220
 		}
221 221
 
222
-		return implode( ',', $this->headers[ $key ] );
222
+		return implode(',', $this->headers[$key]);
223 223
 	}
224 224
 
225 225
 	/**
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 * @param string $key Header name, will be canonicalized to lowercase.
232 232
 	 * @return array|null List of string values if set, null otherwise.
233 233
 	 */
234
-	public function get_header_as_array( $key ) {
235
-		$key = $this->canonicalize_header_name( $key );
234
+	public function get_header_as_array($key) {
235
+		$key = $this->canonicalize_header_name($key);
236 236
 
237
-		if ( ! isset( $this->headers[ $key ] ) ) {
237
+		if ( ! isset($this->headers[$key])) {
238 238
 			return null;
239 239
 		}
240 240
 
241
-		return $this->headers[ $key ];
241
+		return $this->headers[$key];
242 242
 	}
243 243
 
244 244
 	/**
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 	 * @param string $key   Header name.
251 251
 	 * @param string $value Header value, or list of values.
252 252
 	 */
253
-	public function set_header( $key, $value ) {
254
-		$key = $this->canonicalize_header_name( $key );
253
+	public function set_header($key, $value) {
254
+		$key = $this->canonicalize_header_name($key);
255 255
 		$value = (array) $value;
256 256
 
257
-		$this->headers[ $key ] = $value;
257
+		$this->headers[$key] = $value;
258 258
 	}
259 259
 
260 260
 	/**
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
 	 * @param string $key   Header name.
267 267
 	 * @param string $value Header value, or list of values.
268 268
 	 */
269
-	public function add_header( $key, $value ) {
270
-		$key = $this->canonicalize_header_name( $key );
269
+	public function add_header($key, $value) {
270
+		$key = $this->canonicalize_header_name($key);
271 271
 		$value = (array) $value;
272 272
 
273
-		if ( ! isset( $this->headers[ $key ] ) ) {
274
-			$this->headers[ $key ] = array();
273
+		if ( ! isset($this->headers[$key])) {
274
+			$this->headers[$key] = array();
275 275
 		}
276 276
 
277
-		$this->headers[ $key ] = array_merge( $this->headers[ $key ], $value );
277
+		$this->headers[$key] = array_merge($this->headers[$key], $value);
278 278
 	}
279 279
 
280 280
 	/**
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @param string $key Header name.
287 287
 	 */
288
-	public function remove_header( $key ) {
289
-		$key = $this->canonicalize_header_name( $key );
290
-		unset( $this->headers[ $key ] );
288
+	public function remove_header($key) {
289
+		$key = $this->canonicalize_header_name($key);
290
+		unset($this->headers[$key]);
291 291
 	}
292 292
 
293 293
 	/**
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	}
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		$order = array();
357 357
 
358 358
 		$content_type = $this->get_content_type();
359
-		if ( $content_type['value'] === 'application/json' ) {
359
+		if ($content_type['value'] === 'application/json') {
360 360
 			$order[] = 'JSON';
361 361
 		}
362 362
 
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
 		// Ensure we parse the body data.
366 366
 		$body = $this->get_body();
367 367
 
368
-		if ( 'POST' !== $this->method && ! empty( $body ) ) {
368
+		if ('POST' !== $this->method && ! empty($body)) {
369 369
 			$this->parse_body_params();
370 370
 		}
371 371
 
372
-		$accepts_body_data = array( 'POST', 'PUT', 'PATCH', 'DELETE' );
373
-		if ( in_array( $this->method, $accepts_body_data ) ) {
372
+		$accepts_body_data = array('POST', 'PUT', 'PATCH', 'DELETE');
373
+		if (in_array($this->method, $accepts_body_data)) {
374 374
 			$order[] = 'POST';
375 375
 		}
376 376
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 		 * }
394 394
 		 * @param WP_REST_Request $this The request object.
395 395
 		 */
396
-		return apply_filters( 'rest_request_parameter_order', $order, $this );
396
+		return apply_filters('rest_request_parameter_order', $order, $this);
397 397
 	}
398 398
 
399 399
 	/**
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 	 * @param string $key Parameter name.
406 406
 	 * @return mixed|null Value if set, null otherwise.
407 407
 	 */
408
-	public function get_param( $key ) {
408
+	public function get_param($key) {
409 409
 		$order = $this->get_parameter_order();
410 410
 
411
-		foreach ( $order as $type ) {
411
+		foreach ($order as $type) {
412 412
 			// Determine if we have the parameter for this type.
413
-			if ( isset( $this->params[ $type ][ $key ] ) ) {
414
-				return $this->params[ $type ][ $key ];
413
+			if (isset($this->params[$type][$key])) {
414
+				return $this->params[$type][$key];
415 415
 			}
416 416
 		}
417 417
 
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
 	 * @param string $key   Parameter name.
428 428
 	 * @param mixed  $value Parameter value.
429 429
 	 */
430
-	public function set_param( $key, $value ) {
430
+	public function set_param($key, $value) {
431 431
 		$order = $this->get_parameter_order();
432
-		$this->params[ $order[0] ][ $key ] = $value;
432
+		$this->params[$order[0]][$key] = $value;
433 433
 	}
434 434
 
435 435
 	/**
@@ -445,14 +445,14 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public function get_params() {
447 447
 		$order = $this->get_parameter_order();
448
-		$order = array_reverse( $order, true );
448
+		$order = array_reverse($order, true);
449 449
 
450 450
 		$params = array();
451
-		foreach ( $order as $type ) {
451
+		foreach ($order as $type) {
452 452
 			// array_merge / the "+" operator will mess up
453 453
 			// numeric keys, so instead do a manual foreach.
454
-			foreach ( (array) $this->params[ $type ] as $key => $value ) {
455
-				$params[ $key ] = $value;
454
+			foreach ((array) $this->params[$type] as $key => $value) {
455
+				$params[$key] = $value;
456 456
 			}
457 457
 		}
458 458
 
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 	 *
484 484
 	 * @param array $params Parameter map of key to value.
485 485
 	 */
486
-	public function set_url_params( $params ) {
486
+	public function set_url_params($params) {
487 487
 		$this->params['URL'] = $params;
488 488
 	}
489 489
 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 	 *
512 512
 	 * @param array $params Parameter map of key to value.
513 513
 	 */
514
-	public function set_query_params( $params ) {
514
+	public function set_query_params($params) {
515 515
 		$this->params['GET'] = $params;
516 516
 	}
517 517
 
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	 *
540 540
 	 * @param array $params Parameter map of key to value.
541 541
 	 */
542
-	public function set_body_params( $params ) {
542
+	public function set_body_params($params) {
543 543
 		$this->params['POST'] = $params;
544 544
 	}
545 545
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 	 *
568 568
 	 * @param array $params Parameter map of key to value.
569 569
 	 */
570
-	public function set_file_params( $params ) {
570
+	public function set_file_params($params) {
571 571
 		$this->params['FILES'] = $params;
572 572
 	}
573 573
 
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 	 *
596 596
 	 * @param array $params Parameter map of key to value.
597 597
 	 */
598
-	public function set_default_params( $params ) {
598
+	public function set_default_params($params) {
599 599
 		$this->params['defaults'] = $params;
600 600
 	}
601 601
 
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	 *
620 620
 	 * @param string $data Binary data from the request body.
621 621
 	 */
622
-	public function set_body( $data ) {
622
+	public function set_body($data) {
623 623
 		$this->body = $data;
624 624
 
625 625
 		// Enable lazy parsing.
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * @return true|WP_Error True if the JSON data was passed or no JSON data was provided, WP_Error if invalid JSON was passed.
655 655
 	 */
656 656
 	protected function parse_json_params() {
657
-		if ( $this->parsed_json ) {
657
+		if ($this->parsed_json) {
658 658
 			return true;
659 659
 		}
660 660
 
@@ -663,16 +663,16 @@  discard block
 block discarded – undo
663 663
 		// Check that we actually got JSON.
664 664
 		$content_type = $this->get_content_type();
665 665
 
666
-		if ( empty( $content_type ) || 'application/json' !== $content_type['value'] ) {
666
+		if (empty($content_type) || 'application/json' !== $content_type['value']) {
667 667
 			return true;
668 668
 		}
669 669
 
670 670
 		$body = $this->get_body();
671
-		if ( empty( $body ) ) {
671
+		if (empty($body)) {
672 672
 			return true;
673 673
 		}
674 674
 
675
-		$params = json_decode( $body, true );
675
+		$params = json_decode($body, true);
676 676
 
677 677
 		/*
678 678
 		 * Check for a parsing error.
@@ -680,19 +680,19 @@  discard block
 block discarded – undo
680 680
 		 * Note that due to WP's JSON compatibility functions, json_last_error
681 681
 		 * might not be defined: https://core.trac.wordpress.org/ticket/27799
682 682
 		 */
683
-		if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error() ) ) {
683
+		if (null === $params && ( ! function_exists('json_last_error') || JSON_ERROR_NONE !== json_last_error())) {
684 684
 			// Ensure subsequent calls receive error instance.
685 685
 			$this->parsed_json = false;
686 686
 
687 687
 			$error_data = array(
688 688
 				'status' => WP_Http::BAD_REQUEST,
689 689
 			);
690
-			if ( function_exists( 'json_last_error' ) ) {
690
+			if (function_exists('json_last_error')) {
691 691
 				$error_data['json_error_code'] = json_last_error();
692 692
 				$error_data['json_error_message'] = json_last_error_msg();
693 693
 			}
694 694
 
695
-			return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data );
695
+			return new WP_Error('rest_invalid_json', __('Invalid JSON body passed.'), $error_data);
696 696
 		}
697 697
 
698 698
 		$this->params['JSON'] = $params;
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 * @access protected
710 710
 	 */
711 711
 	protected function parse_body_params() {
712
-		if ( $this->parsed_body ) {
712
+		if ($this->parsed_body) {
713 713
 			return;
714 714
 		}
715 715
 
@@ -721,26 +721,26 @@  discard block
 block discarded – undo
721 721
 		 */
722 722
 		$content_type = $this->get_content_type();
723 723
 
724
-		if ( ! empty( $content_type ) && 'application/x-www-form-urlencoded' !== $content_type['value'] ) {
724
+		if ( ! empty($content_type) && 'application/x-www-form-urlencoded' !== $content_type['value']) {
725 725
 			return;
726 726
 		}
727 727
 
728
-		parse_str( $this->get_body(), $params );
728
+		parse_str($this->get_body(), $params);
729 729
 
730 730
 		/*
731 731
 		 * Amazingly, parse_str follows magic quote rules. Sigh.
732 732
 		 *
733 733
 		 * NOTE: Do not refactor to use `wp_unslash`.
734 734
 		 */
735
-		if ( get_magic_quotes_gpc() ) {
736
-			$params = stripslashes_deep( $params );
735
+		if (get_magic_quotes_gpc()) {
736
+			$params = stripslashes_deep($params);
737 737
 		}
738 738
 
739 739
 		/*
740 740
 		 * Add to the POST parameters stored internally. If a user has already
741 741
 		 * set these manually (via `set_body_params`), don't override them.
742 742
 		 */
743
-		$this->params['POST'] = array_merge( $params, $this->params['POST'] );
743
+		$this->params['POST'] = array_merge($params, $this->params['POST']);
744 744
 	}
745 745
 
746 746
 	/**
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 *
764 764
 	 * @param string $route Route matching regex.
765 765
 	 */
766
-	public function set_route( $route ) {
766
+	public function set_route($route) {
767 767
 		$this->route = $route;
768 768
 	}
769 769
 
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 	 *
790 790
 	 * @param array $attributes Attributes for the request.
791 791
 	 */
792
-	public function set_attributes( $attributes ) {
792
+	public function set_attributes($attributes) {
793 793
 		$this->attributes = $attributes;
794 794
 	}
795 795
 
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 		$attributes = $this->get_attributes();
809 809
 
810 810
 		// No arguments set, skip sanitizing.
811
-		if ( empty( $attributes['args'] ) ) {
811
+		if (empty($attributes['args'])) {
812 812
 			return true;
813 813
 		}
814 814
 
@@ -816,37 +816,37 @@  discard block
 block discarded – undo
816 816
 
817 817
 		$invalid_params = array();
818 818
 
819
-		foreach ( $order as $type ) {
820
-			if ( empty( $this->params[ $type ] ) ) {
819
+		foreach ($order as $type) {
820
+			if (empty($this->params[$type])) {
821 821
 				continue;
822 822
 			}
823
-			foreach ( $this->params[ $type ] as $key => $value ) {
824
-				if ( ! isset( $attributes['args'][ $key ] ) ) {
823
+			foreach ($this->params[$type] as $key => $value) {
824
+				if ( ! isset($attributes['args'][$key])) {
825 825
 					continue;
826 826
 				}
827
-				$param_args = $attributes['args'][ $key ];
827
+				$param_args = $attributes['args'][$key];
828 828
 
829 829
 				// If the arg has a type but no sanitize_callback attribute, default to rest_parse_request_arg.
830
-				if ( ! array_key_exists( 'sanitize_callback', $param_args ) && ! empty( $param_args['type'] ) ) {
830
+				if ( ! array_key_exists('sanitize_callback', $param_args) && ! empty($param_args['type'])) {
831 831
 					$param_args['sanitize_callback'] = 'rest_parse_request_arg';
832 832
 				}
833 833
 				// If there's still no sanitize_callback, nothing to do here.
834
-				if ( empty( $param_args['sanitize_callback'] ) ) {
834
+				if (empty($param_args['sanitize_callback'])) {
835 835
 					continue;
836 836
 				}
837 837
 
838
-				$sanitized_value = call_user_func( $param_args['sanitize_callback'], $value, $this, $key );
838
+				$sanitized_value = call_user_func($param_args['sanitize_callback'], $value, $this, $key);
839 839
 
840
-				if ( is_wp_error( $sanitized_value ) ) {
841
-					$invalid_params[ $key ] = $sanitized_value->get_error_message();
840
+				if (is_wp_error($sanitized_value)) {
841
+					$invalid_params[$key] = $sanitized_value->get_error_message();
842 842
 				} else {
843
-					$this->params[ $type ][ $key ] = $sanitized_value;
843
+					$this->params[$type][$key] = $sanitized_value;
844 844
 				}
845 845
 			}
846 846
 		}
847 847
 
848
-		if ( $invalid_params ) {
849
-			return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
848
+		if ($invalid_params) {
849
+			return new WP_Error('rest_invalid_param', sprintf(__('Invalid parameter(s): %s'), implode(', ', array_keys($invalid_params))), array('status' => 400, 'params' => $invalid_params));
850 850
 		}
851 851
 
852 852
 		return true;
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 	public function has_valid_params() {
865 865
 		// If JSON data was passed, check for errors.
866 866
 		$json_error = $this->parse_json_params();
867
-		if ( is_wp_error( $json_error ) ) {
867
+		if (is_wp_error($json_error)) {
868 868
 			return $json_error;
869 869
 		}
870 870
 
@@ -872,20 +872,20 @@  discard block
 block discarded – undo
872 872
 		$required = array();
873 873
 
874 874
 		// No arguments set, skip validation.
875
-		if ( empty( $attributes['args'] ) ) {
875
+		if (empty($attributes['args'])) {
876 876
 			return true;
877 877
 		}
878 878
 
879
-		foreach ( $attributes['args'] as $key => $arg ) {
879
+		foreach ($attributes['args'] as $key => $arg) {
880 880
 
881
-			$param = $this->get_param( $key );
882
-			if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) {
881
+			$param = $this->get_param($key);
882
+			if (isset($arg['required']) && true === $arg['required'] && null === $param) {
883 883
 				$required[] = $key;
884 884
 			}
885 885
 		}
886 886
 
887
-		if ( ! empty( $required ) ) {
888
-			return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) );
887
+		if ( ! empty($required)) {
888
+			return new WP_Error('rest_missing_callback_param', sprintf(__('Missing parameter(s): %s'), implode(', ', $required)), array('status' => 400, 'params' => $required));
889 889
 		}
890 890
 
891 891
 		/*
@@ -895,25 +895,25 @@  discard block
 block discarded – undo
895 895
 		 */
896 896
 		$invalid_params = array();
897 897
 
898
-		foreach ( $attributes['args'] as $key => $arg ) {
898
+		foreach ($attributes['args'] as $key => $arg) {
899 899
 
900
-			$param = $this->get_param( $key );
900
+			$param = $this->get_param($key);
901 901
 
902
-			if ( null !== $param && ! empty( $arg['validate_callback'] ) ) {
903
-				$valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key );
902
+			if (null !== $param && ! empty($arg['validate_callback'])) {
903
+				$valid_check = call_user_func($arg['validate_callback'], $param, $this, $key);
904 904
 
905
-				if ( false === $valid_check ) {
906
-					$invalid_params[ $key ] = __( 'Invalid parameter.' );
905
+				if (false === $valid_check) {
906
+					$invalid_params[$key] = __('Invalid parameter.');
907 907
 				}
908 908
 
909
-				if ( is_wp_error( $valid_check ) ) {
910
-					$invalid_params[ $key ] = $valid_check->get_error_message();
909
+				if (is_wp_error($valid_check)) {
910
+					$invalid_params[$key] = $valid_check->get_error_message();
911 911
 				}
912 912
 			}
913 913
 		}
914 914
 
915
-		if ( $invalid_params ) {
916
-			return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
915
+		if ($invalid_params) {
916
+			return new WP_Error('rest_invalid_param', sprintf(__('Invalid parameter(s): %s'), implode(', ', array_keys($invalid_params))), array('status' => 400, 'params' => $invalid_params));
917 917
 		}
918 918
 
919 919
 		return true;
@@ -929,11 +929,11 @@  discard block
 block discarded – undo
929 929
 	 * @param string $offset Parameter name.
930 930
 	 * @return bool Whether the parameter is set.
931 931
 	 */
932
-	public function offsetExists( $offset ) {
932
+	public function offsetExists($offset) {
933 933
 		$order = $this->get_parameter_order();
934 934
 
935
-		foreach ( $order as $type ) {
936
-			if ( isset( $this->params[ $type ][ $offset ] ) ) {
935
+		foreach ($order as $type) {
936
+			if (isset($this->params[$type][$offset])) {
937 937
 				return true;
938 938
 			}
939 939
 		}
@@ -950,8 +950,8 @@  discard block
 block discarded – undo
950 950
 	 * @param string $offset Parameter name.
951 951
 	 * @return mixed|null Value if set, null otherwise.
952 952
 	 */
953
-	public function offsetGet( $offset ) {
954
-		return $this->get_param( $offset );
953
+	public function offsetGet($offset) {
954
+		return $this->get_param($offset);
955 955
 	}
956 956
 
957 957
 	/**
@@ -963,8 +963,8 @@  discard block
 block discarded – undo
963 963
 	 * @param string $offset Parameter name.
964 964
 	 * @param mixed  $value  Parameter value.
965 965
 	 */
966
-	public function offsetSet( $offset, $value ) {
967
-		$this->set_param( $offset, $value );
966
+	public function offsetSet($offset, $value) {
967
+		$this->set_param($offset, $value);
968 968
 	}
969 969
 
970 970
 	/**
@@ -975,12 +975,12 @@  discard block
 block discarded – undo
975 975
 	 *
976 976
 	 * @param string $offset Parameter name.
977 977
 	 */
978
-	public function offsetUnset( $offset ) {
978
+	public function offsetUnset($offset) {
979 979
 		$order = $this->get_parameter_order();
980 980
 
981 981
 		// Remove the offset from every group.
982
-		foreach ( $order as $type ) {
983
-			unset( $this->params[ $type ][ $offset ] );
982
+		foreach ($order as $type) {
983
+			unset($this->params[$type][$offset]);
984 984
 		}
985 985
 	}
986 986
 
@@ -994,29 +994,29 @@  discard block
 block discarded – undo
994 994
 	 * @param string $url URL with protocol, domain, path and query args.
995 995
 	 * @return WP_REST_Request|false WP_REST_Request object on success, false on failure.
996 996
 	 */
997
-	public static function from_url( $url ) {
998
-		$bits = parse_url( $url );
997
+	public static function from_url($url) {
998
+		$bits = parse_url($url);
999 999
 		$query_params = array();
1000 1000
 
1001
-		if ( ! empty( $bits['query'] ) ) {
1002
-			wp_parse_str( $bits['query'], $query_params );
1001
+		if ( ! empty($bits['query'])) {
1002
+			wp_parse_str($bits['query'], $query_params);
1003 1003
 		}
1004 1004
 
1005 1005
 		$api_root = rest_url();
1006
-		if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) {
1006
+		if (get_option('permalink_structure') && 0 === strpos($url, $api_root)) {
1007 1007
 			// Pretty permalinks on, and URL is under the API root.
1008
-			$api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) );
1009
-			$route = parse_url( $api_url_part, PHP_URL_PATH );
1010
-		} elseif ( ! empty( $query_params['rest_route'] ) ) {
1008
+			$api_url_part = substr($url, strlen(untrailingslashit($api_root)));
1009
+			$route = parse_url($api_url_part, PHP_URL_PATH);
1010
+		} elseif ( ! empty($query_params['rest_route'])) {
1011 1011
 			// ?rest_route=... set directly
1012 1012
 			$route = $query_params['rest_route'];
1013
-			unset( $query_params['rest_route'] );
1013
+			unset($query_params['rest_route']);
1014 1014
 		}
1015 1015
 
1016 1016
 		$request = false;
1017
-		if ( ! empty( $route ) ) {
1018
-			$request = new WP_REST_Request( 'GET', $route );
1019
-			$request->set_query_params( $query_params );
1017
+		if ( ! empty($route)) {
1018
+			$request = new WP_REST_Request('GET', $route);
1019
+			$request->set_query_params($query_params);
1020 1020
 		}
1021 1021
 
1022 1022
 		/**
@@ -1028,6 +1028,6 @@  discard block
 block discarded – undo
1028 1028
 		 *                                       could not be parsed.
1029 1029
 		 * @param string                $url     URL the request was generated from.
1030 1030
 		 */
1031
-		return apply_filters( 'rest_request_from_url', $request, $url );
1031
+		return apply_filters('rest_request_from_url', $request, $url);
1032 1032
 	}
1033 1033
 }
Please login to merge, or discard this patch.
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	 * @access public
249 249
 	 *
250 250
 	 * @param WP_REST_Request $request Request object.
251
-	 * @return WP_Error|stdClass $prepared_attachment Post object.
251
+	 * @return string $prepared_attachment Post object.
252 252
 	 */
253 253
 	protected function prepare_item_for_database( $request ) {
254 254
 		$prepared_attachment = parent::prepare_item_for_database( $request );
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 	 * @since 4.7.0
484 484
 	 * @access protected
485 485
 	 *
486
-	 * @param array $data    Supplied file data.
486
+	 * @param string $data    Supplied file data.
487 487
 	 * @param array $headers HTTP headers from the request.
488 488
 	 * @return array|WP_Error Data from wp_handle_sideload().
489 489
 	 */
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -27,29 +27,29 @@  discard block
 block discarded – undo
27 27
 	 * @param WP_REST_Request $request       Optional. Request to prepare items for.
28 28
 	 * @return array Array of query arguments.
29 29
 	 */
30
-	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
31
-		$query_args = parent::prepare_items_query( $prepared_args, $request );
30
+	protected function prepare_items_query($prepared_args = array(), $request = null) {
31
+		$query_args = parent::prepare_items_query($prepared_args, $request);
32 32
 
33
-		if ( empty( $query_args['post_status'] ) ) {
33
+		if (empty($query_args['post_status'])) {
34 34
 			$query_args['post_status'] = 'inherit';
35 35
 		}
36 36
 
37 37
 		$media_types = $this->get_media_types();
38 38
 
39
-		if ( ! empty( $request['media_type'] ) && isset( $media_types[ $request['media_type'] ] ) ) {
40
-			$query_args['post_mime_type'] = $media_types[ $request['media_type'] ];
39
+		if ( ! empty($request['media_type']) && isset($media_types[$request['media_type']])) {
40
+			$query_args['post_mime_type'] = $media_types[$request['media_type']];
41 41
 		}
42 42
 
43
-		if ( ! empty( $request['mime_type'] ) ) {
44
-			$parts = explode( '/', $request['mime_type'] );
45
-			if ( isset( $media_types[ $parts[0] ] ) && in_array( $request['mime_type'], $media_types[ $parts[0] ], true ) ) {
43
+		if ( ! empty($request['mime_type'])) {
44
+			$parts = explode('/', $request['mime_type']);
45
+			if (isset($media_types[$parts[0]]) && in_array($request['mime_type'], $media_types[$parts[0]], true)) {
46 46
 				$query_args['post_mime_type'] = $request['mime_type'];
47 47
 			}
48 48
 		}
49 49
 
50 50
 		// Filter query clauses to include filenames.
51
-		if ( isset( $query_args['s'] ) ) {
52
-			add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
51
+		if (isset($query_args['s'])) {
52
+			add_filter('posts_clauses', '_filter_query_attachment_filenames');
53 53
 		}
54 54
 
55 55
 		return $query_args;
@@ -64,24 +64,24 @@  discard block
 block discarded – undo
64 64
 	 * @param WP_REST_Request $request Full details about the request.
65 65
 	 * @return WP_Error|true Boolean true if the attachment may be created, or a WP_Error if not.
66 66
 	 */
67
-	public function create_item_permissions_check( $request ) {
68
-		$ret = parent::create_item_permissions_check( $request );
67
+	public function create_item_permissions_check($request) {
68
+		$ret = parent::create_item_permissions_check($request);
69 69
 
70
-		if ( ! $ret || is_wp_error( $ret ) ) {
70
+		if ( ! $ret || is_wp_error($ret)) {
71 71
 			return $ret;
72 72
 		}
73 73
 
74
-		if ( ! current_user_can( 'upload_files' ) ) {
75
-			return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) );
74
+		if ( ! current_user_can('upload_files')) {
75
+			return new WP_Error('rest_cannot_create', __('Sorry, you are not allowed to upload media on this site.'), array('status' => 400));
76 76
 		}
77 77
 
78 78
 		// Attaching media to a post requires ability to edit said post.
79
-		if ( ! empty( $request['post'] ) ) {
80
-			$parent = get_post( (int) $request['post'] );
81
-			$post_parent_type = get_post_type_object( $parent->post_type );
79
+		if ( ! empty($request['post'])) {
80
+			$parent = get_post((int) $request['post']);
81
+			$post_parent_type = get_post_type_object($parent->post_type);
82 82
 
83
-			if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) {
84
-				return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) );
83
+			if ( ! current_user_can($post_parent_type->cap->edit_post, $request['post'])) {
84
+				return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to upload media to this post.'), array('status' => rest_authorization_required_code()));
85 85
 			}
86 86
 		}
87 87
 
@@ -97,68 +97,68 @@  discard block
 block discarded – undo
97 97
 	 * @param WP_REST_Request $request Full details about the request.
98 98
 	 * @return WP_Error|WP_REST_Response Response object on success, WP_Error object on failure.
99 99
 	 */
100
-	public function create_item( $request ) {
100
+	public function create_item($request) {
101 101
 
102
-		if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
103
-			return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
102
+		if ( ! empty($request['post']) && in_array(get_post_type($request['post']), array('revision', 'attachment'), true)) {
103
+			return new WP_Error('rest_invalid_param', __('Invalid parent type.'), array('status' => 400));
104 104
 		}
105 105
 
106 106
 		// Get the file via $_FILES or raw data.
107 107
 		$files = $request->get_file_params();
108 108
 		$headers = $request->get_headers();
109 109
 
110
-		if ( ! empty( $files ) ) {
111
-			$file = $this->upload_from_file( $files, $headers );
110
+		if ( ! empty($files)) {
111
+			$file = $this->upload_from_file($files, $headers);
112 112
 		} else {
113
-			$file = $this->upload_from_data( $request->get_body(), $headers );
113
+			$file = $this->upload_from_data($request->get_body(), $headers);
114 114
 		}
115 115
 
116
-		if ( is_wp_error( $file ) ) {
116
+		if (is_wp_error($file)) {
117 117
 			return $file;
118 118
 		}
119 119
 
120
-		$name       = basename( $file['file'] );
121
-		$name_parts = pathinfo( $name );
122
-		$name       = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) );
120
+		$name       = basename($file['file']);
121
+		$name_parts = pathinfo($name);
122
+		$name       = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
123 123
 
124 124
 		$url     = $file['url'];
125 125
 		$type    = $file['type'];
126 126
 		$file    = $file['file'];
127 127
 
128 128
 		// use image exif/iptc data for title and caption defaults if possible
129
-		$image_meta = @wp_read_image_metadata( $file );
129
+		$image_meta = @wp_read_image_metadata($file);
130 130
 
131
-		if ( ! empty( $image_meta ) ) {
132
-			if ( empty( $request['title'] ) && trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
131
+		if ( ! empty($image_meta)) {
132
+			if (empty($request['title']) && trim($image_meta['title']) && ! is_numeric(sanitize_title($image_meta['title']))) {
133 133
 				$request['title'] = $image_meta['title'];
134 134
 			}
135 135
 
136
-			if ( empty( $request['caption'] ) && trim( $image_meta['caption'] ) ) {
136
+			if (empty($request['caption']) && trim($image_meta['caption'])) {
137 137
 				$request['caption'] = $image_meta['caption'];
138 138
 			}
139 139
 		}
140 140
 
141
-		$attachment = $this->prepare_item_for_database( $request );
141
+		$attachment = $this->prepare_item_for_database($request);
142 142
 		$attachment->file = $file;
143 143
 		$attachment->post_mime_type = $type;
144 144
 		$attachment->guid = $url;
145 145
 
146
-		if ( empty( $attachment->post_title ) ) {
147
-			$attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
146
+		if (empty($attachment->post_title)) {
147
+			$attachment->post_title = preg_replace('/\.[^.]+$/', '', basename($file));
148 148
 		}
149 149
 
150
-		$id = wp_insert_post( wp_slash( (array) $attachment ), true );
150
+		$id = wp_insert_post(wp_slash((array) $attachment), true);
151 151
 
152
-		if ( is_wp_error( $id ) ) {
153
-			if ( 'db_update_error' === $id->get_error_code() ) {
154
-				$id->add_data( array( 'status' => 500 ) );
152
+		if (is_wp_error($id)) {
153
+			if ('db_update_error' === $id->get_error_code()) {
154
+				$id->add_data(array('status' => 500));
155 155
 			} else {
156
-				$id->add_data( array( 'status' => 400 ) );
156
+				$id->add_data(array('status' => 400));
157 157
 			}
158 158
 			return $id;
159 159
 		}
160 160
 
161
-		$attachment = get_post( $id );
161
+		$attachment = get_post($id);
162 162
 
163 163
 		/**
164 164
 		 * Fires after a single attachment is created or updated via the REST API.
@@ -170,28 +170,28 @@  discard block
 block discarded – undo
170 170
 		 * @param WP_REST_Request $request    The request sent to the API.
171 171
 		 * @param bool            $creating   True when creating an attachment, false when updating.
172 172
 		 */
173
-		do_action( 'rest_insert_attachment', $attachment, $request, true );
173
+		do_action('rest_insert_attachment', $attachment, $request, true);
174 174
 
175 175
 		// Include admin functions to get access to wp_generate_attachment_metadata().
176
-		require_once ABSPATH . 'wp-admin/includes/admin.php';
176
+		require_once ABSPATH.'wp-admin/includes/admin.php';
177 177
 
178
-		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
178
+		wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
179 179
 
180
-		if ( isset( $request['alt_text'] ) ) {
181
-			update_post_meta( $id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) );
180
+		if (isset($request['alt_text'])) {
181
+			update_post_meta($id, '_wp_attachment_image_alt', sanitize_text_field($request['alt_text']));
182 182
 		}
183 183
 
184
-		$fields_update = $this->update_additional_fields_for_object( $attachment, $request );
184
+		$fields_update = $this->update_additional_fields_for_object($attachment, $request);
185 185
 
186
-		if ( is_wp_error( $fields_update ) ) {
186
+		if (is_wp_error($fields_update)) {
187 187
 			return $fields_update;
188 188
 		}
189 189
 
190
-		$request->set_param( 'context', 'edit' );
191
-		$response = $this->prepare_item_for_response( $attachment, $request );
192
-		$response = rest_ensure_response( $response );
193
-		$response->set_status( 201 );
194
-		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ) );
190
+		$request->set_param('context', 'edit');
191
+		$response = $this->prepare_item_for_response($attachment, $request);
192
+		$response = rest_ensure_response($response);
193
+		$response->set_status(201);
194
+		$response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $id)));
195 195
 
196 196
 		return $response;
197 197
 	}
@@ -205,38 +205,38 @@  discard block
 block discarded – undo
205 205
 	 * @param WP_REST_Request $request Full details about the request.
206 206
 	 * @return WP_Error|WP_REST_Response Response object on success, WP_Error object on failure.
207 207
 	 */
208
-	public function update_item( $request ) {
209
-		if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
210
-			return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
208
+	public function update_item($request) {
209
+		if ( ! empty($request['post']) && in_array(get_post_type($request['post']), array('revision', 'attachment'), true)) {
210
+			return new WP_Error('rest_invalid_param', __('Invalid parent type.'), array('status' => 400));
211 211
 		}
212 212
 
213
-		$response = parent::update_item( $request );
213
+		$response = parent::update_item($request);
214 214
 
215
-		if ( is_wp_error( $response ) ) {
215
+		if (is_wp_error($response)) {
216 216
 			return $response;
217 217
 		}
218 218
 
219
-		$response = rest_ensure_response( $response );
219
+		$response = rest_ensure_response($response);
220 220
 		$data = $response->get_data();
221 221
 
222
-		if ( isset( $request['alt_text'] ) ) {
223
-			update_post_meta( $data['id'], '_wp_attachment_image_alt', $request['alt_text'] );
222
+		if (isset($request['alt_text'])) {
223
+			update_post_meta($data['id'], '_wp_attachment_image_alt', $request['alt_text']);
224 224
 		}
225 225
 
226
-		$attachment = get_post( $request['id'] );
226
+		$attachment = get_post($request['id']);
227 227
 
228 228
 		/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
229
-		do_action( 'rest_insert_attachment', $data, $request, false );
229
+		do_action('rest_insert_attachment', $data, $request, false);
230 230
 
231
-		$fields_update = $this->update_additional_fields_for_object( $attachment, $request );
231
+		$fields_update = $this->update_additional_fields_for_object($attachment, $request);
232 232
 
233
-		if ( is_wp_error( $fields_update ) ) {
233
+		if (is_wp_error($fields_update)) {
234 234
 			return $fields_update;
235 235
 		}
236 236
 
237
-		$request->set_param( 'context', 'edit' );
238
-		$response = $this->prepare_item_for_response( $attachment, $request );
239
-		$response = rest_ensure_response( $response );
237
+		$request->set_param('context', 'edit');
238
+		$response = $this->prepare_item_for_response($attachment, $request);
239
+		$response = rest_ensure_response($response);
240 240
 
241 241
 		return $response;
242 242
 	}
@@ -250,28 +250,28 @@  discard block
 block discarded – undo
250 250
 	 * @param WP_REST_Request $request Request object.
251 251
 	 * @return WP_Error|stdClass $prepared_attachment Post object.
252 252
 	 */
253
-	protected function prepare_item_for_database( $request ) {
254
-		$prepared_attachment = parent::prepare_item_for_database( $request );
253
+	protected function prepare_item_for_database($request) {
254
+		$prepared_attachment = parent::prepare_item_for_database($request);
255 255
 
256 256
 		// Attachment caption (post_excerpt internally)
257
-		if ( isset( $request['caption'] ) ) {
258
-			if ( is_string( $request['caption'] ) ) {
257
+		if (isset($request['caption'])) {
258
+			if (is_string($request['caption'])) {
259 259
 				$prepared_attachment->post_excerpt = $request['caption'];
260
-			} elseif ( isset( $request['caption']['raw'] ) ) {
260
+			} elseif (isset($request['caption']['raw'])) {
261 261
 				$prepared_attachment->post_excerpt = $request['caption']['raw'];
262 262
 			}
263 263
 		}
264 264
 
265 265
 		// Attachment description (post_content internally)
266
-		if ( isset( $request['description'] ) ) {
267
-			if ( is_string( $request['description'] ) ) {
266
+		if (isset($request['description'])) {
267
+			if (is_string($request['description'])) {
268 268
 				$prepared_attachment->post_content = $request['description'];
269
-			} elseif ( isset( $request['description']['raw'] ) ) {
269
+			} elseif (isset($request['description']['raw'])) {
270 270
 				$prepared_attachment->post_content = $request['description']['raw'];
271 271
 			}
272 272
 		}
273 273
 
274
-		if ( isset( $request['post'] ) ) {
274
+		if (isset($request['post'])) {
275 275
 			$prepared_attachment->post_parent = (int) $request['post'];
276 276
 		}
277 277
 
@@ -288,56 +288,56 @@  discard block
 block discarded – undo
288 288
 	 * @param WP_REST_Request $request Request object.
289 289
 	 * @return WP_REST_Response Response object.
290 290
 	 */
291
-	public function prepare_item_for_response( $post, $request ) {
292
-		$response = parent::prepare_item_for_response( $post, $request );
291
+	public function prepare_item_for_response($post, $request) {
292
+		$response = parent::prepare_item_for_response($post, $request);
293 293
 		$data = $response->get_data();
294 294
 
295 295
 		$data['description'] = array(
296 296
 			'raw'       => $post->post_content,
297 297
 			/** This filter is documented in wp-includes/post-template.php */
298
-			'rendered'  => apply_filters( 'the_content', $post->post_content ),
298
+			'rendered'  => apply_filters('the_content', $post->post_content),
299 299
 		);
300 300
 
301 301
 		/** This filter is documented in wp-includes/post-template.php */
302
-		$caption = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
302
+		$caption = apply_filters('the_excerpt', apply_filters('get_the_excerpt', $post->post_excerpt, $post));
303 303
 		$data['caption'] = array(
304 304
 			'raw'       => $post->post_excerpt,
305 305
 			'rendered'  => $caption,
306 306
 		);
307 307
 
308
-		$data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
309
-		$data['media_type']    = wp_attachment_is_image( $post->ID ) ? 'image' : 'file';
308
+		$data['alt_text']      = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
309
+		$data['media_type']    = wp_attachment_is_image($post->ID) ? 'image' : 'file';
310 310
 		$data['mime_type']     = $post->post_mime_type;
311
-		$data['media_details'] = wp_get_attachment_metadata( $post->ID );
312
-		$data['post']          = ! empty( $post->post_parent ) ? (int) $post->post_parent : null;
313
-		$data['source_url']    = wp_get_attachment_url( $post->ID );
311
+		$data['media_details'] = wp_get_attachment_metadata($post->ID);
312
+		$data['post']          = ! empty($post->post_parent) ? (int) $post->post_parent : null;
313
+		$data['source_url']    = wp_get_attachment_url($post->ID);
314 314
 
315 315
 		// Ensure empty details is an empty object.
316
-		if ( empty( $data['media_details'] ) ) {
316
+		if (empty($data['media_details'])) {
317 317
 			$data['media_details'] = new stdClass;
318
-		} elseif ( ! empty( $data['media_details']['sizes'] ) ) {
318
+		} elseif ( ! empty($data['media_details']['sizes'])) {
319 319
 
320
-			foreach ( $data['media_details']['sizes'] as $size => &$size_data ) {
320
+			foreach ($data['media_details']['sizes'] as $size => &$size_data) {
321 321
 
322
-				if ( isset( $size_data['mime-type'] ) ) {
322
+				if (isset($size_data['mime-type'])) {
323 323
 					$size_data['mime_type'] = $size_data['mime-type'];
324
-					unset( $size_data['mime-type'] );
324
+					unset($size_data['mime-type']);
325 325
 				}
326 326
 
327 327
 				// Use the same method image_downsize() does.
328
-				$image_src = wp_get_attachment_image_src( $post->ID, $size );
329
-				if ( ! $image_src ) {
328
+				$image_src = wp_get_attachment_image_src($post->ID, $size);
329
+				if ( ! $image_src) {
330 330
 					continue;
331 331
 				}
332 332
 
333 333
 				$size_data['source_url'] = $image_src[0];
334 334
 			}
335 335
 
336
-			$full_src = wp_get_attachment_image_src( $post->ID, 'full' );
336
+			$full_src = wp_get_attachment_image_src($post->ID, 'full');
337 337
 
338
-			if ( ! empty( $full_src ) ) {
338
+			if ( ! empty($full_src)) {
339 339
 				$data['media_details']['sizes']['full'] = array(
340
-					'file'       => wp_basename( $full_src[0] ),
340
+					'file'       => wp_basename($full_src[0]),
341 341
 					'width'      => $full_src[1],
342 342
 					'height'     => $full_src[2],
343 343
 					'mime_type'  => $post->post_mime_type,
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
 			$data['media_details']['sizes'] = new stdClass;
349 349
 		}
350 350
 
351
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
351
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
352 352
 
353
-		$data = $this->filter_response_by_context( $data, $context );
353
+		$data = $this->filter_response_by_context($data, $context);
354 354
 
355 355
 		// Wrap the data in a response object.
356
-		$response = rest_ensure_response( $data );
356
+		$response = rest_ensure_response($data);
357 357
 
358
-		$response->add_links( $this->prepare_links( $post ) );
358
+		$response->add_links($this->prepare_links($post));
359 359
 
360 360
 		/**
361 361
 		 * Filters an attachment returned from the REST API.
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 		 * @param WP_Post          $post     The original attachment post.
369 369
 		 * @param WP_REST_Request  $request  Request used to generate the response.
370 370
 		 */
371
-		return apply_filters( 'rest_prepare_attachment', $response, $post, $request );
371
+		return apply_filters('rest_prepare_attachment', $response, $post, $request);
372 372
 	}
373 373
 
374 374
 	/**
@@ -384,95 +384,95 @@  discard block
 block discarded – undo
384 384
 		$schema = parent::get_item_schema();
385 385
 
386 386
 		$schema['properties']['alt_text'] = array(
387
-			'description'     => __( 'Alternative text to display when attachment is not displayed.' ),
387
+			'description'     => __('Alternative text to display when attachment is not displayed.'),
388 388
 			'type'            => 'string',
389
-			'context'         => array( 'view', 'edit', 'embed' ),
389
+			'context'         => array('view', 'edit', 'embed'),
390 390
 			'arg_options'     => array(
391 391
 				'sanitize_callback' => 'sanitize_text_field',
392 392
 			),
393 393
 		);
394 394
 
395 395
 		$schema['properties']['caption'] = array(
396
-			'description' => __( 'The attachment caption.' ),
396
+			'description' => __('The attachment caption.'),
397 397
 			'type'        => 'object',
398
-			'context'     => array( 'view', 'edit', 'embed' ),
398
+			'context'     => array('view', 'edit', 'embed'),
399 399
 			'arg_options' => array(
400 400
 				'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
401 401
 			),
402 402
 			'properties'  => array(
403 403
 				'raw' => array(
404
-					'description' => __( 'Caption for the attachment, as it exists in the database.' ),
404
+					'description' => __('Caption for the attachment, as it exists in the database.'),
405 405
 					'type'        => 'string',
406
-					'context'     => array( 'edit' ),
406
+					'context'     => array('edit'),
407 407
 				),
408 408
 				'rendered' => array(
409
-					'description' => __( 'HTML caption for the attachment, transformed for display.' ),
409
+					'description' => __('HTML caption for the attachment, transformed for display.'),
410 410
 					'type'        => 'string',
411
-					'context'     => array( 'view', 'edit', 'embed' ),
411
+					'context'     => array('view', 'edit', 'embed'),
412 412
 					'readonly'    => true,
413 413
 				),
414 414
 			),
415 415
 		);
416 416
 
417 417
 		$schema['properties']['description'] = array(
418
-			'description' => __( 'The attachment description.' ),
418
+			'description' => __('The attachment description.'),
419 419
 			'type'        => 'object',
420
-			'context'     => array( 'view', 'edit' ),
420
+			'context'     => array('view', 'edit'),
421 421
 			'arg_options' => array(
422 422
 				'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
423 423
 			),
424 424
 			'properties'  => array(
425 425
 				'raw' => array(
426
-					'description' => __( 'Description for the object, as it exists in the database.' ),
426
+					'description' => __('Description for the object, as it exists in the database.'),
427 427
 					'type'        => 'string',
428
-					'context'     => array( 'edit' ),
428
+					'context'     => array('edit'),
429 429
 				),
430 430
 				'rendered' => array(
431
-					'description' => __( 'HTML description for the object, transformed for display.' ),
431
+					'description' => __('HTML description for the object, transformed for display.'),
432 432
 					'type'        => 'string',
433
-					'context'     => array( 'view', 'edit' ),
433
+					'context'     => array('view', 'edit'),
434 434
 					'readonly'    => true,
435 435
 				),
436 436
 			),
437 437
 		);
438 438
 
439 439
 		$schema['properties']['media_type'] = array(
440
-			'description'     => __( 'Attachment type.' ),
440
+			'description'     => __('Attachment type.'),
441 441
 			'type'            => 'string',
442
-			'enum'            => array( 'image', 'file' ),
443
-			'context'         => array( 'view', 'edit', 'embed' ),
442
+			'enum'            => array('image', 'file'),
443
+			'context'         => array('view', 'edit', 'embed'),
444 444
 			'readonly'        => true,
445 445
 		);
446 446
 
447 447
 		$schema['properties']['mime_type'] = array(
448
-			'description'     => __( 'The attachment MIME type.' ),
448
+			'description'     => __('The attachment MIME type.'),
449 449
 			'type'            => 'string',
450
-			'context'         => array( 'view', 'edit', 'embed' ),
450
+			'context'         => array('view', 'edit', 'embed'),
451 451
 			'readonly'        => true,
452 452
 		);
453 453
 
454 454
 		$schema['properties']['media_details'] = array(
455
-			'description'     => __( 'Details about the media file, specific to its type.' ),
455
+			'description'     => __('Details about the media file, specific to its type.'),
456 456
 			'type'            => 'object',
457
-			'context'         => array( 'view', 'edit', 'embed' ),
457
+			'context'         => array('view', 'edit', 'embed'),
458 458
 			'readonly'        => true,
459 459
 		);
460 460
 
461 461
 		$schema['properties']['post'] = array(
462
-			'description'     => __( 'The ID for the associated post of the attachment.' ),
462
+			'description'     => __('The ID for the associated post of the attachment.'),
463 463
 			'type'            => 'integer',
464
-			'context'         => array( 'view', 'edit' ),
464
+			'context'         => array('view', 'edit'),
465 465
 		);
466 466
 
467 467
 		$schema['properties']['source_url'] = array(
468
-			'description'     => __( 'URL to the original attachment file.' ),
468
+			'description'     => __('URL to the original attachment file.'),
469 469
 			'type'            => 'string',
470 470
 			'format'          => 'uri',
471
-			'context'         => array( 'view', 'edit', 'embed' ),
471
+			'context'         => array('view', 'edit', 'embed'),
472 472
 			'readonly'        => true,
473 473
 		);
474 474
 
475
-		unset( $schema['properties']['password'] );
475
+		unset($schema['properties']['password']);
476 476
 
477 477
 		return $schema;
478 478
 	}
@@ -487,52 +487,52 @@  discard block
 block discarded – undo
487 487
 	 * @param array $headers HTTP headers from the request.
488 488
 	 * @return array|WP_Error Data from wp_handle_sideload().
489 489
 	 */
490
-	protected function upload_from_data( $data, $headers ) {
491
-		if ( empty( $data ) ) {
492
-			return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) );
490
+	protected function upload_from_data($data, $headers) {
491
+		if (empty($data)) {
492
+			return new WP_Error('rest_upload_no_data', __('No data supplied.'), array('status' => 400));
493 493
 		}
494 494
 
495
-		if ( empty( $headers['content_type'] ) ) {
496
-			return new WP_Error( 'rest_upload_no_content_type', __( 'No Content-Type supplied.' ), array( 'status' => 400 ) );
495
+		if (empty($headers['content_type'])) {
496
+			return new WP_Error('rest_upload_no_content_type', __('No Content-Type supplied.'), array('status' => 400));
497 497
 		}
498 498
 
499
-		if ( empty( $headers['content_disposition'] ) ) {
500
-			return new WP_Error( 'rest_upload_no_content_disposition', __( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) );
499
+		if (empty($headers['content_disposition'])) {
500
+			return new WP_Error('rest_upload_no_content_disposition', __('No Content-Disposition supplied.'), array('status' => 400));
501 501
 		}
502 502
 
503
-		$filename = self::get_filename_from_disposition( $headers['content_disposition'] );
503
+		$filename = self::get_filename_from_disposition($headers['content_disposition']);
504 504
 
505
-		if ( empty( $filename ) ) {
506
-			return new WP_Error( 'rest_upload_invalid_disposition', __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), array( 'status' => 400 ) );
505
+		if (empty($filename)) {
506
+			return new WP_Error('rest_upload_invalid_disposition', __('Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.'), array('status' => 400));
507 507
 		}
508 508
 
509
-		if ( ! empty( $headers['content_md5'] ) ) {
510
-			$content_md5 = array_shift( $headers['content_md5'] );
511
-			$expected    = trim( $content_md5 );
512
-			$actual      = md5( $data );
509
+		if ( ! empty($headers['content_md5'])) {
510
+			$content_md5 = array_shift($headers['content_md5']);
511
+			$expected    = trim($content_md5);
512
+			$actual      = md5($data);
513 513
 
514
-			if ( $expected !== $actual ) {
515
-				return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) );
514
+			if ($expected !== $actual) {
515
+				return new WP_Error('rest_upload_hash_mismatch', __('Content hash did not match expected.'), array('status' => 412));
516 516
 			}
517 517
 		}
518 518
 
519 519
 		// Get the content-type.
520
-		$type = array_shift( $headers['content_type'] );
520
+		$type = array_shift($headers['content_type']);
521 521
 
522 522
 		/** Include admin functions to get access to wp_tempnam() and wp_handle_sideload() */
523
-		require_once ABSPATH . 'wp-admin/includes/admin.php';
523
+		require_once ABSPATH.'wp-admin/includes/admin.php';
524 524
 
525 525
 		// Save the file.
526
-		$tmpfname = wp_tempnam( $filename );
526
+		$tmpfname = wp_tempnam($filename);
527 527
 
528
-		$fp = fopen( $tmpfname, 'w+' );
528
+		$fp = fopen($tmpfname, 'w+');
529 529
 
530
-		if ( ! $fp ) {
531
-			return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) );
530
+		if ( ! $fp) {
531
+			return new WP_Error('rest_upload_file_error', __('Could not open file handle.'), array('status' => 500));
532 532
 		}
533 533
 
534
-		fwrite( $fp, $data );
535
-		fclose( $fp );
534
+		fwrite($fp, $data);
535
+		fclose($fp);
536 536
 
537 537
 		// Now, sideload it in.
538 538
 		$file_data = array(
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
 			'test_form' => false,
547 547
 		);
548 548
 
549
-		$sideloaded = wp_handle_sideload( $file_data, $overrides );
549
+		$sideloaded = wp_handle_sideload($file_data, $overrides);
550 550
 
551
-		if ( isset( $sideloaded['error'] ) ) {
552
-			@unlink( $tmpfname );
551
+		if (isset($sideloaded['error'])) {
552
+			@unlink($tmpfname);
553 553
 
554
-			return new WP_Error( 'rest_upload_sideload_error', $sideloaded['error'], array( 'status' => 500 ) );
554
+			return new WP_Error('rest_upload_sideload_error', $sideloaded['error'], array('status' => 500));
555 555
 		}
556 556
 
557 557
 		return $sideloaded;
@@ -587,41 +587,41 @@  discard block
 block discarded – undo
587 587
 	 * @param string[] $disposition_header List of Content-Disposition header values.
588 588
 	 * @return string|null Filename if available, or null if not found.
589 589
 	 */
590
-	public static function get_filename_from_disposition( $disposition_header ) {
590
+	public static function get_filename_from_disposition($disposition_header) {
591 591
 		// Get the filename.
592 592
 		$filename = null;
593 593
 
594
-		foreach ( $disposition_header as $value ) {
595
-			$value = trim( $value );
594
+		foreach ($disposition_header as $value) {
595
+			$value = trim($value);
596 596
 
597
-			if ( strpos( $value, ';' ) === false ) {
597
+			if (strpos($value, ';') === false) {
598 598
 				continue;
599 599
 			}
600 600
 
601
-			list( $type, $attr_parts ) = explode( ';', $value, 2 );
601
+			list($type, $attr_parts) = explode(';', $value, 2);
602 602
 
603
-			$attr_parts = explode( ';', $attr_parts );
603
+			$attr_parts = explode(';', $attr_parts);
604 604
 			$attributes = array();
605 605
 
606
-			foreach ( $attr_parts as $part ) {
607
-				if ( strpos( $part, '=' ) === false ) {
606
+			foreach ($attr_parts as $part) {
607
+				if (strpos($part, '=') === false) {
608 608
 					continue;
609 609
 				}
610 610
 
611
-				list( $key, $value ) = explode( '=', $part, 2 );
611
+				list($key, $value) = explode('=', $part, 2);
612 612
 
613
-				$attributes[ trim( $key ) ] = trim( $value );
613
+				$attributes[trim($key)] = trim($value);
614 614
 			}
615 615
 
616
-			if ( empty( $attributes['filename'] ) ) {
616
+			if (empty($attributes['filename'])) {
617 617
 				continue;
618 618
 			}
619 619
 
620
-			$filename = trim( $attributes['filename'] );
620
+			$filename = trim($attributes['filename']);
621 621
 
622 622
 			// Unquote quoted filename, but after trimming.
623
-			if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) {
624
-				$filename = substr( $filename, 1, -1 );
623
+			if (substr($filename, 0, 1) === '"' && substr($filename, -1, 1) === '"') {
624
+				$filename = substr($filename, 1, -1);
625 625
 			}
626 626
 		}
627 627
 
@@ -639,19 +639,19 @@  discard block
 block discarded – undo
639 639
 	public function get_collection_params() {
640 640
 		$params = parent::get_collection_params();
641 641
 		$params['status']['default'] = 'inherit';
642
-		$params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' );
642
+		$params['status']['items']['enum'] = array('inherit', 'private', 'trash');
643 643
 		$media_types = $this->get_media_types();
644 644
 
645 645
 		$params['media_type'] = array(
646 646
 			'default'           => null,
647
-			'description'       => __( 'Limit result set to attachments of a particular media type.' ),
647
+			'description'       => __('Limit result set to attachments of a particular media type.'),
648 648
 			'type'              => 'string',
649
-			'enum'              => array_keys( $media_types ),
649
+			'enum'              => array_keys($media_types),
650 650
 		);
651 651
 
652 652
 		$params['mime_type'] = array(
653 653
 			'default'     => null,
654
-			'description' => __( 'Limit result set to attachments of a particular MIME type.' ),
654
+			'description' => __('Limit result set to attachments of a particular MIME type.'),
655 655
 			'type'        => 'string',
656 656
 		);
657 657
 
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
 	 * @param string          $parameter Additional parameter to pass for validation.
670 670
 	 * @return WP_Error|bool True if the user may query, WP_Error if not.
671 671
 	 */
672
-	public function validate_user_can_query_private_statuses( $value, $request, $parameter ) {
673
-		if ( 'inherit' === $value ) {
672
+	public function validate_user_can_query_private_statuses($value, $request, $parameter) {
673
+		if ('inherit' === $value) {
674 674
 			return true;
675 675
 		}
676 676
 
677
-		return parent::validate_user_can_query_private_statuses( $value, $request, $parameter );
677
+		return parent::validate_user_can_query_private_statuses($value, $request, $parameter);
678 678
 	}
679 679
 
680 680
 	/**
@@ -687,19 +687,19 @@  discard block
 block discarded – undo
687 687
 	 * @param array $headers HTTP headers from the request.
688 688
 	 * @return array|WP_Error Data from wp_handle_upload().
689 689
 	 */
690
-	protected function upload_from_file( $files, $headers ) {
691
-		if ( empty( $files ) ) {
692
-			return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) );
690
+	protected function upload_from_file($files, $headers) {
691
+		if (empty($files)) {
692
+			return new WP_Error('rest_upload_no_data', __('No data supplied.'), array('status' => 400));
693 693
 		}
694 694
 
695 695
 		// Verify hash, if given.
696
-		if ( ! empty( $headers['content_md5'] ) ) {
697
-			$content_md5 = array_shift( $headers['content_md5'] );
698
-			$expected    = trim( $content_md5 );
699
-			$actual      = md5_file( $files['file']['tmp_name'] );
696
+		if ( ! empty($headers['content_md5'])) {
697
+			$content_md5 = array_shift($headers['content_md5']);
698
+			$expected    = trim($content_md5);
699
+			$actual      = md5_file($files['file']['tmp_name']);
700 700
 
701
-			if ( $expected !== $actual ) {
702
-				return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) );
701
+			if ($expected !== $actual) {
702
+				return new WP_Error('rest_upload_hash_mismatch', __('Content hash did not match expected.'), array('status' => 412));
703 703
 			}
704 704
 		}
705 705
 
@@ -709,17 +709,17 @@  discard block
 block discarded – undo
709 709
 		);
710 710
 
711 711
 		// Bypasses is_uploaded_file() when running unit tests.
712
-		if ( defined( 'DIR_TESTDATA' ) && DIR_TESTDATA ) {
712
+		if (defined('DIR_TESTDATA') && DIR_TESTDATA) {
713 713
 			$overrides['action'] = 'wp_handle_mock_upload';
714 714
 		}
715 715
 
716 716
 		/** Include admin functions to get access to wp_handle_upload() */
717
-		require_once ABSPATH . 'wp-admin/includes/admin.php';
717
+		require_once ABSPATH.'wp-admin/includes/admin.php';
718 718
 
719
-		$file = wp_handle_upload( $files['file'], $overrides );
719
+		$file = wp_handle_upload($files['file'], $overrides);
720 720
 
721
-		if ( isset( $file['error'] ) ) {
722
-			return new WP_Error( 'rest_upload_unknown_error', $file['error'], array( 'status' => 500 ) );
721
+		if (isset($file['error'])) {
722
+			return new WP_Error('rest_upload_unknown_error', $file['error'], array('status' => 500));
723 723
 		}
724 724
 
725 725
 		return $file;
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
 	protected function get_media_types() {
739 739
 		$media_types = array();
740 740
 
741
-		foreach ( get_allowed_mime_types() as $mime_type ) {
742
-			$parts = explode( '/', $mime_type );
741
+		foreach (get_allowed_mime_types() as $mime_type) {
742
+			$parts = explode('/', $mime_type);
743 743
 
744
-			if ( ! isset( $media_types[ $parts[0] ] ) ) {
745
-				$media_types[ $parts[0] ] = array();
744
+			if ( ! isset($media_types[$parts[0]])) {
745
+				$media_types[$parts[0]] = array();
746 746
 			}
747 747
 
748
-			$media_types[ $parts[0] ][] = $mime_type;
748
+			$media_types[$parts[0]][] = $mime_type;
749 749
 		}
750 750
 
751 751
 		return $media_types;
Please login to merge, or discard this patch.
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1002,7 +1002,7 @@
 block discarded – undo
1002 1002
 	 * @since 4.7.0
1003 1003
 	 * @access protected
1004 1004
 	 *
1005
-	 * @param string|int $comment_approved comment status.
1005
+	 * @param string $comment_approved comment status.
1006 1006
 	 * @return string Comment status.
1007 1007
 	 */
1008 1008
 	protected function prepare_status_response( $comment_approved ) {
Please login to merge, or discard this patch.
Spacing   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -46,65 +46,65 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function register_routes() {
48 48
 
49
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
49
+		register_rest_route($this->namespace, '/'.$this->rest_base, array(
50 50
 			array(
51 51
 				'methods'   => WP_REST_Server::READABLE,
52
-				'callback'  => array( $this, 'get_items' ),
53
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
52
+				'callback'  => array($this, 'get_items'),
53
+				'permission_callback' => array($this, 'get_items_permissions_check'),
54 54
 				'args'      => $this->get_collection_params(),
55 55
 			),
56 56
 			array(
57 57
 				'methods'  => WP_REST_Server::CREATABLE,
58
-				'callback' => array( $this, 'create_item' ),
59
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
60
-				'args'     => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
58
+				'callback' => array($this, 'create_item'),
59
+				'permission_callback' => array($this, 'create_item_permissions_check'),
60
+				'args'     => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
61 61
 			),
62
-			'schema' => array( $this, 'get_public_item_schema' ),
63
-		) );
62
+			'schema' => array($this, 'get_public_item_schema'),
63
+		));
64 64
 
65
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
65
+		register_rest_route($this->namespace, '/'.$this->rest_base.'/(?P<id>[\d]+)', array(
66 66
 			'args' => array(
67 67
 				'id' => array(
68
-					'description' => __( 'Unique identifier for the object.' ),
68
+					'description' => __('Unique identifier for the object.'),
69 69
 					'type'        => 'integer',
70 70
 				),
71 71
 			),
72 72
 			array(
73 73
 				'methods'  => WP_REST_Server::READABLE,
74
-				'callback' => array( $this, 'get_item' ),
75
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
74
+				'callback' => array($this, 'get_item'),
75
+				'permission_callback' => array($this, 'get_item_permissions_check'),
76 76
 				'args'     => array(
77
-					'context'          => $this->get_context_param( array( 'default' => 'view' ) ),
77
+					'context'          => $this->get_context_param(array('default' => 'view')),
78 78
 					'password' => array(
79
-						'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
79
+						'description' => __('The password for the parent post of the comment (if the post is password protected).'),
80 80
 						'type'        => 'string',
81 81
 					),
82 82
 				),
83 83
 			),
84 84
 			array(
85 85
 				'methods'  => WP_REST_Server::EDITABLE,
86
-				'callback' => array( $this, 'update_item' ),
87
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
88
-				'args'     => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
86
+				'callback' => array($this, 'update_item'),
87
+				'permission_callback' => array($this, 'update_item_permissions_check'),
88
+				'args'     => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
89 89
 			),
90 90
 			array(
91 91
 				'methods'  => WP_REST_Server::DELETABLE,
92
-				'callback' => array( $this, 'delete_item' ),
93
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
92
+				'callback' => array($this, 'delete_item'),
93
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
94 94
 				'args'     => array(
95 95
 					'force'    => array(
96 96
 						'type'        => 'boolean',
97 97
 						'default'     => false,
98
-						'description' => __( 'Whether to bypass trash and force deletion.' ),
98
+						'description' => __('Whether to bypass trash and force deletion.'),
99 99
 					),
100 100
 					'password' => array(
101
-						'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
101
+						'description' => __('The password for the parent post of the comment (if the post is password protected).'),
102 102
 						'type'        => 'string',
103 103
 					),
104 104
 				),
105 105
 			),
106
-			'schema' => array( $this, 'get_public_item_schema' ),
107
-		) );
106
+			'schema' => array($this, 'get_public_item_schema'),
107
+		));
108 108
 	}
109 109
 
110 110
 	/**
@@ -116,44 +116,44 @@  discard block
 block discarded – undo
116 116
 	 * @param WP_REST_Request $request Full details about the request.
117 117
 	 * @return WP_Error|bool True if the request has read access, error object otherwise.
118 118
 	 */
119
-	public function get_items_permissions_check( $request ) {
119
+	public function get_items_permissions_check($request) {
120 120
 
121
-		if ( ! empty( $request['post'] ) ) {
122
-			foreach ( (array) $request['post'] as $post_id ) {
123
-				$post = get_post( $post_id );
121
+		if ( ! empty($request['post'])) {
122
+			foreach ((array) $request['post'] as $post_id) {
123
+				$post = get_post($post_id);
124 124
 
125
-				if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post, $request ) ) {
126
-					return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
127
-				} elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) {
128
-					return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) );
125
+				if ( ! empty($post_id) && $post && ! $this->check_read_post_permission($post, $request)) {
126
+					return new WP_Error('rest_cannot_read_post', __('Sorry, you are not allowed to read the post for this comment.'), array('status' => rest_authorization_required_code()));
127
+				} elseif (0 === $post_id && ! current_user_can('moderate_comments')) {
128
+					return new WP_Error('rest_cannot_read', __('Sorry, you are not allowed to read comments without a post.'), array('status' => rest_authorization_required_code()));
129 129
 				}
130 130
 			}
131 131
 		}
132 132
 
133
-		if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) {
134
-			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) );
133
+		if ( ! empty($request['context']) && 'edit' === $request['context'] && ! current_user_can('moderate_comments')) {
134
+			return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit comments.'), array('status' => rest_authorization_required_code()));
135 135
 		}
136 136
 
137
-		if ( ! current_user_can( 'edit_posts' ) ) {
138
-			$protected_params = array( 'author', 'author_exclude', 'author_email', 'type', 'status' );
137
+		if ( ! current_user_can('edit_posts')) {
138
+			$protected_params = array('author', 'author_exclude', 'author_email', 'type', 'status');
139 139
 			$forbidden_params = array();
140 140
 
141
-			foreach ( $protected_params as $param ) {
142
-				if ( 'status' === $param ) {
143
-					if ( 'approve' !== $request[ $param ] ) {
141
+			foreach ($protected_params as $param) {
142
+				if ('status' === $param) {
143
+					if ('approve' !== $request[$param]) {
144 144
 						$forbidden_params[] = $param;
145 145
 					}
146
-				} elseif ( 'type' === $param ) {
147
-					if ( 'comment' !== $request[ $param ] ) {
146
+				} elseif ('type' === $param) {
147
+					if ('comment' !== $request[$param]) {
148 148
 						$forbidden_params[] = $param;
149 149
 					}
150
-				} elseif ( ! empty( $request[ $param ] ) ) {
150
+				} elseif ( ! empty($request[$param])) {
151 151
 					$forbidden_params[] = $param;
152 152
 				}
153 153
 			}
154 154
 
155
-			if ( ! empty( $forbidden_params ) ) {
156
-				return new WP_Error( 'rest_forbidden_param', sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) );
155
+			if ( ! empty($forbidden_params)) {
156
+				return new WP_Error('rest_forbidden_param', sprintf(__('Query parameter not permitted: %s'), implode(', ', $forbidden_params)), array('status' => rest_authorization_required_code()));
157 157
 			}
158 158
 		}
159 159
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param WP_REST_Request $request Full details about the request.
170 170
 	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
171 171
 	 */
172
-	public function get_items( $request ) {
172
+	public function get_items($request) {
173 173
 
174 174
 		// Retrieve the list of registered collection query parameters.
175 175
 		$registered = $this->get_collection_params();
@@ -203,21 +203,21 @@  discard block
 block discarded – undo
203 203
 		 * For each known parameter which is both registered and present in the request,
204 204
 		 * set the parameter's value on the query $prepared_args.
205 205
 		 */
206
-		foreach ( $parameter_mappings as $api_param => $wp_param ) {
207
-			if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
208
-				$prepared_args[ $wp_param ] = $request[ $api_param ];
206
+		foreach ($parameter_mappings as $api_param => $wp_param) {
207
+			if (isset($registered[$api_param], $request[$api_param])) {
208
+				$prepared_args[$wp_param] = $request[$api_param];
209 209
 			}
210 210
 		}
211 211
 
212 212
 		// Ensure certain parameter values default to empty strings.
213
-		foreach ( array( 'author_email', 'search' ) as $param ) {
214
-			if ( ! isset( $prepared_args[ $param ] ) ) {
215
-				$prepared_args[ $param ] = '';
213
+		foreach (array('author_email', 'search') as $param) {
214
+			if ( ! isset($prepared_args[$param])) {
215
+				$prepared_args[$param] = '';
216 216
 			}
217 217
 		}
218 218
 
219
-		if ( isset( $registered['orderby'] ) ) {
220
-			$prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] );
219
+		if (isset($registered['orderby'])) {
220
+			$prepared_args['orderby'] = $this->normalize_query_param($request['orderby']);
221 221
 		}
222 222
 
223 223
 		$prepared_args['no_found_rows'] = false;
@@ -225,17 +225,17 @@  discard block
 block discarded – undo
225 225
 		$prepared_args['date_query'] = array();
226 226
 
227 227
 		// Set before into date query. Date query must be specified as an array of an array.
228
-		if ( isset( $registered['before'], $request['before'] ) ) {
228
+		if (isset($registered['before'], $request['before'])) {
229 229
 			$prepared_args['date_query'][0]['before'] = $request['before'];
230 230
 		}
231 231
 
232 232
 		// Set after into date query. Date query must be specified as an array of an array.
233
-		if ( isset( $registered['after'], $request['after'] ) ) {
233
+		if (isset($registered['after'], $request['after'])) {
234 234
 			$prepared_args['date_query'][0]['after'] = $request['after'];
235 235
 		}
236 236
 
237
-		if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) {
238
-			$prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 );
237
+		if (isset($registered['page']) && empty($request['offset'])) {
238
+			$prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1);
239 239
 		}
240 240
 
241 241
 		/**
@@ -248,58 +248,58 @@  discard block
 block discarded – undo
248 248
 		 * @param array           $prepared_args Array of arguments for WP_Comment_Query.
249 249
 		 * @param WP_REST_Request $request       The current request.
250 250
 		 */
251
-		$prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request );
251
+		$prepared_args = apply_filters('rest_comment_query', $prepared_args, $request);
252 252
 
253 253
 		$query = new WP_Comment_Query;
254
-		$query_result = $query->query( $prepared_args );
254
+		$query_result = $query->query($prepared_args);
255 255
 
256 256
 		$comments = array();
257 257
 
258
-		foreach ( $query_result as $comment ) {
259
-			if ( ! $this->check_read_permission( $comment, $request ) ) {
258
+		foreach ($query_result as $comment) {
259
+			if ( ! $this->check_read_permission($comment, $request)) {
260 260
 				continue;
261 261
 			}
262 262
 
263
-			$data = $this->prepare_item_for_response( $comment, $request );
264
-			$comments[] = $this->prepare_response_for_collection( $data );
263
+			$data = $this->prepare_item_for_response($comment, $request);
264
+			$comments[] = $this->prepare_response_for_collection($data);
265 265
 		}
266 266
 
267 267
 		$total_comments = (int) $query->found_comments;
268 268
 		$max_pages      = (int) $query->max_num_pages;
269 269
 
270
-		if ( $total_comments < 1 ) {
270
+		if ($total_comments < 1) {
271 271
 			// Out-of-bounds, run the query again without LIMIT for total count.
272
-			unset( $prepared_args['number'], $prepared_args['offset'] );
272
+			unset($prepared_args['number'], $prepared_args['offset']);
273 273
 
274 274
 			$query = new WP_Comment_Query;
275 275
 			$prepared_args['count'] = true;
276 276
 
277
-			$total_comments = $query->query( $prepared_args );
278
-			$max_pages = ceil( $total_comments / $request['per_page'] );
277
+			$total_comments = $query->query($prepared_args);
278
+			$max_pages = ceil($total_comments / $request['per_page']);
279 279
 		}
280 280
 
281
-		$response = rest_ensure_response( $comments );
282
-		$response->header( 'X-WP-Total', $total_comments );
283
-		$response->header( 'X-WP-TotalPages', $max_pages );
281
+		$response = rest_ensure_response($comments);
282
+		$response->header('X-WP-Total', $total_comments);
283
+		$response->header('X-WP-TotalPages', $max_pages);
284 284
 
285
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
285
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)));
286 286
 
287
-		if ( $request['page'] > 1 ) {
287
+		if ($request['page'] > 1) {
288 288
 			$prev_page = $request['page'] - 1;
289 289
 
290
-			if ( $prev_page > $max_pages ) {
290
+			if ($prev_page > $max_pages) {
291 291
 				$prev_page = $max_pages;
292 292
 			}
293 293
 
294
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
295
-			$response->link_header( 'prev', $prev_link );
294
+			$prev_link = add_query_arg('page', $prev_page, $base);
295
+			$response->link_header('prev', $prev_link);
296 296
 		}
297 297
 
298
-		if ( $max_pages > $request['page'] ) {
298
+		if ($max_pages > $request['page']) {
299 299
 			$next_page = $request['page'] + 1;
300
-			$next_link = add_query_arg( 'page', $next_page, $base );
300
+			$next_link = add_query_arg('page', $next_page, $base);
301 301
 
302
-			$response->link_header( 'next', $next_link );
302
+			$response->link_header('next', $next_link);
303 303
 		}
304 304
 
305 305
 		return $response;
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @param int $id Supplied ID.
314 314
 	 * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise.
315 315
 	 */
316
-	protected function get_comment( $id ) {
317
-		$error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) );
318
-		if ( (int) $id <= 0 ) {
316
+	protected function get_comment($id) {
317
+		$error = new WP_Error('rest_comment_invalid_id', __('Invalid comment ID.'), array('status' => 404));
318
+		if ((int) $id <= 0) {
319 319
 			return $error;
320 320
 		}
321 321
 
322 322
 		$id = (int) $id;
323
-		$comment = get_comment( $id );
324
-		if ( empty( $comment ) ) {
323
+		$comment = get_comment($id);
324
+		if (empty($comment)) {
325 325
 			return $error;
326 326
 		}
327 327
 
328
-		if ( ! empty( $comment->comment_post_ID ) ) {
329
-			$post = get_post( (int) $comment->comment_post_ID );
330
-			if ( empty( $post ) ) {
331
-				return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) );
328
+		if ( ! empty($comment->comment_post_ID)) {
329
+			$post = get_post((int) $comment->comment_post_ID);
330
+			if (empty($post)) {
331
+				return new WP_Error('rest_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
332 332
 			}
333 333
 		}
334 334
 
@@ -344,24 +344,24 @@  discard block
 block discarded – undo
344 344
 	 * @param WP_REST_Request $request Full details about the request.
345 345
 	 * @return WP_Error|bool True if the request has read access for the item, error object otherwise.
346 346
 	 */
347
-	public function get_item_permissions_check( $request ) {
348
-		$comment = $this->get_comment( $request['id'] );
349
-		if ( is_wp_error( $comment ) ) {
347
+	public function get_item_permissions_check($request) {
348
+		$comment = $this->get_comment($request['id']);
349
+		if (is_wp_error($comment)) {
350 350
 			return $comment;
351 351
 		}
352 352
 
353
-		if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) {
354
-			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) );
353
+		if ( ! empty($request['context']) && 'edit' === $request['context'] && ! current_user_can('moderate_comments')) {
354
+			return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit comments.'), array('status' => rest_authorization_required_code()));
355 355
 		}
356 356
 
357
-		$post = get_post( $comment->comment_post_ID );
357
+		$post = get_post($comment->comment_post_ID);
358 358
 
359
-		if ( ! $this->check_read_permission( $comment, $request ) ) {
360
-			return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) );
359
+		if ( ! $this->check_read_permission($comment, $request)) {
360
+			return new WP_Error('rest_cannot_read', __('Sorry, you are not allowed to read this comment.'), array('status' => rest_authorization_required_code()));
361 361
 		}
362 362
 
363
-		if ( $post && ! $this->check_read_post_permission( $post, $request ) ) {
364
-			return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
363
+		if ($post && ! $this->check_read_post_permission($post, $request)) {
364
+			return new WP_Error('rest_cannot_read_post', __('Sorry, you are not allowed to read the post for this comment.'), array('status' => rest_authorization_required_code()));
365 365
 		}
366 366
 
367 367
 		return true;
@@ -376,14 +376,14 @@  discard block
 block discarded – undo
376 376
 	 * @param WP_REST_Request $request Full details about the request.
377 377
 	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
378 378
 	 */
379
-	public function get_item( $request ) {
380
-		$comment = $this->get_comment( $request['id'] );
381
-		if ( is_wp_error( $comment ) ) {
379
+	public function get_item($request) {
380
+		$comment = $this->get_comment($request['id']);
381
+		if (is_wp_error($comment)) {
382 382
 			return $comment;
383 383
 		}
384 384
 
385
-		$data = $this->prepare_item_for_response( $comment, $request );
386
-		$response = rest_ensure_response( $data );
385
+		$data = $this->prepare_item_for_response($comment, $request);
386
+		$response = rest_ensure_response($data);
387 387
 
388 388
 		return $response;
389 389
 	}
@@ -397,10 +397,10 @@  discard block
 block discarded – undo
397 397
 	 * @param WP_REST_Request $request Full details about the request.
398 398
 	 * @return WP_Error|bool True if the request has access to create items, error object otherwise.
399 399
 	 */
400
-	public function create_item_permissions_check( $request ) {
401
-		if ( ! is_user_logged_in() ) {
402
-			if ( get_option( 'comment_registration' ) ) {
403
-				return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
400
+	public function create_item_permissions_check($request) {
401
+		if ( ! is_user_logged_in()) {
402
+			if (get_option('comment_registration')) {
403
+				return new WP_Error('rest_comment_login_required', __('Sorry, you must be logged in to comment.'), array('status' => 401));
404 404
 			}
405 405
 
406 406
 			/**
@@ -415,62 +415,62 @@  discard block
 block discarded – undo
415 415
 			 * @param WP_REST_Request $request Request used to generate the
416 416
 			 *                                 response.
417 417
 			 */
418
-			$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );
419
-			if ( ! $allow_anonymous ) {
420
-				return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
418
+			$allow_anonymous = apply_filters('rest_allow_anonymous_comments', false, $request);
419
+			if ( ! $allow_anonymous) {
420
+				return new WP_Error('rest_comment_login_required', __('Sorry, you must be logged in to comment.'), array('status' => 401));
421 421
 			}
422 422
 		}
423 423
 
424 424
 		// Limit who can set comment `author`, `author_ip` or `status` to anything other than the default.
425
-		if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
426
-			return new WP_Error( 'rest_comment_invalid_author',
425
+		if (isset($request['author']) && get_current_user_id() !== $request['author'] && ! current_user_can('moderate_comments')) {
426
+			return new WP_Error('rest_comment_invalid_author',
427 427
 				/* translators: %s: request parameter */
428
-				sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ),
429
-				array( 'status' => rest_authorization_required_code() )
428
+				sprintf(__("Sorry, you are not allowed to edit '%s' for comments."), 'author'),
429
+				array('status' => rest_authorization_required_code())
430 430
 			);
431 431
 		}
432 432
 
433
-		if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) {
434
-			if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) {
435
-				return new WP_Error( 'rest_comment_invalid_author_ip',
433
+		if (isset($request['author_ip']) && ! current_user_can('moderate_comments')) {
434
+			if (empty($_SERVER['REMOTE_ADDR']) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR']) {
435
+				return new WP_Error('rest_comment_invalid_author_ip',
436 436
 					/* translators: %s: request parameter */
437
-					sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ),
438
-					array( 'status' => rest_authorization_required_code() )
437
+					sprintf(__("Sorry, you are not allowed to edit '%s' for comments."), 'author_ip'),
438
+					array('status' => rest_authorization_required_code())
439 439
 				);
440 440
 			}
441 441
 		}
442 442
 
443
-		if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) {
444
-			return new WP_Error( 'rest_comment_invalid_status',
443
+		if (isset($request['status']) && ! current_user_can('moderate_comments')) {
444
+			return new WP_Error('rest_comment_invalid_status',
445 445
 				/* translators: %s: request parameter */
446
-				sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ),
447
-				array( 'status' => rest_authorization_required_code() )
446
+				sprintf(__("Sorry, you are not allowed to edit '%s' for comments."), 'status'),
447
+				array('status' => rest_authorization_required_code())
448 448
 			);
449 449
 		}
450 450
 
451
-		if ( empty( $request['post'] ) ) {
452
-			return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) );
451
+		if (empty($request['post'])) {
452
+			return new WP_Error('rest_comment_invalid_post_id', __('Sorry, you are not allowed to create this comment without a post.'), array('status' => 403));
453 453
 		}
454 454
 
455
-		$post = get_post( (int) $request['post'] );
456
-		if ( ! $post ) {
457
-			return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) );
455
+		$post = get_post((int) $request['post']);
456
+		if ( ! $post) {
457
+			return new WP_Error('rest_comment_invalid_post_id', __('Sorry, you are not allowed to create this comment without a post.'), array('status' => 403));
458 458
 		}
459 459
 
460
-		if ( 'draft' === $post->post_status ) {
461
-			return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) );
460
+		if ('draft' === $post->post_status) {
461
+			return new WP_Error('rest_comment_draft_post', __('Sorry, you are not allowed to create a comment on this post.'), array('status' => 403));
462 462
 		}
463 463
 
464
-		if ( 'trash' === $post->post_status ) {
465
-			return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) );
464
+		if ('trash' === $post->post_status) {
465
+			return new WP_Error('rest_comment_trash_post', __('Sorry, you are not allowed to create a comment on this post.'), array('status' => 403));
466 466
 		}
467 467
 
468
-		if ( ! $this->check_read_post_permission( $post, $request ) ) {
469
-			return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
468
+		if ( ! $this->check_read_post_permission($post, $request)) {
469
+			return new WP_Error('rest_cannot_read_post', __('Sorry, you are not allowed to read the post for this comment.'), array('status' => rest_authorization_required_code()));
470 470
 		}
471 471
 
472
-		if ( ! comments_open( $post->ID ) ) {
473
-			return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) );
472
+		if ( ! comments_open($post->ID)) {
473
+			return new WP_Error('rest_comment_closed', __('Sorry, comments are closed for this item.'), array('status' => 403));
474 474
 		}
475 475
 
476 476
 		return true;
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param WP_REST_Request $request Full details about the request.
486 486
 	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
487 487
 	 */
488
-	public function create_item( $request ) {
489
-		if ( ! empty( $request['id'] ) ) {
490
-			return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) );
488
+	public function create_item($request) {
489
+		if ( ! empty($request['id'])) {
490
+			return new WP_Error('rest_comment_exists', __('Cannot create existing comment.'), array('status' => 400));
491 491
 		}
492 492
 
493 493
 		// Do not allow comments to be created with a non-default type.
494
-		if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) {
495
-			return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) );
494
+		if ( ! empty($request['type']) && 'comment' !== $request['type']) {
495
+			return new WP_Error('rest_invalid_comment_type', __('Cannot create a comment with that type.'), array('status' => 400));
496 496
 		}
497 497
 
498
-		$prepared_comment = $this->prepare_item_for_database( $request );
499
-		if ( is_wp_error( $prepared_comment ) ) {
498
+		$prepared_comment = $this->prepare_item_for_database($request);
499
+		if (is_wp_error($prepared_comment)) {
500 500
 			return $prepared_comment;
501 501
 		}
502 502
 
@@ -506,22 +506,22 @@  discard block
 block discarded – undo
506 506
 		 * Do not allow a comment to be created with missing or empty
507 507
 		 * comment_content. See wp_handle_comment_submission().
508 508
 		 */
509
-		if ( empty( $prepared_comment['comment_content'] ) ) {
510
-			return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) );
509
+		if (empty($prepared_comment['comment_content'])) {
510
+			return new WP_Error('rest_comment_content_invalid', __('Invalid comment content.'), array('status' => 400));
511 511
 		}
512 512
 
513 513
 		// Setting remaining values before wp_insert_comment so we can use wp_allow_comment().
514
-		if ( ! isset( $prepared_comment['comment_date_gmt'] ) ) {
515
-			$prepared_comment['comment_date_gmt'] = current_time( 'mysql', true );
514
+		if ( ! isset($prepared_comment['comment_date_gmt'])) {
515
+			$prepared_comment['comment_date_gmt'] = current_time('mysql', true);
516 516
 		}
517 517
 
518 518
 		// Set author data if the user's logged in.
519
-		$missing_author = empty( $prepared_comment['user_id'] )
520
-			&& empty( $prepared_comment['comment_author'] )
521
-			&& empty( $prepared_comment['comment_author_email'] )
522
-			&& empty( $prepared_comment['comment_author_url'] );
519
+		$missing_author = empty($prepared_comment['user_id'])
520
+			&& empty($prepared_comment['comment_author'])
521
+			&& empty($prepared_comment['comment_author_email'])
522
+			&& empty($prepared_comment['comment_author_url']);
523 523
 
524
-		if ( is_user_logged_in() && $missing_author ) {
524
+		if (is_user_logged_in() && $missing_author) {
525 525
 			$user = wp_get_current_user();
526 526
 
527 527
 			$prepared_comment['user_id'] = $user->ID;
@@ -531,42 +531,42 @@  discard block
 block discarded – undo
531 531
 		}
532 532
 
533 533
 		// Honor the discussion setting that requires a name and email address of the comment author.
534
-		if ( get_option( 'require_name_email' ) ) {
535
-			if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) {
536
-				return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) );
534
+		if (get_option('require_name_email')) {
535
+			if (empty($prepared_comment['comment_author']) || empty($prepared_comment['comment_author_email'])) {
536
+				return new WP_Error('rest_comment_author_data_required', __('Creating a comment requires valid author name and email values.'), array('status' => 400));
537 537
 			}
538 538
 		}
539 539
 
540
-		if ( ! isset( $prepared_comment['comment_author_email'] ) ) {
540
+		if ( ! isset($prepared_comment['comment_author_email'])) {
541 541
 			$prepared_comment['comment_author_email'] = '';
542 542
 		}
543 543
 
544
-		if ( ! isset( $prepared_comment['comment_author_url'] ) ) {
544
+		if ( ! isset($prepared_comment['comment_author_url'])) {
545 545
 			$prepared_comment['comment_author_url'] = '';
546 546
 		}
547 547
 
548
-		if ( ! isset( $prepared_comment['comment_agent'] ) ) {
548
+		if ( ! isset($prepared_comment['comment_agent'])) {
549 549
 			$prepared_comment['comment_agent'] = '';
550 550
 		}
551 551
 
552
-		$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment );
553
-		if ( is_wp_error( $check_comment_lengths ) ) {
552
+		$check_comment_lengths = wp_check_comment_data_max_lengths($prepared_comment);
553
+		if (is_wp_error($check_comment_lengths)) {
554 554
 			$error_code = $check_comment_lengths->get_error_code();
555
-			return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) );
555
+			return new WP_Error($error_code, __('Comment field exceeds maximum length allowed.'), array('status' => 400));
556 556
 		}
557 557
 
558
-		$prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true );
558
+		$prepared_comment['comment_approved'] = wp_allow_comment($prepared_comment, true);
559 559
 
560
-		if ( is_wp_error( $prepared_comment['comment_approved'] ) ) {
560
+		if (is_wp_error($prepared_comment['comment_approved'])) {
561 561
 			$error_code    = $prepared_comment['comment_approved']->get_error_code();
562 562
 			$error_message = $prepared_comment['comment_approved']->get_error_message();
563 563
 
564
-			if ( 'comment_duplicate' === $error_code ) {
565
-				return new WP_Error( $error_code, $error_message, array( 'status' => 409 ) );
564
+			if ('comment_duplicate' === $error_code) {
565
+				return new WP_Error($error_code, $error_message, array('status' => 409));
566 566
 			}
567 567
 
568
-			if ( 'comment_flood' === $error_code ) {
569
-				return new WP_Error( $error_code, $error_message, array( 'status' => 400 ) );
568
+			if ('comment_flood' === $error_code) {
569
+				return new WP_Error($error_code, $error_message, array('status' => 400));
570 570
 			}
571 571
 
572 572
 			return $prepared_comment['comment_approved'];
@@ -585,22 +585,22 @@  discard block
 block discarded – undo
585 585
 		 * @param array|WP_Error  $prepared_comment The prepared comment data for wp_insert_comment().
586 586
 		 * @param WP_REST_Request $request          Request used to insert the comment.
587 587
 		 */
588
-		$prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );
589
-		if ( is_wp_error( $prepared_comment ) ) {
588
+		$prepared_comment = apply_filters('rest_pre_insert_comment', $prepared_comment, $request);
589
+		if (is_wp_error($prepared_comment)) {
590 590
 			return $prepared_comment;
591 591
 		}
592 592
 
593
-		$comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) );
593
+		$comment_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_comment)));
594 594
 
595
-		if ( ! $comment_id ) {
596
-			return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) );
595
+		if ( ! $comment_id) {
596
+			return new WP_Error('rest_comment_failed_create', __('Creating comment failed.'), array('status' => 500));
597 597
 		}
598 598
 
599
-		if ( isset( $request['status'] ) ) {
600
-			$this->handle_status_param( $request['status'], $comment_id );
599
+		if (isset($request['status'])) {
600
+			$this->handle_status_param($request['status'], $comment_id);
601 601
 		}
602 602
 
603
-		$comment = get_comment( $comment_id );
603
+		$comment = get_comment($comment_id);
604 604
 
605 605
 		/**
606 606
 		 * Fires after a comment is created or updated via the REST API.
@@ -612,33 +612,33 @@  discard block
 block discarded – undo
612 612
 		 * @param bool            $creating True when creating a comment, false
613 613
 		 *                                  when updating.
614 614
 		 */
615
-		do_action( 'rest_insert_comment', $comment, $request, true );
615
+		do_action('rest_insert_comment', $comment, $request, true);
616 616
 
617 617
 		$schema = $this->get_item_schema();
618 618
 
619
-		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
620
-			$meta_update = $this->meta->update_value( $request['meta'], $comment_id );
619
+		if ( ! empty($schema['properties']['meta']) && isset($request['meta'])) {
620
+			$meta_update = $this->meta->update_value($request['meta'], $comment_id);
621 621
 
622
-			if ( is_wp_error( $meta_update ) ) {
622
+			if (is_wp_error($meta_update)) {
623 623
 				return $meta_update;
624 624
 			}
625 625
 		}
626 626
 
627
-		$fields_update = $this->update_additional_fields_for_object( $comment, $request );
627
+		$fields_update = $this->update_additional_fields_for_object($comment, $request);
628 628
 
629
-		if ( is_wp_error( $fields_update ) ) {
629
+		if (is_wp_error($fields_update)) {
630 630
 			return $fields_update;
631 631
 		}
632 632
 
633
-		$context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view';
633
+		$context = current_user_can('moderate_comments') ? 'edit' : 'view';
634 634
 
635
-		$request->set_param( 'context', $context );
635
+		$request->set_param('context', $context);
636 636
 
637
-		$response = $this->prepare_item_for_response( $comment, $request );
638
-		$response = rest_ensure_response( $response );
637
+		$response = $this->prepare_item_for_response($comment, $request);
638
+		$response = rest_ensure_response($response);
639 639
 
640
-		$response->set_status( 201 );
641
-		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) );
640
+		$response->set_status(201);
641
+		$response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $comment_id)));
642 642
 
643 643
 
644 644
 		return $response;
@@ -653,14 +653,14 @@  discard block
 block discarded – undo
653 653
 	 * @param WP_REST_Request $request Full details about the request.
654 654
 	 * @return WP_Error|bool True if the request has access to update the item, error object otherwise.
655 655
 	 */
656
-	public function update_item_permissions_check( $request ) {
657
-		$comment = $this->get_comment( $request['id'] );
658
-		if ( is_wp_error( $comment ) ) {
656
+	public function update_item_permissions_check($request) {
657
+		$comment = $this->get_comment($request['id']);
658
+		if (is_wp_error($comment)) {
659 659
 			return $comment;
660 660
 		}
661 661
 
662
-		if ( ! $this->check_edit_permission( $comment ) ) {
663
-			return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) );
662
+		if ( ! $this->check_edit_permission($comment)) {
663
+			return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to edit this comment.'), array('status' => rest_authorization_required_code()));
664 664
 		}
665 665
 
666 666
 		return true;
@@ -675,92 +675,92 @@  discard block
 block discarded – undo
675 675
 	 * @param WP_REST_Request $request Full details about the request.
676 676
 	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
677 677
 	 */
678
-	public function update_item( $request ) {
679
-		$comment = $this->get_comment( $request['id'] );
680
-		if ( is_wp_error( $comment ) ) {
678
+	public function update_item($request) {
679
+		$comment = $this->get_comment($request['id']);
680
+		if (is_wp_error($comment)) {
681 681
 			return $comment;
682 682
 		}
683 683
 
684 684
 		$id = $comment->comment_ID;
685 685
 
686
-		if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) {
687
-			return new WP_Error( 'rest_comment_invalid_type', __( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) );
686
+		if (isset($request['type']) && get_comment_type($id) !== $request['type']) {
687
+			return new WP_Error('rest_comment_invalid_type', __('Sorry, you are not allowed to change the comment type.'), array('status' => 404));
688 688
 		}
689 689
 
690
-		$prepared_args = $this->prepare_item_for_database( $request );
690
+		$prepared_args = $this->prepare_item_for_database($request);
691 691
 
692
-		if ( is_wp_error( $prepared_args ) ) {
692
+		if (is_wp_error($prepared_args)) {
693 693
 			return $prepared_args;
694 694
 		}
695 695
 
696
-		if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
697
-			$post = get_post( $prepared_args['comment_post_ID'] );
698
-			if ( empty( $post ) ) {
699
-				return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) );
696
+		if ( ! empty($prepared_args['comment_post_ID'])) {
697
+			$post = get_post($prepared_args['comment_post_ID']);
698
+			if (empty($post)) {
699
+				return new WP_Error('rest_comment_invalid_post_id', __('Invalid post ID.'), array('status' => 403));
700 700
 			}
701 701
 		}
702 702
 
703
-		if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
703
+		if (empty($prepared_args) && isset($request['status'])) {
704 704
 			// Only the comment status is being changed.
705
-			$change = $this->handle_status_param( $request['status'], $id );
705
+			$change = $this->handle_status_param($request['status'], $id);
706 706
 
707
-			if ( ! $change ) {
708
-				return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment status failed.' ), array( 'status' => 500 ) );
707
+			if ( ! $change) {
708
+				return new WP_Error('rest_comment_failed_edit', __('Updating comment status failed.'), array('status' => 500));
709 709
 			}
710
-		} elseif ( ! empty( $prepared_args ) ) {
711
-			if ( is_wp_error( $prepared_args ) ) {
710
+		} elseif ( ! empty($prepared_args)) {
711
+			if (is_wp_error($prepared_args)) {
712 712
 				return $prepared_args;
713 713
 			}
714 714
 
715
-			if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) {
716
-				return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) );
715
+			if (isset($prepared_args['comment_content']) && empty($prepared_args['comment_content'])) {
716
+				return new WP_Error('rest_comment_content_invalid', __('Invalid comment content.'), array('status' => 400));
717 717
 			}
718 718
 
719 719
 			$prepared_args['comment_ID'] = $id;
720 720
 
721
-			$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args );
722
-			if ( is_wp_error( $check_comment_lengths ) ) {
721
+			$check_comment_lengths = wp_check_comment_data_max_lengths($prepared_args);
722
+			if (is_wp_error($check_comment_lengths)) {
723 723
 				$error_code = $check_comment_lengths->get_error_code();
724
-				return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) );
724
+				return new WP_Error($error_code, __('Comment field exceeds maximum length allowed.'), array('status' => 400));
725 725
 			}
726 726
 
727
-			$updated = wp_update_comment( wp_slash( (array) $prepared_args ) );
727
+			$updated = wp_update_comment(wp_slash((array) $prepared_args));
728 728
 
729
-			if ( false === $updated ) {
730
-				return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) );
729
+			if (false === $updated) {
730
+				return new WP_Error('rest_comment_failed_edit', __('Updating comment failed.'), array('status' => 500));
731 731
 			}
732 732
 
733
-			if ( isset( $request['status'] ) ) {
734
-				$this->handle_status_param( $request['status'], $id );
733
+			if (isset($request['status'])) {
734
+				$this->handle_status_param($request['status'], $id);
735 735
 			}
736 736
 		}
737 737
 
738
-		$comment = get_comment( $id );
738
+		$comment = get_comment($id);
739 739
 
740 740
 		/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */
741
-		do_action( 'rest_insert_comment', $comment, $request, false );
741
+		do_action('rest_insert_comment', $comment, $request, false);
742 742
 
743 743
 		$schema = $this->get_item_schema();
744 744
 
745
-		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
746
-			$meta_update = $this->meta->update_value( $request['meta'], $id );
745
+		if ( ! empty($schema['properties']['meta']) && isset($request['meta'])) {
746
+			$meta_update = $this->meta->update_value($request['meta'], $id);
747 747
 
748
-			if ( is_wp_error( $meta_update ) ) {
748
+			if (is_wp_error($meta_update)) {
749 749
 				return $meta_update;
750 750
 			}
751 751
 		}
752 752
 
753
-		$fields_update = $this->update_additional_fields_for_object( $comment, $request );
753
+		$fields_update = $this->update_additional_fields_for_object($comment, $request);
754 754
 
755
-		if ( is_wp_error( $fields_update ) ) {
755
+		if (is_wp_error($fields_update)) {
756 756
 			return $fields_update;
757 757
 		}
758 758
 
759
-		$request->set_param( 'context', 'edit' );
759
+		$request->set_param('context', 'edit');
760 760
 
761
-		$response = $this->prepare_item_for_response( $comment, $request );
761
+		$response = $this->prepare_item_for_response($comment, $request);
762 762
 
763
-		return rest_ensure_response( $response );
763
+		return rest_ensure_response($response);
764 764
 	}
765 765
 
766 766
 	/**
@@ -772,14 +772,14 @@  discard block
 block discarded – undo
772 772
 	 * @param WP_REST_Request $request Full details about the request.
773 773
 	 * @return WP_Error|bool True if the request has access to delete the item, error object otherwise.
774 774
 	 */
775
-	public function delete_item_permissions_check( $request ) {
776
-		$comment = $this->get_comment( $request['id'] );
777
-		if ( is_wp_error( $comment ) ) {
775
+	public function delete_item_permissions_check($request) {
776
+		$comment = $this->get_comment($request['id']);
777
+		if (is_wp_error($comment)) {
778 778
 			return $comment;
779 779
 		}
780 780
 
781
-		if ( ! $this->check_edit_permission( $comment ) ) {
782
-			return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) );
781
+		if ( ! $this->check_edit_permission($comment)) {
782
+			return new WP_Error('rest_cannot_delete', __('Sorry, you are not allowed to delete this comment.'), array('status' => rest_authorization_required_code()));
783 783
 		}
784 784
 		return true;
785 785
 	}
@@ -793,13 +793,13 @@  discard block
 block discarded – undo
793 793
 	 * @param WP_REST_Request $request Full details about the request.
794 794
 	 * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
795 795
 	 */
796
-	public function delete_item( $request ) {
797
-		$comment = $this->get_comment( $request['id'] );
798
-		if ( is_wp_error( $comment ) ) {
796
+	public function delete_item($request) {
797
+		$comment = $this->get_comment($request['id']);
798
+		if (is_wp_error($comment)) {
799 799
 			return $comment;
800 800
 		}
801 801
 
802
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
802
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
803 803
 
804 804
 		/**
805 805
 		 * Filters whether a comment can be trashed.
@@ -811,32 +811,32 @@  discard block
 block discarded – undo
811 811
 		 * @param bool    $supports_trash Whether the post type support trashing.
812 812
 		 * @param WP_Post $comment        The comment object being considered for trashing support.
813 813
 		 */
814
-		$supports_trash = apply_filters( 'rest_comment_trashable', ( EMPTY_TRASH_DAYS > 0 ), $comment );
814
+		$supports_trash = apply_filters('rest_comment_trashable', (EMPTY_TRASH_DAYS > 0), $comment);
815 815
 
816
-		$request->set_param( 'context', 'edit' );
816
+		$request->set_param('context', 'edit');
817 817
 
818
-		if ( $force ) {
819
-			$previous = $this->prepare_item_for_response( $comment, $request );
820
-			$result = wp_delete_comment( $comment->comment_ID, true );
818
+		if ($force) {
819
+			$previous = $this->prepare_item_for_response($comment, $request);
820
+			$result = wp_delete_comment($comment->comment_ID, true);
821 821
 			$response = new WP_REST_Response();
822
-			$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
822
+			$response->set_data(array('deleted' => true, 'previous' => $previous->get_data()));
823 823
 		} else {
824 824
 			// If this type doesn't support trashing, error out.
825
-			if ( ! $supports_trash ) {
826
-				return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
825
+			if ( ! $supports_trash) {
826
+				return new WP_Error('rest_trash_not_supported', __('The comment does not support trashing. Set force=true to delete.'), array('status' => 501));
827 827
 			}
828 828
 
829
-			if ( 'trash' === $comment->comment_approved ) {
830
-				return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) );
829
+			if ('trash' === $comment->comment_approved) {
830
+				return new WP_Error('rest_already_trashed', __('The comment has already been trashed.'), array('status' => 410));
831 831
 			}
832 832
 
833
-			$result = wp_trash_comment( $comment->comment_ID );
834
-			$comment = get_comment( $comment->comment_ID );
835
-			$response = $this->prepare_item_for_response( $comment, $request );
833
+			$result = wp_trash_comment($comment->comment_ID);
834
+			$comment = get_comment($comment->comment_ID);
835
+			$response = $this->prepare_item_for_response($comment, $request);
836 836
 		}
837 837
 
838
-		if ( ! $result ) {
839
-			return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) );
838
+		if ( ! $result) {
839
+			return new WP_Error('rest_cannot_delete', __('The comment cannot be deleted.'), array('status' => 500));
840 840
 		}
841 841
 
842 842
 		/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 		 * @param WP_REST_Response $response The response returned from the API.
849 849
 		 * @param WP_REST_Request  $request  The request sent to the API.
850 850
 		 */
851
-		do_action( 'rest_delete_comment', $comment, $response, $request );
851
+		do_action('rest_delete_comment', $comment, $response, $request);
852 852
 
853 853
 		return $response;
854 854
 	}
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 	 * @param WP_REST_Request $request Request object.
864 864
 	 * @return WP_REST_Response Response object.
865 865
 	 */
866
-	public function prepare_item_for_response( $comment, $request ) {
866
+	public function prepare_item_for_response($comment, $request) {
867 867
 		$data = array(
868 868
 			'id'                 => (int) $comment->comment_ID,
869 869
 			'post'               => (int) $comment->comment_post_ID,
@@ -874,36 +874,36 @@  discard block
 block discarded – undo
874 874
 			'author_url'         => $comment->comment_author_url,
875 875
 			'author_ip'          => $comment->comment_author_IP,
876 876
 			'author_user_agent'  => $comment->comment_agent,
877
-			'date'               => mysql_to_rfc3339( $comment->comment_date ),
878
-			'date_gmt'           => mysql_to_rfc3339( $comment->comment_date_gmt ),
877
+			'date'               => mysql_to_rfc3339($comment->comment_date),
878
+			'date_gmt'           => mysql_to_rfc3339($comment->comment_date_gmt),
879 879
 			'content'            => array(
880 880
 				/** This filter is documented in wp-includes/comment-template.php */
881
-				'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
881
+				'rendered' => apply_filters('comment_text', $comment->comment_content, $comment),
882 882
 				'raw'      => $comment->comment_content,
883 883
 			),
884
-			'link'               => get_comment_link( $comment ),
885
-			'status'             => $this->prepare_status_response( $comment->comment_approved ),
886
-			'type'               => get_comment_type( $comment->comment_ID ),
884
+			'link'               => get_comment_link($comment),
885
+			'status'             => $this->prepare_status_response($comment->comment_approved),
886
+			'type'               => get_comment_type($comment->comment_ID),
887 887
 		);
888 888
 
889 889
 		$schema = $this->get_item_schema();
890 890
 
891
-		if ( ! empty( $schema['properties']['author_avatar_urls'] ) ) {
892
-			$data['author_avatar_urls'] = rest_get_avatar_urls( $comment->comment_author_email );
891
+		if ( ! empty($schema['properties']['author_avatar_urls'])) {
892
+			$data['author_avatar_urls'] = rest_get_avatar_urls($comment->comment_author_email);
893 893
 		}
894 894
 
895
-		if ( ! empty( $schema['properties']['meta'] ) ) {
896
-			$data['meta'] = $this->meta->get_value( $comment->comment_ID, $request );
895
+		if ( ! empty($schema['properties']['meta'])) {
896
+			$data['meta'] = $this->meta->get_value($comment->comment_ID, $request);
897 897
 		}
898 898
 
899
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
900
-		$data    = $this->add_additional_fields_to_object( $data, $request );
901
-		$data    = $this->filter_response_by_context( $data, $context );
899
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
900
+		$data    = $this->add_additional_fields_to_object($data, $request);
901
+		$data    = $this->filter_response_by_context($data, $context);
902 902
 
903 903
 		// Wrap the data in a response object.
904
-		$response = rest_ensure_response( $data );
904
+		$response = rest_ensure_response($data);
905 905
 
906
-		$response->add_links( $this->prepare_links( $comment ) );
906
+		$response->add_links($this->prepare_links($comment));
907 907
 
908 908
 		/**
909 909
 		 * Filters a comment returned from the API.
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 		 * @param WP_Comment        $comment  The original comment object.
917 917
 		 * @param WP_REST_Request   $request  Request used to generate the response.
918 918
 		 */
919
-		return apply_filters( 'rest_prepare_comment', $response, $comment, $request );
919
+		return apply_filters('rest_prepare_comment', $response, $comment, $request);
920 920
 	}
921 921
 
922 922
 	/**
@@ -928,57 +928,57 @@  discard block
 block discarded – undo
928 928
 	 * @param WP_Comment $comment Comment object.
929 929
 	 * @return array Links for the given comment.
930 930
 	 */
931
-	protected function prepare_links( $comment ) {
931
+	protected function prepare_links($comment) {
932 932
 		$links = array(
933 933
 			'self' => array(
934
-				'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
934
+				'href' => rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID)),
935 935
 			),
936 936
 			'collection' => array(
937
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
937
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
938 938
 			),
939 939
 		);
940 940
 
941
-		if ( 0 !== (int) $comment->user_id ) {
941
+		if (0 !== (int) $comment->user_id) {
942 942
 			$links['author'] = array(
943
-				'href'       => rest_url( 'wp/v2/users/' . $comment->user_id ),
943
+				'href'       => rest_url('wp/v2/users/'.$comment->user_id),
944 944
 				'embeddable' => true,
945 945
 			);
946 946
 		}
947 947
 
948
-		if ( 0 !== (int) $comment->comment_post_ID ) {
949
-			$post = get_post( $comment->comment_post_ID );
948
+		if (0 !== (int) $comment->comment_post_ID) {
949
+			$post = get_post($comment->comment_post_ID);
950 950
 
951
-			if ( ! empty( $post->ID ) ) {
952
-				$obj = get_post_type_object( $post->post_type );
953
-				$base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
951
+			if ( ! empty($post->ID)) {
952
+				$obj = get_post_type_object($post->post_type);
953
+				$base = ! empty($obj->rest_base) ? $obj->rest_base : $obj->name;
954 954
 
955 955
 				$links['up'] = array(
956
-					'href'       => rest_url( 'wp/v2/' . $base . '/' . $comment->comment_post_ID ),
956
+					'href'       => rest_url('wp/v2/'.$base.'/'.$comment->comment_post_ID),
957 957
 					'embeddable' => true,
958 958
 					'post_type'  => $post->post_type,
959 959
 				);
960 960
 			}
961 961
 		}
962 962
 
963
-		if ( 0 !== (int) $comment->comment_parent ) {
963
+		if (0 !== (int) $comment->comment_parent) {
964 964
 			$links['in-reply-to'] = array(
965
-				'href'       => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_parent ) ),
965
+				'href'       => rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_parent)),
966 966
 				'embeddable' => true,
967 967
 			);
968 968
 		}
969 969
 
970 970
 		// Only grab one comment to verify the comment has children.
971
-		$comment_children = $comment->get_children( array(
971
+		$comment_children = $comment->get_children(array(
972 972
 			'number' => 1,
973 973
 			'count'  => true
974
-		) );
974
+		));
975 975
 
976
-		if ( ! empty( $comment_children ) ) {
976
+		if ( ! empty($comment_children)) {
977 977
 			$args = array(
978 978
 				'parent' => $comment->comment_ID
979 979
 			);
980 980
 
981
-			$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );
981
+			$rest_url = add_query_arg($args, rest_url($this->namespace.'/'.$this->rest_base));
982 982
 
983 983
 			$links['children'] = array(
984 984
 				'href' => $rest_url,
@@ -997,24 +997,24 @@  discard block
 block discarded – undo
997 997
 	 * @param string $query_param Query parameter.
998 998
 	 * @return string The normalized query parameter.
999 999
 	 */
1000
-	protected function normalize_query_param( $query_param ) {
1000
+	protected function normalize_query_param($query_param) {
1001 1001
 		$prefix = 'comment_';
1002 1002
 
1003
-		switch ( $query_param ) {
1003
+		switch ($query_param) {
1004 1004
 			case 'id':
1005
-				$normalized = $prefix . 'ID';
1005
+				$normalized = $prefix.'ID';
1006 1006
 				break;
1007 1007
 			case 'post':
1008
-				$normalized = $prefix . 'post_ID';
1008
+				$normalized = $prefix.'post_ID';
1009 1009
 				break;
1010 1010
 			case 'parent':
1011
-				$normalized = $prefix . 'parent';
1011
+				$normalized = $prefix.'parent';
1012 1012
 				break;
1013 1013
 			case 'include':
1014 1014
 				$normalized = 'comment__in';
1015 1015
 				break;
1016 1016
 			default:
1017
-				$normalized = $prefix . $query_param;
1017
+				$normalized = $prefix.$query_param;
1018 1018
 				break;
1019 1019
 		}
1020 1020
 
@@ -1030,9 +1030,9 @@  discard block
 block discarded – undo
1030 1030
 	 * @param string|int $comment_approved comment status.
1031 1031
 	 * @return string Comment status.
1032 1032
 	 */
1033
-	protected function prepare_status_response( $comment_approved ) {
1033
+	protected function prepare_status_response($comment_approved) {
1034 1034
 
1035
-		switch ( $comment_approved ) {
1035
+		switch ($comment_approved) {
1036 1036
 			case 'hold':
1037 1037
 			case '0':
1038 1038
 				$status = 'hold';
@@ -1062,77 +1062,77 @@  discard block
 block discarded – undo
1062 1062
 	 * @param WP_REST_Request $request Request object.
1063 1063
 	 * @return array|WP_Error Prepared comment, otherwise WP_Error object.
1064 1064
 	 */
1065
-	protected function prepare_item_for_database( $request ) {
1065
+	protected function prepare_item_for_database($request) {
1066 1066
 		$prepared_comment = array();
1067 1067
 
1068 1068
 		/*
1069 1069
 		 * Allow the comment_content to be set via the 'content' or
1070 1070
 		 * the 'content.raw' properties of the Request object.
1071 1071
 		 */
1072
-		if ( isset( $request['content'] ) && is_string( $request['content'] ) ) {
1072
+		if (isset($request['content']) && is_string($request['content'])) {
1073 1073
 			$prepared_comment['comment_content'] = $request['content'];
1074
-		} elseif ( isset( $request['content']['raw'] ) && is_string( $request['content']['raw'] ) ) {
1074
+		} elseif (isset($request['content']['raw']) && is_string($request['content']['raw'])) {
1075 1075
 			$prepared_comment['comment_content'] = $request['content']['raw'];
1076 1076
 		}
1077 1077
 
1078
-		if ( isset( $request['post'] ) ) {
1078
+		if (isset($request['post'])) {
1079 1079
 			$prepared_comment['comment_post_ID'] = (int) $request['post'];
1080 1080
 		}
1081 1081
 
1082
-		if ( isset( $request['parent'] ) ) {
1082
+		if (isset($request['parent'])) {
1083 1083
 			$prepared_comment['comment_parent'] = $request['parent'];
1084 1084
 		}
1085 1085
 
1086
-		if ( isset( $request['author'] ) ) {
1087
-			$user = new WP_User( $request['author'] );
1086
+		if (isset($request['author'])) {
1087
+			$user = new WP_User($request['author']);
1088 1088
 
1089
-			if ( $user->exists() ) {
1089
+			if ($user->exists()) {
1090 1090
 				$prepared_comment['user_id'] = $user->ID;
1091 1091
 				$prepared_comment['comment_author'] = $user->display_name;
1092 1092
 				$prepared_comment['comment_author_email'] = $user->user_email;
1093 1093
 				$prepared_comment['comment_author_url'] = $user->user_url;
1094 1094
 			} else {
1095
-				return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) );
1095
+				return new WP_Error('rest_comment_author_invalid', __('Invalid comment author ID.'), array('status' => 400));
1096 1096
 			}
1097 1097
 		}
1098 1098
 
1099
-		if ( isset( $request['author_name'] ) ) {
1099
+		if (isset($request['author_name'])) {
1100 1100
 			$prepared_comment['comment_author'] = $request['author_name'];
1101 1101
 		}
1102 1102
 
1103
-		if ( isset( $request['author_email'] ) ) {
1103
+		if (isset($request['author_email'])) {
1104 1104
 			$prepared_comment['comment_author_email'] = $request['author_email'];
1105 1105
 		}
1106 1106
 
1107
-		if ( isset( $request['author_url'] ) ) {
1107
+		if (isset($request['author_url'])) {
1108 1108
 			$prepared_comment['comment_author_url'] = $request['author_url'];
1109 1109
 		}
1110 1110
 
1111
-		if ( isset( $request['author_ip'] ) && current_user_can( 'moderate_comments' ) ) {
1111
+		if (isset($request['author_ip']) && current_user_can('moderate_comments')) {
1112 1112
 			$prepared_comment['comment_author_IP'] = $request['author_ip'];
1113
-		} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) {
1113
+		} elseif ( ! empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address($_SERVER['REMOTE_ADDR'])) {
1114 1114
 			$prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
1115 1115
 		} else {
1116 1116
 			$prepared_comment['comment_author_IP'] = '127.0.0.1';
1117 1117
 		}
1118 1118
 
1119
-		if ( ! empty( $request['author_user_agent'] ) ) {
1119
+		if ( ! empty($request['author_user_agent'])) {
1120 1120
 			$prepared_comment['comment_agent'] = $request['author_user_agent'];
1121
-		} elseif ( $request->get_header( 'user_agent' ) ) {
1122
-			$prepared_comment['comment_agent'] = $request->get_header( 'user_agent' );
1121
+		} elseif ($request->get_header('user_agent')) {
1122
+			$prepared_comment['comment_agent'] = $request->get_header('user_agent');
1123 1123
 		}
1124 1124
 
1125
-		if ( ! empty( $request['date'] ) ) {
1126
-			$date_data = rest_get_date_with_gmt( $request['date'] );
1125
+		if ( ! empty($request['date'])) {
1126
+			$date_data = rest_get_date_with_gmt($request['date']);
1127 1127
 
1128
-			if ( ! empty( $date_data ) ) {
1129
-				list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data;
1128
+			if ( ! empty($date_data)) {
1129
+				list($prepared_comment['comment_date'], $prepared_comment['comment_date_gmt']) = $date_data;
1130 1130
 			}
1131
-		} elseif ( ! empty( $request['date_gmt'] ) ) {
1132
-			$date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
1131
+		} elseif ( ! empty($request['date_gmt'])) {
1132
+			$date_data = rest_get_date_with_gmt($request['date_gmt'], true);
1133 1133
 
1134
-			if ( ! empty( $date_data ) ) {
1135
-				list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data;
1134
+			if ( ! empty($date_data)) {
1135
+				list($prepared_comment['comment_date'], $prepared_comment['comment_date_gmt']) = $date_data;
1136 1136
 			}
1137 1137
 		}
1138 1138
 
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
 		 * @param array           $prepared_comment The prepared comment data for `wp_insert_comment`.
1147 1147
 		 * @param WP_REST_Request $request          The current request.
1148 1148
 		 */
1149
-		return apply_filters( 'rest_preprocess_comment', $prepared_comment, $request );
1149
+		return apply_filters('rest_preprocess_comment', $prepared_comment, $request);
1150 1150
 	}
1151 1151
 
1152 1152
 	/**
@@ -1164,141 +1164,141 @@  discard block
 block discarded – undo
1164 1164
 			'type'                 => 'object',
1165 1165
 			'properties'           => array(
1166 1166
 				'id'               => array(
1167
-					'description'  => __( 'Unique identifier for the object.' ),
1167
+					'description'  => __('Unique identifier for the object.'),
1168 1168
 					'type'         => 'integer',
1169
-					'context'      => array( 'view', 'edit', 'embed' ),
1169
+					'context'      => array('view', 'edit', 'embed'),
1170 1170
 					'readonly'     => true,
1171 1171
 				),
1172 1172
 				'author'           => array(
1173
-					'description'  => __( 'The ID of the user object, if author was a user.' ),
1173
+					'description'  => __('The ID of the user object, if author was a user.'),
1174 1174
 					'type'         => 'integer',
1175
-					'context'      => array( 'view', 'edit', 'embed' ),
1175
+					'context'      => array('view', 'edit', 'embed'),
1176 1176
 				),
1177 1177
 				'author_email'     => array(
1178
-					'description'  => __( 'Email address for the object author.' ),
1178
+					'description'  => __('Email address for the object author.'),
1179 1179
 					'type'         => 'string',
1180 1180
 					'format'       => 'email',
1181
-					'context'      => array( 'edit' ),
1181
+					'context'      => array('edit'),
1182 1182
 					'arg_options'  => array(
1183
-						'sanitize_callback' => array( $this, 'check_comment_author_email' ),
1183
+						'sanitize_callback' => array($this, 'check_comment_author_email'),
1184 1184
 						'validate_callback' => null, // skip built-in validation of 'email'.
1185 1185
 					),
1186 1186
 				),
1187 1187
 				'author_ip'     => array(
1188
-					'description'  => __( 'IP address for the object author.' ),
1188
+					'description'  => __('IP address for the object author.'),
1189 1189
 					'type'         => 'string',
1190 1190
 					'format'       => 'ip',
1191
-					'context'      => array( 'edit' ),
1191
+					'context'      => array('edit'),
1192 1192
 				),
1193 1193
 				'author_name'     => array(
1194
-					'description'  => __( 'Display name for the object author.' ),
1194
+					'description'  => __('Display name for the object author.'),
1195 1195
 					'type'         => 'string',
1196
-					'context'      => array( 'view', 'edit', 'embed' ),
1196
+					'context'      => array('view', 'edit', 'embed'),
1197 1197
 					'arg_options'  => array(
1198 1198
 						'sanitize_callback' => 'sanitize_text_field',
1199 1199
 					),
1200 1200
 				),
1201 1201
 				'author_url'       => array(
1202
-					'description'  => __( 'URL for the object author.' ),
1202
+					'description'  => __('URL for the object author.'),
1203 1203
 					'type'         => 'string',
1204 1204
 					'format'       => 'uri',
1205
-					'context'      => array( 'view', 'edit', 'embed' ),
1205
+					'context'      => array('view', 'edit', 'embed'),
1206 1206
 				),
1207 1207
 				'author_user_agent'     => array(
1208
-					'description'  => __( 'User agent for the object author.' ),
1208
+					'description'  => __('User agent for the object author.'),
1209 1209
 					'type'         => 'string',
1210
-					'context'      => array( 'edit' ),
1210
+					'context'      => array('edit'),
1211 1211
 					'arg_options'  => array(
1212 1212
 						'sanitize_callback' => 'sanitize_text_field',
1213 1213
 					),
1214 1214
 				),
1215 1215
 				'content'          => array(
1216
-					'description'     => __( 'The content for the object.' ),
1216
+					'description'     => __('The content for the object.'),
1217 1217
 					'type'            => 'object',
1218
-					'context'         => array( 'view', 'edit', 'embed' ),
1218
+					'context'         => array('view', 'edit', 'embed'),
1219 1219
 					'arg_options'     => array(
1220 1220
 						'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
1221 1221
 					),
1222 1222
 					'properties'      => array(
1223 1223
 						'raw'         => array(
1224
-							'description'     => __( 'Content for the object, as it exists in the database.' ),
1224
+							'description'     => __('Content for the object, as it exists in the database.'),
1225 1225
 							'type'            => 'string',
1226
-							'context'         => array( 'edit' ),
1226
+							'context'         => array('edit'),
1227 1227
 						),
1228 1228
 						'rendered'    => array(
1229
-							'description'     => __( 'HTML content for the object, transformed for display.' ),
1229
+							'description'     => __('HTML content for the object, transformed for display.'),
1230 1230
 							'type'            => 'string',
1231
-							'context'         => array( 'view', 'edit', 'embed' ),
1231
+							'context'         => array('view', 'edit', 'embed'),
1232 1232
 							'readonly'        => true,
1233 1233
 						),
1234 1234
 					),
1235 1235
 				),
1236 1236
 				'date'             => array(
1237
-					'description'  => __( "The date the object was published, in the site's timezone." ),
1237
+					'description'  => __("The date the object was published, in the site's timezone."),
1238 1238
 					'type'         => 'string',
1239 1239
 					'format'       => 'date-time',
1240
-					'context'      => array( 'view', 'edit', 'embed' ),
1240
+					'context'      => array('view', 'edit', 'embed'),
1241 1241
 				),
1242 1242
 				'date_gmt'         => array(
1243
-					'description'  => __( 'The date the object was published, as GMT.' ),
1243
+					'description'  => __('The date the object was published, as GMT.'),
1244 1244
 					'type'         => 'string',
1245 1245
 					'format'       => 'date-time',
1246
-					'context'      => array( 'view', 'edit' ),
1246
+					'context'      => array('view', 'edit'),
1247 1247
 				),
1248 1248
 				'link'             => array(
1249
-					'description'  => __( 'URL to the object.' ),
1249
+					'description'  => __('URL to the object.'),
1250 1250
 					'type'         => 'string',
1251 1251
 					'format'       => 'uri',
1252
-					'context'      => array( 'view', 'edit', 'embed' ),
1252
+					'context'      => array('view', 'edit', 'embed'),
1253 1253
 					'readonly'     => true,
1254 1254
 				),
1255 1255
 				'parent'           => array(
1256
-					'description'  => __( 'The ID for the parent of the object.' ),
1256
+					'description'  => __('The ID for the parent of the object.'),
1257 1257
 					'type'         => 'integer',
1258
-					'context'      => array( 'view', 'edit', 'embed' ),
1258
+					'context'      => array('view', 'edit', 'embed'),
1259 1259
 					'default'      => 0,
1260 1260
 				),
1261 1261
 				'post'             => array(
1262
-					'description'  => __( 'The ID of the associated post object.' ),
1262
+					'description'  => __('The ID of the associated post object.'),
1263 1263
 					'type'         => 'integer',
1264
-					'context'      => array( 'view', 'edit' ),
1264
+					'context'      => array('view', 'edit'),
1265 1265
 					'default'      => 0,
1266 1266
 				),
1267 1267
 				'status'           => array(
1268
-					'description'  => __( 'State of the object.' ),
1268
+					'description'  => __('State of the object.'),
1269 1269
 					'type'         => 'string',
1270
-					'context'      => array( 'view', 'edit' ),
1270
+					'context'      => array('view', 'edit'),
1271 1271
 					'arg_options'  => array(
1272 1272
 						'sanitize_callback' => 'sanitize_key',
1273 1273
 					),
1274 1274
 				),
1275 1275
 				'type'             => array(
1276
-					'description'  => __( 'Type of Comment for the object.' ),
1276
+					'description'  => __('Type of Comment for the object.'),
1277 1277
 					'type'         => 'string',
1278
-					'context'      => array( 'view', 'edit', 'embed' ),
1278
+					'context'      => array('view', 'edit', 'embed'),
1279 1279
 					'readonly'     => true,
1280 1280
 				),
1281 1281
 			),
1282 1282
 		);
1283 1283
 
1284
-		if ( get_option( 'show_avatars' ) ) {
1284
+		if (get_option('show_avatars')) {
1285 1285
 			$avatar_properties = array();
1286 1286
 
1287 1287
 			$avatar_sizes = rest_get_avatar_sizes();
1288
-			foreach ( $avatar_sizes as $size ) {
1289
-				$avatar_properties[ $size ] = array(
1288
+			foreach ($avatar_sizes as $size) {
1289
+				$avatar_properties[$size] = array(
1290 1290
 					/* translators: %d: avatar image size in pixels */
1291
-					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ),
1291
+					'description' => sprintf(__('Avatar URL with image size of %d pixels.'), $size),
1292 1292
 					'type'        => 'string',
1293 1293
 					'format'      => 'uri',
1294
-					'context'     => array( 'embed', 'view', 'edit' ),
1294
+					'context'     => array('embed', 'view', 'edit'),
1295 1295
 				);
1296 1296
 			}
1297 1297
 
1298 1298
 			$schema['properties']['author_avatar_urls'] = array(
1299
-				'description'   => __( 'Avatar URLs for the object author.' ),
1299
+				'description'   => __('Avatar URLs for the object author.'),
1300 1300
 				'type'          => 'object',
1301
-				'context'       => array( 'view', 'edit', 'embed' ),
1301
+				'context'       => array('view', 'edit', 'embed'),
1302 1302
 				'readonly'      => true,
1303 1303
 				'properties'    => $avatar_properties,
1304 1304
 			);
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 
1307 1307
 		$schema['properties']['meta'] = $this->meta->get_field_schema();
1308 1308
 
1309
-		return $this->add_additional_fields_schema( $schema );
1309
+		return $this->add_additional_fields_schema($schema);
1310 1310
 	}
1311 1311
 
1312 1312
 	/**
@@ -1323,13 +1323,13 @@  discard block
 block discarded – undo
1323 1323
 		$query_params['context']['default'] = 'view';
1324 1324
 
1325 1325
 		$query_params['after'] = array(
1326
-			'description'       => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
1326
+			'description'       => __('Limit response to comments published after a given ISO8601 compliant date.'),
1327 1327
 			'type'              => 'string',
1328 1328
 			'format'            => 'date-time',
1329 1329
 		);
1330 1330
 
1331 1331
 		$query_params['author'] = array(
1332
-			'description'       => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
1332
+			'description'       => __('Limit result set to comments assigned to specific user IDs. Requires authorization.'),
1333 1333
 			'type'              => 'array',
1334 1334
 			'items'             => array(
1335 1335
 				'type'          => 'integer',
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
 		);
1338 1338
 
1339 1339
 		$query_params['author_exclude'] = array(
1340
-			'description'       => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
1340
+			'description'       => __('Ensure result set excludes comments assigned to specific user IDs. Requires authorization.'),
1341 1341
 			'type'              => 'array',
1342 1342
 			'items'             => array(
1343 1343
 				'type'          => 'integer',
@@ -1346,19 +1346,19 @@  discard block
 block discarded – undo
1346 1346
 
1347 1347
 		$query_params['author_email'] = array(
1348 1348
 			'default'           => null,
1349
-			'description'       => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
1349
+			'description'       => __('Limit result set to that from a specific author email. Requires authorization.'),
1350 1350
 			'format'            => 'email',
1351 1351
 			'type'              => 'string',
1352 1352
 		);
1353 1353
 
1354 1354
 		$query_params['before'] = array(
1355
-			'description'       => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
1355
+			'description'       => __('Limit response to comments published before a given ISO8601 compliant date.'),
1356 1356
 			'type'              => 'string',
1357 1357
 			'format'            => 'date-time',
1358 1358
 		);
1359 1359
 
1360 1360
 		$query_params['exclude'] = array(
1361
-			'description'        => __( 'Ensure result set excludes specific IDs.' ),
1361
+			'description'        => __('Ensure result set excludes specific IDs.'),
1362 1362
 			'type'               => 'array',
1363 1363
 			'items'              => array(
1364 1364
 				'type'           => 'integer',
@@ -1367,7 +1367,7 @@  discard block
 block discarded – undo
1367 1367
 		);
1368 1368
 
1369 1369
 		$query_params['include'] = array(
1370
-			'description'        => __( 'Limit result set to specific IDs.' ),
1370
+			'description'        => __('Limit result set to specific IDs.'),
1371 1371
 			'type'               => 'array',
1372 1372
 			'items'              => array(
1373 1373
 				'type'           => 'integer',
@@ -1376,12 +1376,12 @@  discard block
 block discarded – undo
1376 1376
 		);
1377 1377
 
1378 1378
 		$query_params['offset'] = array(
1379
-			'description'        => __( 'Offset the result set by a specific number of items.' ),
1379
+			'description'        => __('Offset the result set by a specific number of items.'),
1380 1380
 			'type'               => 'integer',
1381 1381
 		);
1382 1382
 
1383
-		$query_params['order']      = array(
1384
-			'description'           => __( 'Order sort attribute ascending or descending.' ),
1383
+		$query_params['order'] = array(
1384
+			'description'           => __('Order sort attribute ascending or descending.'),
1385 1385
 			'type'                  => 'string',
1386 1386
 			'default'               => 'desc',
1387 1387
 			'enum'                  => array(
@@ -1390,8 +1390,8 @@  discard block
 block discarded – undo
1390 1390
 			),
1391 1391
 		);
1392 1392
 
1393
-		$query_params['orderby']    = array(
1394
-			'description'           => __( 'Sort collection by object attribute.' ),
1393
+		$query_params['orderby'] = array(
1394
+			'description'           => __('Sort collection by object attribute.'),
1395 1395
 			'type'                  => 'string',
1396 1396
 			'default'               => 'date_gmt',
1397 1397
 			'enum'                  => array(
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
 
1408 1408
 		$query_params['parent'] = array(
1409 1409
 			'default'           => array(),
1410
-			'description'       => __( 'Limit result set to comments of specific parent IDs.' ),
1410
+			'description'       => __('Limit result set to comments of specific parent IDs.'),
1411 1411
 			'type'              => 'array',
1412 1412
 			'items'             => array(
1413 1413
 				'type'          => 'integer',
@@ -1416,16 +1416,16 @@  discard block
 block discarded – undo
1416 1416
 
1417 1417
 		$query_params['parent_exclude'] = array(
1418 1418
 			'default'           => array(),
1419
-			'description'       => __( 'Ensure result set excludes specific parent IDs.' ),
1419
+			'description'       => __('Ensure result set excludes specific parent IDs.'),
1420 1420
 			'type'              => 'array',
1421 1421
 			'items'             => array(
1422 1422
 				'type'          => 'integer',
1423 1423
 			),
1424 1424
 		);
1425 1425
 
1426
-		$query_params['post']   = array(
1426
+		$query_params['post'] = array(
1427 1427
 			'default'           => array(),
1428
-			'description'       => __( 'Limit result set to comments assigned to specific post IDs.' ),
1428
+			'description'       => __('Limit result set to comments assigned to specific post IDs.'),
1429 1429
 			'type'              => 'array',
1430 1430
 			'items'             => array(
1431 1431
 				'type'          => 'integer',
@@ -1434,7 +1434,7 @@  discard block
 block discarded – undo
1434 1434
 
1435 1435
 		$query_params['status'] = array(
1436 1436
 			'default'           => 'approve',
1437
-			'description'       => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ),
1437
+			'description'       => __('Limit result set to comments assigned a specific status. Requires authorization.'),
1438 1438
 			'sanitize_callback' => 'sanitize_key',
1439 1439
 			'type'              => 'string',
1440 1440
 			'validate_callback' => 'rest_validate_request_arg',
@@ -1442,14 +1442,14 @@  discard block
 block discarded – undo
1442 1442
 
1443 1443
 		$query_params['type'] = array(
1444 1444
 			'default'           => 'comment',
1445
-			'description'       => __( 'Limit result set to comments assigned a specific type. Requires authorization.' ),
1445
+			'description'       => __('Limit result set to comments assigned a specific type. Requires authorization.'),
1446 1446
 			'sanitize_callback' => 'sanitize_key',
1447 1447
 			'type'              => 'string',
1448 1448
 			'validate_callback' => 'rest_validate_request_arg',
1449 1449
 		);
1450 1450
 
1451 1451
 		$query_params['password'] = array(
1452
-			'description' => __( 'The password for the post if it is password protected.' ),
1452
+			'description' => __('The password for the post if it is password protected.'),
1453 1453
 			'type'        => 'string',
1454 1454
 		);
1455 1455
 
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
 		 *
1465 1465
 		 * @param array $query_params JSON Schema-formatted collection parameters.
1466 1466
 		 */
1467
-		return apply_filters( 'rest_comment_collection_params', $query_params );
1467
+		return apply_filters('rest_comment_collection_params', $query_params);
1468 1468
 	}
1469 1469
 
1470 1470
 	/**
@@ -1477,34 +1477,34 @@  discard block
 block discarded – undo
1477 1477
 	 * @param int        $comment_id Comment ID.
1478 1478
 	 * @return bool Whether the status was changed.
1479 1479
 	 */
1480
-	protected function handle_status_param( $new_status, $comment_id ) {
1481
-		$old_status = wp_get_comment_status( $comment_id );
1480
+	protected function handle_status_param($new_status, $comment_id) {
1481
+		$old_status = wp_get_comment_status($comment_id);
1482 1482
 
1483
-		if ( $new_status === $old_status ) {
1483
+		if ($new_status === $old_status) {
1484 1484
 			return false;
1485 1485
 		}
1486 1486
 
1487
-		switch ( $new_status ) {
1487
+		switch ($new_status) {
1488 1488
 			case 'approved' :
1489 1489
 			case 'approve':
1490 1490
 			case '1':
1491
-				$changed = wp_set_comment_status( $comment_id, 'approve' );
1491
+				$changed = wp_set_comment_status($comment_id, 'approve');
1492 1492
 				break;
1493 1493
 			case 'hold':
1494 1494
 			case '0':
1495
-				$changed = wp_set_comment_status( $comment_id, 'hold' );
1495
+				$changed = wp_set_comment_status($comment_id, 'hold');
1496 1496
 				break;
1497 1497
 			case 'spam' :
1498
-				$changed = wp_spam_comment( $comment_id );
1498
+				$changed = wp_spam_comment($comment_id);
1499 1499
 				break;
1500 1500
 			case 'unspam' :
1501
-				$changed = wp_unspam_comment( $comment_id );
1501
+				$changed = wp_unspam_comment($comment_id);
1502 1502
 				break;
1503 1503
 			case 'trash' :
1504
-				$changed = wp_trash_comment( $comment_id );
1504
+				$changed = wp_trash_comment($comment_id);
1505 1505
 				break;
1506 1506
 			case 'untrash' :
1507
-				$changed = wp_untrash_comment( $comment_id );
1507
+				$changed = wp_untrash_comment($comment_id);
1508 1508
 				break;
1509 1509
 			default :
1510 1510
 				$changed = false;
@@ -1526,29 +1526,29 @@  discard block
 block discarded – undo
1526 1526
 	 * @param WP_REST_Request $request Request data to check.
1527 1527
 	 * @return bool Whether post can be read.
1528 1528
 	 */
1529
-	protected function check_read_post_permission( $post, $request ) {
1530
-		$posts_controller = new WP_REST_Posts_Controller( $post->post_type );
1531
-		$post_type = get_post_type_object( $post->post_type );
1529
+	protected function check_read_post_permission($post, $request) {
1530
+		$posts_controller = new WP_REST_Posts_Controller($post->post_type);
1531
+		$post_type = get_post_type_object($post->post_type);
1532 1532
 
1533 1533
 		$has_password_filter = false;
1534 1534
 
1535 1535
 		// Only check password if a specific post was queried for or a single comment
1536
-		$requested_post = ! empty( $request['post'] ) && 1 === count( $request['post'] );
1537
-		$requested_comment = ! empty( $request['id'] );
1538
-		if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) {
1539
-			add_filter( 'post_password_required', '__return_false' );
1536
+		$requested_post = ! empty($request['post']) && 1 === count($request['post']);
1537
+		$requested_comment = ! empty($request['id']);
1538
+		if (($requested_post || $requested_comment) && $posts_controller->can_access_password_content($post, $request)) {
1539
+			add_filter('post_password_required', '__return_false');
1540 1540
 
1541 1541
 			$has_password_filter = true;
1542 1542
 		}
1543 1543
 
1544
-		if ( post_password_required( $post ) ) {
1545
-			$result = current_user_can( $post_type->cap->edit_post, $post->ID );
1544
+		if (post_password_required($post)) {
1545
+			$result = current_user_can($post_type->cap->edit_post, $post->ID);
1546 1546
 		} else {
1547
-			$result = $posts_controller->check_read_permission( $post );
1547
+			$result = $posts_controller->check_read_permission($post);
1548 1548
 		}
1549 1549
 
1550
-		if ( $has_password_filter ) {
1551
-			remove_filter( 'post_password_required', '__return_false' );
1550
+		if ($has_password_filter) {
1551
+			remove_filter('post_password_required', '__return_false');
1552 1552
 		}
1553 1553
 
1554 1554
 		return $result;
@@ -1564,29 +1564,29 @@  discard block
 block discarded – undo
1564 1564
 	 * @param WP_REST_Request $request Request data to check.
1565 1565
 	 * @return bool Whether the comment can be read.
1566 1566
 	 */
1567
-	protected function check_read_permission( $comment, $request ) {
1568
-		if ( ! empty( $comment->comment_post_ID ) ) {
1569
-			$post = get_post( $comment->comment_post_ID );
1570
-			if ( $post ) {
1571
-				if ( $this->check_read_post_permission( $post, $request ) && 1 === (int) $comment->comment_approved ) {
1567
+	protected function check_read_permission($comment, $request) {
1568
+		if ( ! empty($comment->comment_post_ID)) {
1569
+			$post = get_post($comment->comment_post_ID);
1570
+			if ($post) {
1571
+				if ($this->check_read_post_permission($post, $request) && 1 === (int) $comment->comment_approved) {
1572 1572
 					return true;
1573 1573
 				}
1574 1574
 			}
1575 1575
 		}
1576 1576
 
1577
-		if ( 0 === get_current_user_id() ) {
1577
+		if (0 === get_current_user_id()) {
1578 1578
 			return false;
1579 1579
 		}
1580 1580
 
1581
-		if ( empty( $comment->comment_post_ID ) && ! current_user_can( 'moderate_comments' ) ) {
1581
+		if (empty($comment->comment_post_ID) && ! current_user_can('moderate_comments')) {
1582 1582
 			return false;
1583 1583
 		}
1584 1584
 
1585
-		if ( ! empty( $comment->user_id ) && get_current_user_id() === (int) $comment->user_id ) {
1585
+		if ( ! empty($comment->user_id) && get_current_user_id() === (int) $comment->user_id) {
1586 1586
 			return true;
1587 1587
 		}
1588 1588
 
1589
-		return current_user_can( 'edit_comment', $comment->comment_ID );
1589
+		return current_user_can('edit_comment', $comment->comment_ID);
1590 1590
 	}
1591 1591
 
1592 1592
 	/**
@@ -1598,16 +1598,16 @@  discard block
 block discarded – undo
1598 1598
 	 * @param object $comment Comment object.
1599 1599
 	 * @return bool Whether the comment can be edited or deleted.
1600 1600
 	 */
1601
-	protected function check_edit_permission( $comment ) {
1602
-		if ( 0 === (int) get_current_user_id() ) {
1601
+	protected function check_edit_permission($comment) {
1602
+		if (0 === (int) get_current_user_id()) {
1603 1603
 			return false;
1604 1604
 		}
1605 1605
 
1606
-		if ( ! current_user_can( 'moderate_comments' ) ) {
1606
+		if ( ! current_user_can('moderate_comments')) {
1607 1607
 			return false;
1608 1608
 		}
1609 1609
 
1610
-		return current_user_can( 'edit_comment', $comment->comment_ID );
1610
+		return current_user_can('edit_comment', $comment->comment_ID);
1611 1611
 	}
1612 1612
 
1613 1613
 	/**
@@ -1626,14 +1626,14 @@  discard block
 block discarded – undo
1626 1626
 	 * @return WP_Error|string The sanitized email address, if valid,
1627 1627
 	 *                         otherwise an error.
1628 1628
 	 */
1629
-	public function check_comment_author_email( $value, $request, $param ) {
1629
+	public function check_comment_author_email($value, $request, $param) {
1630 1630
 		$email = (string) $value;
1631
-		if ( empty( $email ) ) {
1631
+		if (empty($email)) {
1632 1632
 			return $email;
1633 1633
 		}
1634 1634
 
1635
-		$check_email = rest_validate_request_arg( $email, $request, $param );
1636
-		if ( is_wp_error( $check_email ) ) {
1635
+		$check_email = rest_validate_request_arg($email, $request, $param);
1636
+		if (is_wp_error($check_email)) {
1637 1637
 			return $check_email;
1638 1638
 		}
1639 1639
 
Please login to merge, or discard this patch.
src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@
 block discarded – undo
179 179
 	 * @access public
180 180
 	 *
181 181
 	 * @param WP_REST_Request $request Request object.
182
-	 * @return WP_Error|object The prepared item, or WP_Error object on failure.
182
+	 * @return WP_Error The prepared item, or WP_Error object on failure.
183 183
 	 */
184 184
 	protected function prepare_item_for_database( $request ) {
185 185
 		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @access public
40 40
 	 */
41 41
 	public function register_routes() {
42
-		_doing_it_wrong( 'WP_REST_Controller::register_routes', __( 'The register_routes() method must be overridden' ), '4.7' );
42
+		_doing_it_wrong('WP_REST_Controller::register_routes', __('The register_routes() method must be overridden'), '4.7');
43 43
 	}
44 44
 
45 45
 	/**
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * @param WP_REST_Request $request Full data about the request.
52 52
 	 * @return WP_Error|bool True if the request has read access, WP_Error object otherwise.
53 53
 	 */
54
-	public function get_items_permissions_check( $request ) {
55
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
54
+	public function get_items_permissions_check($request) {
55
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
56 56
 	}
57 57
 
58 58
 	/**
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 	 * @param WP_REST_Request $request Full data about the request.
65 65
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
66 66
 	 */
67
-	public function get_items( $request ) {
68
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
67
+	public function get_items($request) {
68
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
69 69
 	}
70 70
 
71 71
 	/**
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	 * @param WP_REST_Request $request Full data about the request.
78 78
 	 * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise.
79 79
 	 */
80
-	public function get_item_permissions_check( $request ) {
81
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
80
+	public function get_item_permissions_check($request) {
81
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
82 82
 	}
83 83
 
84 84
 	/**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @param WP_REST_Request $request Full data about the request.
91 91
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
92 92
 	 */
93
-	public function get_item( $request ) {
94
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
93
+	public function get_item($request) {
94
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
95 95
 	}
96 96
 
97 97
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 * @param WP_REST_Request $request Full data about the request.
104 104
 	 * @return WP_Error|bool True if the request has access to create items, WP_Error object otherwise.
105 105
 	 */
106
-	public function create_item_permissions_check( $request ) {
107
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
106
+	public function create_item_permissions_check($request) {
107
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
108 108
 	}
109 109
 
110 110
 	/**
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 	 * @param WP_REST_Request $request Full data about the request.
117 117
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
118 118
 	 */
119
-	public function create_item( $request ) {
120
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
119
+	public function create_item($request) {
120
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
121 121
 	}
122 122
 
123 123
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @param WP_REST_Request $request Full data about the request.
130 130
 	 * @return WP_Error|bool True if the request has access to update the item, WP_Error object otherwise.
131 131
 	 */
132
-	public function update_item_permissions_check( $request ) {
133
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
132
+	public function update_item_permissions_check($request) {
133
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
134 134
 	}
135 135
 
136 136
 	/**
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @param WP_REST_Request $request Full data about the request.
143 143
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
144 144
 	 */
145
-	public function update_item( $request ) {
146
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
145
+	public function update_item($request) {
146
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
147 147
 	}
148 148
 
149 149
 	/**
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 * @param WP_REST_Request $request Full data about the request.
156 156
 	 * @return WP_Error|bool True if the request has access to delete the item, WP_Error object otherwise.
157 157
 	 */
158
-	public function delete_item_permissions_check( $request ) {
159
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
158
+	public function delete_item_permissions_check($request) {
159
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
160 160
 	}
161 161
 
162 162
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param WP_REST_Request $request Full data about the request.
169 169
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
170 170
 	 */
171
-	public function delete_item( $request ) {
172
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
171
+	public function delete_item($request) {
172
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
173 173
 	}
174 174
 
175 175
 	/**
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 	 * @param WP_REST_Request $request Request object.
182 182
 	 * @return WP_Error|object The prepared item, or WP_Error object on failure.
183 183
 	 */
184
-	protected function prepare_item_for_database( $request ) {
185
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
184
+	protected function prepare_item_for_database($request) {
185
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
186 186
 	}
187 187
 
188 188
 	/**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param WP_REST_Request $request Request object.
196 196
 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
197 197
 	 */
198
-	public function prepare_item_for_response( $item, $request ) {
199
-		return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
198
+	public function prepare_item_for_response($item, $request) {
199
+		return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array('status' => 405));
200 200
 	}
201 201
 
202 202
 	/**
@@ -208,21 +208,21 @@  discard block
 block discarded – undo
208 208
 	 * @param WP_REST_Response $response Response object.
209 209
 	 * @return array|mixed Response data, ready for insertion into collection data.
210 210
 	 */
211
-	public function prepare_response_for_collection( $response ) {
212
-		if ( ! ( $response instanceof WP_REST_Response ) ) {
211
+	public function prepare_response_for_collection($response) {
212
+		if ( ! ($response instanceof WP_REST_Response)) {
213 213
 			return $response;
214 214
 		}
215 215
 
216 216
 		$data   = (array) $response->get_data();
217 217
 		$server = rest_get_server();
218 218
 
219
-		if ( method_exists( $server, 'get_compact_response_links' ) ) {
220
-			$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
219
+		if (method_exists($server, 'get_compact_response_links')) {
220
+			$links = call_user_func(array($server, 'get_compact_response_links'), $response);
221 221
 		} else {
222
-			$links = call_user_func( array( $server, 'get_response_links' ), $response );
222
+			$links = call_user_func(array($server, 'get_response_links'), $response);
223 223
 		}
224 224
 
225
-		if ( ! empty( $links ) ) {
225
+		if ( ! empty($links)) {
226 226
 			$data['_links'] = $links;
227 227
 		}
228 228
 
@@ -239,29 +239,29 @@  discard block
 block discarded – undo
239 239
 	 * @param string $context Context defined in the schema.
240 240
 	 * @return array Filtered response.
241 241
 	 */
242
-	public function filter_response_by_context( $data, $context ) {
242
+	public function filter_response_by_context($data, $context) {
243 243
 
244 244
 		$schema = $this->get_item_schema();
245 245
 
246
-		foreach ( $data as $key => $value ) {
247
-			if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
246
+		foreach ($data as $key => $value) {
247
+			if (empty($schema['properties'][$key]) || empty($schema['properties'][$key]['context'])) {
248 248
 				continue;
249 249
 			}
250 250
 
251
-			if ( ! in_array( $context, $schema['properties'][ $key ]['context'], true ) ) {
252
-				unset( $data[ $key ] );
251
+			if ( ! in_array($context, $schema['properties'][$key]['context'], true)) {
252
+				unset($data[$key]);
253 253
 				continue;
254 254
 			}
255 255
 
256
-			if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) {
257
-				foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) {
258
-					if ( empty( $details['context'] ) ) {
256
+			if ('object' === $schema['properties'][$key]['type'] && ! empty($schema['properties'][$key]['properties'])) {
257
+				foreach ($schema['properties'][$key]['properties'] as $attribute => $details) {
258
+					if (empty($details['context'])) {
259 259
 						continue;
260 260
 					}
261 261
 
262
-					if ( ! in_array( $context, $details['context'], true ) ) {
263
-						if ( isset( $data[ $key ][ $attribute ] ) ) {
264
-							unset( $data[ $key ][ $attribute ] );
262
+					if ( ! in_array($context, $details['context'], true)) {
263
+						if (isset($data[$key][$attribute])) {
264
+							unset($data[$key][$attribute]);
265 265
 						}
266 266
 					}
267 267
 				}
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 * @return array Item schema data.
281 281
 	 */
282 282
 	public function get_item_schema() {
283
-		return $this->add_additional_fields_schema( array() );
283
+		return $this->add_additional_fields_schema(array());
284 284
 	}
285 285
 
286 286
 	/**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 
296 296
 		$schema = $this->get_item_schema();
297 297
 
298
-		foreach ( $schema['properties'] as &$property ) {
299
-			unset( $property['arg_options'] );
298
+		foreach ($schema['properties'] as &$property) {
299
+			unset($property['arg_options']);
300 300
 		}
301 301
 
302 302
 		return $schema;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 		return array(
315 315
 			'context'                => $this->get_context_param(),
316 316
 			'page'                   => array(
317
-				'description'        => __( 'Current page of the collection.' ),
317
+				'description'        => __('Current page of the collection.'),
318 318
 				'type'               => 'integer',
319 319
 				'default'            => 1,
320 320
 				'sanitize_callback'  => 'absint',
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 				'minimum'            => 1,
323 323
 			),
324 324
 			'per_page'               => array(
325
-				'description'        => __( 'Maximum number of items to be returned in result set.' ),
325
+				'description'        => __('Maximum number of items to be returned in result set.'),
326 326
 				'type'               => 'integer',
327 327
 				'default'            => 10,
328 328
 				'minimum'            => 1,
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 				'validate_callback'  => 'rest_validate_request_arg',
332 332
 			),
333 333
 			'search'                 => array(
334
-				'description'        => __( 'Limit results to those matching a string.' ),
334
+				'description'        => __('Limit results to those matching a string.'),
335 335
 				'type'               => 'string',
336 336
 				'sanitize_callback'  => 'sanitize_text_field',
337 337
 				'validate_callback'  => 'rest_validate_request_arg',
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	 * @param array $args Optional. Additional arguments for context parameter. Default empty array.
351 351
 	 * @return array Context parameter details.
352 352
 	 */
353
-	public function get_context_param( $args = array() ) {
353
+	public function get_context_param($args = array()) {
354 354
 		$param_details = array(
355
-			'description'        => __( 'Scope under which the request is made; determines fields present in response.' ),
355
+			'description'        => __('Scope under which the request is made; determines fields present in response.'),
356 356
 			'type'               => 'string',
357 357
 			'sanitize_callback'  => 'sanitize_key',
358 358
 			'validate_callback'  => 'rest_validate_request_arg',
@@ -360,24 +360,24 @@  discard block
 block discarded – undo
360 360
 
361 361
 		$schema = $this->get_item_schema();
362 362
 
363
-		if ( empty( $schema['properties'] ) ) {
364
-			return array_merge( $param_details, $args );
363
+		if (empty($schema['properties'])) {
364
+			return array_merge($param_details, $args);
365 365
 		}
366 366
 
367 367
 		$contexts = array();
368 368
 
369
-		foreach ( $schema['properties'] as $attributes ) {
370
-			if ( ! empty( $attributes['context'] ) ) {
371
-				$contexts = array_merge( $contexts, $attributes['context'] );
369
+		foreach ($schema['properties'] as $attributes) {
370
+			if ( ! empty($attributes['context'])) {
371
+				$contexts = array_merge($contexts, $attributes['context']);
372 372
 			}
373 373
 		}
374 374
 
375
-		if ( ! empty( $contexts ) ) {
376
-			$param_details['enum'] = array_unique( $contexts );
377
-			rsort( $param_details['enum'] );
375
+		if ( ! empty($contexts)) {
376
+			$param_details['enum'] = array_unique($contexts);
377
+			rsort($param_details['enum']);
378 378
 		}
379 379
 
380
-		return array_merge( $param_details, $args );
380
+		return array_merge($param_details, $args);
381 381
 	}
382 382
 
383 383
 	/**
@@ -390,17 +390,17 @@  discard block
 block discarded – undo
390 390
 	 * @param WP_REST_Request $request Full details about the request.
391 391
 	 * @return array Modified data object with additional fields.
392 392
 	 */
393
-	protected function add_additional_fields_to_object( $object, $request ) {
393
+	protected function add_additional_fields_to_object($object, $request) {
394 394
 
395 395
 		$additional_fields = $this->get_additional_fields();
396 396
 
397
-		foreach ( $additional_fields as $field_name => $field_options ) {
397
+		foreach ($additional_fields as $field_name => $field_options) {
398 398
 
399
-			if ( ! $field_options['get_callback'] ) {
399
+			if ( ! $field_options['get_callback']) {
400 400
 				continue;
401 401
 			}
402 402
 
403
-			$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
403
+			$object[$field_name] = call_user_func($field_options['get_callback'], $object, $field_name, $request, $this->get_object_type());
404 404
 		}
405 405
 
406 406
 		return $object;
@@ -416,22 +416,22 @@  discard block
 block discarded – undo
416 416
 	 * @param WP_REST_Request $request Full details about the request.
417 417
 	 * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated.
418 418
 	 */
419
-	protected function update_additional_fields_for_object( $object, $request ) {
419
+	protected function update_additional_fields_for_object($object, $request) {
420 420
 		$additional_fields = $this->get_additional_fields();
421 421
 
422
-		foreach ( $additional_fields as $field_name => $field_options ) {
423
-			if ( ! $field_options['update_callback'] ) {
422
+		foreach ($additional_fields as $field_name => $field_options) {
423
+			if ( ! $field_options['update_callback']) {
424 424
 				continue;
425 425
 			}
426 426
 
427 427
 			// Don't run the update callbacks if the data wasn't passed in the request.
428
-			if ( ! isset( $request[ $field_name ] ) ) {
428
+			if ( ! isset($request[$field_name])) {
429 429
 				continue;
430 430
 			}
431 431
 
432
-			$result = call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() );
432
+			$result = call_user_func($field_options['update_callback'], $request[$field_name], $object, $field_name, $request, $this->get_object_type());
433 433
 
434
-			if ( is_wp_error( $result ) ) {
434
+			if (is_wp_error($result)) {
435 435
 				return $result;
436 436
 			}
437 437
 		}
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 	 * @param array $schema Schema array.
451 451
 	 * @return array Modified Schema array.
452 452
 	 */
453
-	protected function add_additional_fields_schema( $schema ) {
454
-		if ( empty( $schema['title'] ) ) {
453
+	protected function add_additional_fields_schema($schema) {
454
+		if (empty($schema['title'])) {
455 455
 			return $schema;
456 456
 		}
457 457
 
458 458
 		// Can't use $this->get_object_type otherwise we cause an inf loop.
459 459
 		$object_type = $schema['title'];
460 460
 
461
-		$additional_fields = $this->get_additional_fields( $object_type );
461
+		$additional_fields = $this->get_additional_fields($object_type);
462 462
 
463
-		foreach ( $additional_fields as $field_name => $field_options ) {
464
-			if ( ! $field_options['schema'] ) {
463
+		foreach ($additional_fields as $field_name => $field_options) {
464
+			if ( ! $field_options['schema']) {
465 465
 				continue;
466 466
 			}
467 467
 
468
-			$schema['properties'][ $field_name ] = $field_options['schema'];
468
+			$schema['properties'][$field_name] = $field_options['schema'];
469 469
 		}
470 470
 
471 471
 		return $schema;
@@ -481,23 +481,23 @@  discard block
 block discarded – undo
481 481
 	 * @return array Registered additional fields (if any), empty array if none or if the object type could
482 482
 	 *               not be inferred.
483 483
 	 */
484
-	protected function get_additional_fields( $object_type = null ) {
484
+	protected function get_additional_fields($object_type = null) {
485 485
 
486
-		if ( ! $object_type ) {
486
+		if ( ! $object_type) {
487 487
 			$object_type = $this->get_object_type();
488 488
 		}
489 489
 
490
-		if ( ! $object_type ) {
490
+		if ( ! $object_type) {
491 491
 			return array();
492 492
 		}
493 493
 
494 494
 		global $wp_rest_additional_fields;
495 495
 
496
-		if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
496
+		if ( ! $wp_rest_additional_fields || ! isset($wp_rest_additional_fields[$object_type])) {
497 497
 			return array();
498 498
 		}
499 499
 
500
-		return $wp_rest_additional_fields[ $object_type ];
500
+		return $wp_rest_additional_fields[$object_type];
501 501
 	}
502 502
 
503 503
 	/**
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 	protected function get_object_type() {
512 512
 		$schema = $this->get_item_schema();
513 513
 
514
-		if ( ! $schema || ! isset( $schema['title'] ) ) {
514
+		if ( ! $schema || ! isset($schema['title'])) {
515 515
 			return null;
516 516
 		}
517 517
 
@@ -529,51 +529,51 @@  discard block
 block discarded – undo
529 529
 	 *                       on `EDITABLE` requests. Default WP_REST_Server::CREATABLE.
530 530
 	 * @return array Endpoint arguments.
531 531
 	 */
532
-	public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
532
+	public function get_endpoint_args_for_item_schema($method = WP_REST_Server::CREATABLE) {
533 533
 
534 534
 		$schema            = $this->get_item_schema();
535
-		$schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
535
+		$schema_properties = ! empty($schema['properties']) ? $schema['properties'] : array();
536 536
 		$endpoint_args     = array();
537 537
 
538
-		foreach ( $schema_properties as $field_id => $params ) {
538
+		foreach ($schema_properties as $field_id => $params) {
539 539
 
540 540
 			// Arguments specified as `readonly` are not allowed to be set.
541
-			if ( ! empty( $params['readonly'] ) ) {
541
+			if ( ! empty($params['readonly'])) {
542 542
 				continue;
543 543
 			}
544 544
 
545
-			$endpoint_args[ $field_id ] = array(
545
+			$endpoint_args[$field_id] = array(
546 546
 				'validate_callback' => 'rest_validate_request_arg',
547 547
 				'sanitize_callback' => 'rest_sanitize_request_arg',
548 548
 			);
549 549
 
550
-			if ( isset( $params['description'] ) ) {
551
-				$endpoint_args[ $field_id ]['description'] = $params['description'];
550
+			if (isset($params['description'])) {
551
+				$endpoint_args[$field_id]['description'] = $params['description'];
552 552
 			}
553 553
 
554
-			if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
555
-				$endpoint_args[ $field_id ]['default'] = $params['default'];
554
+			if (WP_REST_Server::CREATABLE === $method && isset($params['default'])) {
555
+				$endpoint_args[$field_id]['default'] = $params['default'];
556 556
 			}
557 557
 
558
-			if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) {
559
-				$endpoint_args[ $field_id ]['required'] = true;
558
+			if (WP_REST_Server::CREATABLE === $method && ! empty($params['required'])) {
559
+				$endpoint_args[$field_id]['required'] = true;
560 560
 			}
561 561
 
562
-			foreach ( array( 'type', 'format', 'enum', 'items' ) as $schema_prop ) {
563
-				if ( isset( $params[ $schema_prop ] ) ) {
564
-					$endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ];
562
+			foreach (array('type', 'format', 'enum', 'items') as $schema_prop) {
563
+				if (isset($params[$schema_prop])) {
564
+					$endpoint_args[$field_id][$schema_prop] = $params[$schema_prop];
565 565
 				}
566 566
 			}
567 567
 
568 568
 			// Merge in any options provided by the schema property.
569
-			if ( isset( $params['arg_options'] ) ) {
569
+			if (isset($params['arg_options'])) {
570 570
 
571 571
 				// Only use required / default from arg_options on CREATABLE endpoints.
572
-				if ( WP_REST_Server::CREATABLE !== $method ) {
573
-					$params['arg_options'] = array_diff_key( $params['arg_options'], array( 'required' => '', 'default' => '' ) );
572
+				if (WP_REST_Server::CREATABLE !== $method) {
573
+					$params['arg_options'] = array_diff_key($params['arg_options'], array('required' => '', 'default' => ''));
574 574
 				}
575 575
 
576
-				$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] );
576
+				$endpoint_args[$field_id] = array_merge($endpoint_args[$field_id], $params['arg_options']);
577 577
 			}
578 578
 		}
579 579
 
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 	 * @param string $slug Slug value passed in request.
598 598
 	 * @return string Sanitized value for the slug.
599 599
 	 */
600
-	public function sanitize_slug( $slug ) {
601
-		return sanitize_title( $slug );
600
+	public function sanitize_slug($slug) {
601
+		return sanitize_title($slug);
602 602
 	}
603 603
 }
Please login to merge, or discard this patch.
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 	 * @access protected
1062 1062
 	 *
1063 1063
 	 * @param string $post_status Post status.
1064
-	 * @param object $post_type   Post type.
1064
+	 * @param WP_Post_Type|null $post_type   Post type.
1065 1065
 	 * @return string|WP_Error Post status or WP_Error if lacking the proper permission.
1066 1066
 	 */
1067 1067
 	protected function handle_status_param( $post_status, $post_type ) {
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
 	 * @since 4.7.0
1202 1202
 	 * @access protected
1203 1203
 	 *
1204
-	 * @param object|string $post_type Post type name or object.
1204
+	 * @param WP_Post_Type|null $post_type Post type name or object.
1205 1205
 	 * @return bool Whether the post type is allowed in REST.
1206 1206
 	 */
1207 1207
 	protected function check_is_post_type_allowed( $post_type ) {
Please login to merge, or discard this patch.
Spacing   +577 added lines, -577 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param string $post_type Post type.
44 44
 	 */
45
-	public function __construct( $post_type ) {
45
+	public function __construct($post_type) {
46 46
 		$this->post_type = $post_type;
47 47
 		$this->namespace = 'wp/v2';
48
-		$obj = get_post_type_object( $post_type );
49
-		$this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
48
+		$obj = get_post_type_object($post_type);
49
+		$this->rest_base = ! empty($obj->rest_base) ? $obj->rest_base : $obj->name;
50 50
 
51
-		$this->meta = new WP_REST_Post_Meta_Fields( $this->post_type );
51
+		$this->meta = new WP_REST_Post_Meta_Fields($this->post_type);
52 52
 	}
53 53
 
54 54
 	/**
@@ -61,65 +61,65 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function register_routes() {
63 63
 
64
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
64
+		register_rest_route($this->namespace, '/'.$this->rest_base, array(
65 65
 			array(
66 66
 				'methods'             => WP_REST_Server::READABLE,
67
-				'callback'            => array( $this, 'get_items' ),
68
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
67
+				'callback'            => array($this, 'get_items'),
68
+				'permission_callback' => array($this, 'get_items_permissions_check'),
69 69
 				'args'                => $this->get_collection_params(),
70 70
 			),
71 71
 			array(
72 72
 				'methods'             => WP_REST_Server::CREATABLE,
73
-				'callback'            => array( $this, 'create_item' ),
74
-				'permission_callback' => array( $this, 'create_item_permissions_check' ),
75
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
73
+				'callback'            => array($this, 'create_item'),
74
+				'permission_callback' => array($this, 'create_item_permissions_check'),
75
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
76 76
 			),
77
-			'schema' => array( $this, 'get_public_item_schema' ),
78
-		) );
77
+			'schema' => array($this, 'get_public_item_schema'),
78
+		));
79 79
 
80 80
 		$schema = $this->get_item_schema();
81 81
 		$get_item_args = array(
82
-			'context'  => $this->get_context_param( array( 'default' => 'view' ) ),
82
+			'context'  => $this->get_context_param(array('default' => 'view')),
83 83
 		);
84
-		if ( isset( $schema['properties']['password'] ) ) {
84
+		if (isset($schema['properties']['password'])) {
85 85
 			$get_item_args['password'] = array(
86
-				'description' => __( 'The password for the post if it is password protected.' ),
86
+				'description' => __('The password for the post if it is password protected.'),
87 87
 				'type'        => 'string',
88 88
 			);
89 89
 		}
90
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
90
+		register_rest_route($this->namespace, '/'.$this->rest_base.'/(?P<id>[\d]+)', array(
91 91
 			'args' => array(
92 92
 				'id' => array(
93
-					'description' => __( 'Unique identifier for the object.' ),
93
+					'description' => __('Unique identifier for the object.'),
94 94
 					'type'        => 'integer',
95 95
 				),
96 96
 			),
97 97
 			array(
98 98
 				'methods'             => WP_REST_Server::READABLE,
99
-				'callback'            => array( $this, 'get_item' ),
100
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
99
+				'callback'            => array($this, 'get_item'),
100
+				'permission_callback' => array($this, 'get_item_permissions_check'),
101 101
 				'args'                => $get_item_args,
102 102
 			),
103 103
 			array(
104 104
 				'methods'             => WP_REST_Server::EDITABLE,
105
-				'callback'            => array( $this, 'update_item' ),
106
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
107
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
105
+				'callback'            => array($this, 'update_item'),
106
+				'permission_callback' => array($this, 'update_item_permissions_check'),
107
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
108 108
 			),
109 109
 			array(
110 110
 				'methods'             => WP_REST_Server::DELETABLE,
111
-				'callback'            => array( $this, 'delete_item' ),
112
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
111
+				'callback'            => array($this, 'delete_item'),
112
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
113 113
 				'args'                => array(
114 114
 					'force' => array(
115 115
 						'type'        => 'boolean',
116 116
 						'default'     => false,
117
-						'description' => __( 'Whether to bypass trash and force deletion.' ),
117
+						'description' => __('Whether to bypass trash and force deletion.'),
118 118
 					),
119 119
 				),
120 120
 			),
121
-			'schema' => array( $this, 'get_public_item_schema' ),
122
-		) );
121
+			'schema' => array($this, 'get_public_item_schema'),
122
+		));
123 123
 	}
124 124
 
125 125
 	/**
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	 * @param  WP_REST_Request $request Full details about the request.
132 132
 	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
133 133
 	 */
134
-	public function get_items_permissions_check( $request ) {
134
+	public function get_items_permissions_check($request) {
135 135
 
136
-		$post_type = get_post_type_object( $this->post_type );
136
+		$post_type = get_post_type_object($this->post_type);
137 137
 
138
-		if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) {
139
-			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) );
138
+		if ('edit' === $request['context'] && ! current_user_can($post_type->cap->edit_posts)) {
139
+			return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit posts in this post type.'), array('status' => rest_authorization_required_code()));
140 140
 		}
141 141
 
142 142
 		return true;
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
 	 * @param WP_REST_Request $request Full details about the request.
152 152
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
153 153
 	 */
154
-	public function get_items( $request ) {
154
+	public function get_items($request) {
155 155
 
156 156
 		// Ensure a search string is set in case the orderby is set to 'relevance'.
157
-		if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
158
-			return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
157
+		if ( ! empty($request['orderby']) && 'relevance' === $request['orderby'] && empty($request['search'])) {
158
+			return new WP_Error('rest_no_search_term_defined', __('You need to define a search term to order by relevance.'), array('status' => 400));
159 159
 		}
160 160
 
161 161
 		// Ensure an include parameter is set in case the orderby is set to 'include'.
162
-		if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) {
163
-			return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) );
162
+		if ( ! empty($request['orderby']) && 'include' === $request['orderby'] && empty($request['include'])) {
163
+			return new WP_Error('rest_orderby_include_missing_include', __('You need to define an include parameter to order by include.'), array('status' => 400));
164 164
 		}
165 165
 
166 166
 		// Retrieve the list of registered collection query parameters.
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 		 * For each known parameter which is both registered and present in the request,
195 195
 		 * set the parameter's value on the query $args.
196 196
 		 */
197
-		foreach ( $parameter_mappings as $api_param => $wp_param ) {
198
-			if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
199
-				$args[ $wp_param ] = $request[ $api_param ];
197
+		foreach ($parameter_mappings as $api_param => $wp_param) {
198
+			if (isset($registered[$api_param], $request[$api_param])) {
199
+				$args[$wp_param] = $request[$api_param];
200 200
 			}
201 201
 		}
202 202
 
@@ -204,48 +204,48 @@  discard block
 block discarded – undo
204 204
 		$args['date_query'] = array();
205 205
 
206 206
 		// Set before into date query. Date query must be specified as an array of an array.
207
-		if ( isset( $registered['before'], $request['before'] ) ) {
207
+		if (isset($registered['before'], $request['before'])) {
208 208
 			$args['date_query'][0]['before'] = $request['before'];
209 209
 		}
210 210
 
211 211
 		// Set after into date query. Date query must be specified as an array of an array.
212
-		if ( isset( $registered['after'], $request['after'] ) ) {
212
+		if (isset($registered['after'], $request['after'])) {
213 213
 			$args['date_query'][0]['after'] = $request['after'];
214 214
 		}
215 215
 
216 216
 		// Ensure our per_page parameter overrides any provided posts_per_page filter.
217
-		if ( isset( $registered['per_page'] ) ) {
217
+		if (isset($registered['per_page'])) {
218 218
 			$args['posts_per_page'] = $request['per_page'];
219 219
 		}
220 220
 
221
-		if ( isset( $registered['sticky'], $request['sticky'] ) ) {
222
-			$sticky_posts = get_option( 'sticky_posts', array() );
223
-			if ( ! is_array( $sticky_posts ) ) {
221
+		if (isset($registered['sticky'], $request['sticky'])) {
222
+			$sticky_posts = get_option('sticky_posts', array());
223
+			if ( ! is_array($sticky_posts)) {
224 224
 				$sticky_posts = array();
225 225
 			}
226
-			if ( $request['sticky'] ) {
226
+			if ($request['sticky']) {
227 227
 				/*
228 228
 				 * As post__in will be used to only get sticky posts,
229 229
 				 * we have to support the case where post__in was already
230 230
 				 * specified.
231 231
 				 */
232
-				$args['post__in'] = $args['post__in'] ? array_intersect( $sticky_posts, $args['post__in'] ) : $sticky_posts;
232
+				$args['post__in'] = $args['post__in'] ? array_intersect($sticky_posts, $args['post__in']) : $sticky_posts;
233 233
 
234 234
 				/*
235 235
 				 * If we intersected, but there are no post ids in common,
236 236
 				 * WP_Query won't return "no posts" for post__in = array()
237 237
 				 * so we have to fake it a bit.
238 238
 				 */
239
-				if ( ! $args['post__in'] ) {
240
-					$args['post__in'] = array( 0 );
239
+				if ( ! $args['post__in']) {
240
+					$args['post__in'] = array(0);
241 241
 				}
242
-			} elseif ( $sticky_posts ) {
242
+			} elseif ($sticky_posts) {
243 243
 				/*
244 244
 				 * As post___not_in will be used to only get posts that
245 245
 				 * are not sticky, we have to support the case where post__not_in
246 246
 				 * was already specified.
247 247
 				 */
248
-				$args['post__not_in'] = array_merge( $args['post__not_in'], $sticky_posts );
248
+				$args['post__not_in'] = array_merge($args['post__not_in'], $sticky_posts);
249 249
 			}
250 250
 		}
251 251
 
@@ -264,29 +264,29 @@  discard block
 block discarded – undo
264 264
 		 * @param array           $args    Key value array of query var to query value.
265 265
 		 * @param WP_REST_Request $request The request used.
266 266
 		 */
267
-		$args = apply_filters( "rest_{$this->post_type}_query", $args, $request );
268
-		$query_args = $this->prepare_items_query( $args, $request );
267
+		$args = apply_filters("rest_{$this->post_type}_query", $args, $request);
268
+		$query_args = $this->prepare_items_query($args, $request);
269 269
 
270
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
270
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
271 271
 
272
-		foreach ( $taxonomies as $taxonomy ) {
273
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
274
-			$tax_exclude = $base . '_exclude';
272
+		foreach ($taxonomies as $taxonomy) {
273
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
274
+			$tax_exclude = $base.'_exclude';
275 275
 
276
-			if ( ! empty( $request[ $base ] ) ) {
276
+			if ( ! empty($request[$base])) {
277 277
 				$query_args['tax_query'][] = array(
278 278
 					'taxonomy'         => $taxonomy->name,
279 279
 					'field'            => 'term_id',
280
-					'terms'            => $request[ $base ],
280
+					'terms'            => $request[$base],
281 281
 					'include_children' => false,
282 282
 				);
283 283
 			}
284 284
 
285
-			if ( ! empty( $request[ $tax_exclude ] ) ) {
285
+			if ( ! empty($request[$tax_exclude])) {
286 286
 				$query_args['tax_query'][] = array(
287 287
 					'taxonomy'         => $taxonomy->name,
288 288
 					'field'            => 'term_id',
289
-					'terms'            => $request[ $tax_exclude ],
289
+					'terms'            => $request[$tax_exclude],
290 290
 					'include_children' => false,
291 291
 					'operator'         => 'NOT IN',
292 292
 				);
@@ -294,70 +294,70 @@  discard block
 block discarded – undo
294 294
 		}
295 295
 
296 296
 		$posts_query  = new WP_Query();
297
-		$query_result = $posts_query->query( $query_args );
297
+		$query_result = $posts_query->query($query_args);
298 298
 
299 299
 		// Allow access to all password protected posts if the context is edit.
300
-		if ( 'edit' === $request['context'] ) {
301
-			add_filter( 'post_password_required', '__return_false' );
300
+		if ('edit' === $request['context']) {
301
+			add_filter('post_password_required', '__return_false');
302 302
 		}
303 303
 
304 304
 		$posts = array();
305 305
 
306
-		foreach ( $query_result as $post ) {
307
-			if ( ! $this->check_read_permission( $post ) ) {
306
+		foreach ($query_result as $post) {
307
+			if ( ! $this->check_read_permission($post)) {
308 308
 				continue;
309 309
 			}
310 310
 
311
-			$data    = $this->prepare_item_for_response( $post, $request );
312
-			$posts[] = $this->prepare_response_for_collection( $data );
311
+			$data    = $this->prepare_item_for_response($post, $request);
312
+			$posts[] = $this->prepare_response_for_collection($data);
313 313
 		}
314 314
 
315 315
 		// Reset filter.
316
-		if ( 'edit' === $request['context'] ) {
317
-			remove_filter( 'post_password_required', '__return_false' );
316
+		if ('edit' === $request['context']) {
317
+			remove_filter('post_password_required', '__return_false');
318 318
 		}
319 319
 
320 320
 		$page = (int) $query_args['paged'];
321 321
 		$total_posts = $posts_query->found_posts;
322 322
 
323
-		if ( $total_posts < 1 ) {
323
+		if ($total_posts < 1) {
324 324
 			// Out-of-bounds, run the query again without LIMIT for total count.
325
-			unset( $query_args['paged'] );
325
+			unset($query_args['paged']);
326 326
 
327 327
 			$count_query = new WP_Query();
328
-			$count_query->query( $query_args );
328
+			$count_query->query($query_args);
329 329
 			$total_posts = $count_query->found_posts;
330 330
 		}
331 331
 
332
-		$max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
332
+		$max_pages = ceil($total_posts / (int) $posts_query->query_vars['posts_per_page']);
333 333
 
334
-		if ( $page > $max_pages && $total_posts > 0 ) {
335
-			return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
334
+		if ($page > $max_pages && $total_posts > 0) {
335
+			return new WP_Error('rest_post_invalid_page_number', __('The page number requested is larger than the number of pages available.'), array('status' => 400));
336 336
 		}
337 337
 
338
-		$response  = rest_ensure_response( $posts );
338
+		$response = rest_ensure_response($posts);
339 339
 
340
-		$response->header( 'X-WP-Total', (int) $total_posts );
341
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
340
+		$response->header('X-WP-Total', (int) $total_posts);
341
+		$response->header('X-WP-TotalPages', (int) $max_pages);
342 342
 
343 343
 		$request_params = $request->get_query_params();
344
-		$base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
344
+		$base = add_query_arg($request_params, rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)));
345 345
 
346
-		if ( $page > 1 ) {
346
+		if ($page > 1) {
347 347
 			$prev_page = $page - 1;
348 348
 
349
-			if ( $prev_page > $max_pages ) {
349
+			if ($prev_page > $max_pages) {
350 350
 				$prev_page = $max_pages;
351 351
 			}
352 352
 
353
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
354
-			$response->link_header( 'prev', $prev_link );
353
+			$prev_link = add_query_arg('page', $prev_page, $base);
354
+			$response->link_header('prev', $prev_link);
355 355
 		}
356
-		if ( $max_pages > $page ) {
356
+		if ($max_pages > $page) {
357 357
 			$next_page = $page + 1;
358
-			$next_link = add_query_arg( 'page', $next_page, $base );
358
+			$next_link = add_query_arg('page', $next_page, $base);
359 359
 
360
-			$response->link_header( 'next', $next_link );
360
+			$response->link_header('next', $next_link);
361 361
 		}
362 362
 
363 363
 		return $response;
@@ -371,14 +371,14 @@  discard block
 block discarded – undo
371 371
 	 * @param int $id Supplied ID.
372 372
 	 * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
373 373
 	 */
374
-	protected function get_post( $id ) {
375
-		$error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) );
376
-		if ( (int) $id <= 0 ) {
374
+	protected function get_post($id) {
375
+		$error = new WP_Error('rest_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
376
+		if ((int) $id <= 0) {
377 377
 			return $error;
378 378
 		}
379 379
 
380
-		$post = get_post( (int) $id );
381
-		if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
380
+		$post = get_post((int) $id);
381
+		if (empty($post) || empty($post->ID) || $this->post_type !== $post->post_type) {
382 382
 			return $error;
383 383
 		}
384 384
 
@@ -394,30 +394,30 @@  discard block
 block discarded – undo
394 394
 	 * @param WP_REST_Request $request Full details about the request.
395 395
 	 * @return bool|WP_Error True if the request has read access for the item, WP_Error object otherwise.
396 396
 	 */
397
-	public function get_item_permissions_check( $request ) {
398
-		$post = $this->get_post( $request['id'] );
399
-		if ( is_wp_error( $post ) ) {
397
+	public function get_item_permissions_check($request) {
398
+		$post = $this->get_post($request['id']);
399
+		if (is_wp_error($post)) {
400 400
 			return $post;
401 401
 		}
402 402
 
403
-		if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) {
404
-			return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) );
403
+		if ('edit' === $request['context'] && $post && ! $this->check_update_permission($post)) {
404
+			return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit this post.'), array('status' => rest_authorization_required_code()));
405 405
 		}
406 406
 
407
-		if ( $post && ! empty( $request['password'] ) ) {
407
+		if ($post && ! empty($request['password'])) {
408 408
 			// Check post password, and return error if invalid.
409
-			if ( ! hash_equals( $post->post_password, $request['password'] ) ) {
410
-				return new WP_Error( 'rest_post_incorrect_password', __( 'Incorrect post password.' ), array( 'status' => 403 ) );
409
+			if ( ! hash_equals($post->post_password, $request['password'])) {
410
+				return new WP_Error('rest_post_incorrect_password', __('Incorrect post password.'), array('status' => 403));
411 411
 			}
412 412
 		}
413 413
 
414 414
 		// Allow access to all password protected posts if the context is edit.
415
-		if ( 'edit' === $request['context'] ) {
416
-			add_filter( 'post_password_required', '__return_false' );
415
+		if ('edit' === $request['context']) {
416
+			add_filter('post_password_required', '__return_false');
417 417
 		}
418 418
 
419
-		if ( $post ) {
420
-			return $this->check_read_permission( $post );
419
+		if ($post) {
420
+			return $this->check_read_permission($post);
421 421
 		}
422 422
 
423 423
 		return true;
@@ -436,24 +436,24 @@  discard block
 block discarded – undo
436 436
 	 * @param WP_REST_Request $request Request data to check.
437 437
 	 * @return bool True if the user can access password-protected content, otherwise false.
438 438
 	 */
439
-	public function can_access_password_content( $post, $request ) {
440
-		if ( empty( $post->post_password ) ) {
439
+	public function can_access_password_content($post, $request) {
440
+		if (empty($post->post_password)) {
441 441
 			// No filter required.
442 442
 			return false;
443 443
 		}
444 444
 
445 445
 		// Edit context always gets access to password-protected posts.
446
-		if ( 'edit' === $request['context'] ) {
446
+		if ('edit' === $request['context']) {
447 447
 			return true;
448 448
 		}
449 449
 
450 450
 		// No password, no auth.
451
-		if ( empty( $request['password'] ) ) {
451
+		if (empty($request['password'])) {
452 452
 			return false;
453 453
 		}
454 454
 
455 455
 		// Double-check the request password.
456
-		return hash_equals( $post->post_password, $request['password'] );
456
+		return hash_equals($post->post_password, $request['password']);
457 457
 	}
458 458
 
459 459
 	/**
@@ -465,17 +465,17 @@  discard block
 block discarded – undo
465 465
 	 * @param WP_REST_Request $request Full details about the request.
466 466
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
467 467
 	 */
468
-	public function get_item( $request ) {
469
-		$post = $this->get_post( $request['id'] );
470
-		if ( is_wp_error( $post ) ) {
468
+	public function get_item($request) {
469
+		$post = $this->get_post($request['id']);
470
+		if (is_wp_error($post)) {
471 471
 			return $post;
472 472
 		}
473 473
 
474
-		$data     = $this->prepare_item_for_response( $post, $request );
475
-		$response = rest_ensure_response( $data );
474
+		$data     = $this->prepare_item_for_response($post, $request);
475
+		$response = rest_ensure_response($data);
476 476
 
477
-		if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
478
-			$response->link_header( 'alternate',  get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
477
+		if (is_post_type_viewable(get_post_type_object($post->post_type))) {
478
+			$response->link_header('alternate', get_permalink($post->ID), array('type' => 'text/html'));
479 479
 		}
480 480
 
481 481
 		return $response;
@@ -490,27 +490,27 @@  discard block
 block discarded – undo
490 490
 	 * @param WP_REST_Request $request Full details about the request.
491 491
 	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
492 492
 	 */
493
-	public function create_item_permissions_check( $request ) {
494
-		if ( ! empty( $request['id'] ) ) {
495
-			return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) );
493
+	public function create_item_permissions_check($request) {
494
+		if ( ! empty($request['id'])) {
495
+			return new WP_Error('rest_post_exists', __('Cannot create existing post.'), array('status' => 400));
496 496
 		}
497 497
 
498
-		$post_type = get_post_type_object( $this->post_type );
498
+		$post_type = get_post_type_object($this->post_type);
499 499
 
500
-		if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
501
-			return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
500
+		if ( ! empty($request['author']) && get_current_user_id() !== $request['author'] && ! current_user_can($post_type->cap->edit_others_posts)) {
501
+			return new WP_Error('rest_cannot_edit_others', __('Sorry, you are not allowed to create posts as this user.'), array('status' => rest_authorization_required_code()));
502 502
 		}
503 503
 
504
-		if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
505
-			return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
504
+		if ( ! empty($request['sticky']) && ! current_user_can($post_type->cap->edit_others_posts)) {
505
+			return new WP_Error('rest_cannot_assign_sticky', __('Sorry, you are not allowed to make posts sticky.'), array('status' => rest_authorization_required_code()));
506 506
 		}
507 507
 
508
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
509
-			return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
508
+		if ( ! current_user_can($post_type->cap->create_posts)) {
509
+			return new WP_Error('rest_cannot_create', __('Sorry, you are not allowed to create posts as this user.'), array('status' => rest_authorization_required_code()));
510 510
 		}
511 511
 
512
-		if ( ! $this->check_assign_terms_permission( $request ) ) {
513
-			return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) );
512
+		if ( ! $this->check_assign_terms_permission($request)) {
513
+			return new WP_Error('rest_cannot_assign_term', __('Sorry, you are not allowed to assign the provided terms.'), array('status' => rest_authorization_required_code()));
514 514
 		}
515 515
 
516 516
 		return true;
@@ -525,33 +525,33 @@  discard block
 block discarded – undo
525 525
 	 * @param WP_REST_Request $request Full details about the request.
526 526
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
527 527
 	 */
528
-	public function create_item( $request ) {
529
-		if ( ! empty( $request['id'] ) ) {
530
-			return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) );
528
+	public function create_item($request) {
529
+		if ( ! empty($request['id'])) {
530
+			return new WP_Error('rest_post_exists', __('Cannot create existing post.'), array('status' => 400));
531 531
 		}
532 532
 
533
-		$prepared_post = $this->prepare_item_for_database( $request );
533
+		$prepared_post = $this->prepare_item_for_database($request);
534 534
 
535
-		if ( is_wp_error( $prepared_post ) ) {
535
+		if (is_wp_error($prepared_post)) {
536 536
 			return $prepared_post;
537 537
 		}
538 538
 
539 539
 		$prepared_post->post_type = $this->post_type;
540 540
 
541
-		$post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true );
541
+		$post_id = wp_insert_post(wp_slash((array) $prepared_post), true);
542 542
 
543
-		if ( is_wp_error( $post_id ) ) {
543
+		if (is_wp_error($post_id)) {
544 544
 
545
-			if ( 'db_insert_error' === $post_id->get_error_code() ) {
546
-				$post_id->add_data( array( 'status' => 500 ) );
545
+			if ('db_insert_error' === $post_id->get_error_code()) {
546
+				$post_id->add_data(array('status' => 500));
547 547
 			} else {
548
-				$post_id->add_data( array( 'status' => 400 ) );
548
+				$post_id->add_data(array('status' => 400));
549 549
 			}
550 550
 
551 551
 			return $post_id;
552 552
 		}
553 553
 
554
-		$post = get_post( $post_id );
554
+		$post = get_post($post_id);
555 555
 
556 556
 		/**
557 557
 		 * Fires after a single post is created or updated via the REST API.
@@ -564,58 +564,58 @@  discard block
 block discarded – undo
564 564
 		 * @param WP_REST_Request $request  Request object.
565 565
 		 * @param bool            $creating True when creating a post, false when updating.
566 566
 		 */
567
-		do_action( "rest_insert_{$this->post_type}", $post, $request, true );
567
+		do_action("rest_insert_{$this->post_type}", $post, $request, true);
568 568
 
569 569
 		$schema = $this->get_item_schema();
570 570
 
571
-		if ( ! empty( $schema['properties']['sticky'] ) ) {
572
-			if ( ! empty( $request['sticky'] ) ) {
573
-				stick_post( $post_id );
571
+		if ( ! empty($schema['properties']['sticky'])) {
572
+			if ( ! empty($request['sticky'])) {
573
+				stick_post($post_id);
574 574
 			} else {
575
-				unstick_post( $post_id );
575
+				unstick_post($post_id);
576 576
 			}
577 577
 		}
578 578
 
579
-		if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) {
580
-			$this->handle_featured_media( $request['featured_media'], $post_id );
579
+		if ( ! empty($schema['properties']['featured_media']) && isset($request['featured_media'])) {
580
+			$this->handle_featured_media($request['featured_media'], $post_id);
581 581
 		}
582 582
 
583
-		if ( ! empty( $schema['properties']['format'] ) && ! empty( $request['format'] ) ) {
584
-			set_post_format( $post, $request['format'] );
583
+		if ( ! empty($schema['properties']['format']) && ! empty($request['format'])) {
584
+			set_post_format($post, $request['format']);
585 585
 		}
586 586
 
587
-		if ( ! empty( $schema['properties']['template'] ) && isset( $request['template'] ) ) {
588
-			$this->handle_template( $request['template'], $post_id );
587
+		if ( ! empty($schema['properties']['template']) && isset($request['template'])) {
588
+			$this->handle_template($request['template'], $post_id);
589 589
 		}
590 590
 
591
-		$terms_update = $this->handle_terms( $post_id, $request );
591
+		$terms_update = $this->handle_terms($post_id, $request);
592 592
 
593
-		if ( is_wp_error( $terms_update ) ) {
593
+		if (is_wp_error($terms_update)) {
594 594
 			return $terms_update;
595 595
 		}
596 596
 
597
-		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
598
-			$meta_update = $this->meta->update_value( $request['meta'], $post_id );
597
+		if ( ! empty($schema['properties']['meta']) && isset($request['meta'])) {
598
+			$meta_update = $this->meta->update_value($request['meta'], $post_id);
599 599
 
600
-			if ( is_wp_error( $meta_update ) ) {
600
+			if (is_wp_error($meta_update)) {
601 601
 				return $meta_update;
602 602
 			}
603 603
 		}
604 604
 
605
-		$post = get_post( $post_id );
606
-		$fields_update = $this->update_additional_fields_for_object( $post, $request );
605
+		$post = get_post($post_id);
606
+		$fields_update = $this->update_additional_fields_for_object($post, $request);
607 607
 
608
-		if ( is_wp_error( $fields_update ) ) {
608
+		if (is_wp_error($fields_update)) {
609 609
 			return $fields_update;
610 610
 		}
611 611
 
612
-		$request->set_param( 'context', 'edit' );
612
+		$request->set_param('context', 'edit');
613 613
 
614
-		$response = $this->prepare_item_for_response( $post, $request );
615
-		$response = rest_ensure_response( $response );
614
+		$response = $this->prepare_item_for_response($post, $request);
615
+		$response = rest_ensure_response($response);
616 616
 
617
-		$response->set_status( 201 );
618
-		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) );
617
+		$response->set_status(201);
618
+		$response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $post_id)));
619 619
 
620 620
 		return $response;
621 621
 	}
@@ -629,28 +629,28 @@  discard block
 block discarded – undo
629 629
 	 * @param WP_REST_Request $request Full details about the request.
630 630
 	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
631 631
 	 */
632
-	public function update_item_permissions_check( $request ) {
633
-		$post = $this->get_post( $request['id'] );
634
-		if ( is_wp_error( $post ) ) {
632
+	public function update_item_permissions_check($request) {
633
+		$post = $this->get_post($request['id']);
634
+		if (is_wp_error($post)) {
635 635
 			return $post;
636 636
 		}
637 637
 
638
-		$post_type = get_post_type_object( $this->post_type );
638
+		$post_type = get_post_type_object($this->post_type);
639 639
 
640
-		if ( $post && ! $this->check_update_permission( $post ) ) {
641
-			return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) );
640
+		if ($post && ! $this->check_update_permission($post)) {
641
+			return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to edit this post.'), array('status' => rest_authorization_required_code()));
642 642
 		}
643 643
 
644
-		if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
645
-			return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
644
+		if ( ! empty($request['author']) && get_current_user_id() !== $request['author'] && ! current_user_can($post_type->cap->edit_others_posts)) {
645
+			return new WP_Error('rest_cannot_edit_others', __('Sorry, you are not allowed to update posts as this user.'), array('status' => rest_authorization_required_code()));
646 646
 		}
647 647
 
648
-		if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
649
-			return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
648
+		if ( ! empty($request['sticky']) && ! current_user_can($post_type->cap->edit_others_posts)) {
649
+			return new WP_Error('rest_cannot_assign_sticky', __('Sorry, you are not allowed to make posts sticky.'), array('status' => rest_authorization_required_code()));
650 650
 		}
651 651
 
652
-		if ( ! $this->check_assign_terms_permission( $request ) ) {
653
-			return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) );
652
+		if ( ! $this->check_assign_terms_permission($request)) {
653
+			return new WP_Error('rest_cannot_assign_term', __('Sorry, you are not allowed to assign the provided terms.'), array('status' => rest_authorization_required_code()));
654 654
 		}
655 655
 
656 656
 		return true;
@@ -665,83 +665,83 @@  discard block
 block discarded – undo
665 665
 	 * @param WP_REST_Request $request Full details about the request.
666 666
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
667 667
 	 */
668
-	public function update_item( $request ) {
669
-		$valid_check = $this->get_post( $request['id'] );
670
-		if ( is_wp_error( $valid_check ) ) {
668
+	public function update_item($request) {
669
+		$valid_check = $this->get_post($request['id']);
670
+		if (is_wp_error($valid_check)) {
671 671
 			return $valid_check;
672 672
 		}
673 673
 
674
-		$post = $this->prepare_item_for_database( $request );
674
+		$post = $this->prepare_item_for_database($request);
675 675
 
676
-		if ( is_wp_error( $post ) ) {
676
+		if (is_wp_error($post)) {
677 677
 			return $post;
678 678
 		}
679 679
 
680 680
 		// convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
681
-		$post_id = wp_update_post( wp_slash( (array) $post ), true );
681
+		$post_id = wp_update_post(wp_slash((array) $post), true);
682 682
 
683
-		if ( is_wp_error( $post_id ) ) {
684
-			if ( 'db_update_error' === $post_id->get_error_code() ) {
685
-				$post_id->add_data( array( 'status' => 500 ) );
683
+		if (is_wp_error($post_id)) {
684
+			if ('db_update_error' === $post_id->get_error_code()) {
685
+				$post_id->add_data(array('status' => 500));
686 686
 			} else {
687
-				$post_id->add_data( array( 'status' => 400 ) );
687
+				$post_id->add_data(array('status' => 400));
688 688
 			}
689 689
 			return $post_id;
690 690
 		}
691 691
 
692
-		$post = get_post( $post_id );
692
+		$post = get_post($post_id);
693 693
 
694 694
 		/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
695
-		do_action( "rest_insert_{$this->post_type}", $post, $request, false );
695
+		do_action("rest_insert_{$this->post_type}", $post, $request, false);
696 696
 
697 697
 		$schema = $this->get_item_schema();
698 698
 
699
-		if ( ! empty( $schema['properties']['format'] ) && ! empty( $request['format'] ) ) {
700
-			set_post_format( $post, $request['format'] );
699
+		if ( ! empty($schema['properties']['format']) && ! empty($request['format'])) {
700
+			set_post_format($post, $request['format']);
701 701
 		}
702 702
 
703
-		if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) {
704
-			$this->handle_featured_media( $request['featured_media'], $post_id );
703
+		if ( ! empty($schema['properties']['featured_media']) && isset($request['featured_media'])) {
704
+			$this->handle_featured_media($request['featured_media'], $post_id);
705 705
 		}
706 706
 
707
-		if ( ! empty( $schema['properties']['sticky'] ) && isset( $request['sticky'] ) ) {
708
-			if ( ! empty( $request['sticky'] ) ) {
709
-				stick_post( $post_id );
707
+		if ( ! empty($schema['properties']['sticky']) && isset($request['sticky'])) {
708
+			if ( ! empty($request['sticky'])) {
709
+				stick_post($post_id);
710 710
 			} else {
711
-				unstick_post( $post_id );
711
+				unstick_post($post_id);
712 712
 			}
713 713
 		}
714 714
 
715
-		if ( ! empty( $schema['properties']['template'] ) && isset( $request['template'] ) ) {
716
-			$this->handle_template( $request['template'], $post->ID );
715
+		if ( ! empty($schema['properties']['template']) && isset($request['template'])) {
716
+			$this->handle_template($request['template'], $post->ID);
717 717
 		}
718 718
 
719
-		$terms_update = $this->handle_terms( $post->ID, $request );
719
+		$terms_update = $this->handle_terms($post->ID, $request);
720 720
 
721
-		if ( is_wp_error( $terms_update ) ) {
721
+		if (is_wp_error($terms_update)) {
722 722
 			return $terms_update;
723 723
 		}
724 724
 
725
-		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
726
-			$meta_update = $this->meta->update_value( $request['meta'], $post->ID );
725
+		if ( ! empty($schema['properties']['meta']) && isset($request['meta'])) {
726
+			$meta_update = $this->meta->update_value($request['meta'], $post->ID);
727 727
 
728
-			if ( is_wp_error( $meta_update ) ) {
728
+			if (is_wp_error($meta_update)) {
729 729
 				return $meta_update;
730 730
 			}
731 731
 		}
732 732
 
733
-		$post = get_post( $post_id );
734
-		$fields_update = $this->update_additional_fields_for_object( $post, $request );
733
+		$post = get_post($post_id);
734
+		$fields_update = $this->update_additional_fields_for_object($post, $request);
735 735
 
736
-		if ( is_wp_error( $fields_update ) ) {
736
+		if (is_wp_error($fields_update)) {
737 737
 			return $fields_update;
738 738
 		}
739 739
 
740
-		$request->set_param( 'context', 'edit' );
740
+		$request->set_param('context', 'edit');
741 741
 
742
-		$response = $this->prepare_item_for_response( $post, $request );
742
+		$response = $this->prepare_item_for_response($post, $request);
743 743
 
744
-		return rest_ensure_response( $response );
744
+		return rest_ensure_response($response);
745 745
 	}
746 746
 
747 747
 	/**
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
 	 * @param WP_REST_Request $request Full details about the request.
754 754
 	 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
755 755
 	 */
756
-	public function delete_item_permissions_check( $request ) {
757
-		$post = $this->get_post( $request['id'] );
758
-		if ( is_wp_error( $post ) ) {
756
+	public function delete_item_permissions_check($request) {
757
+		$post = $this->get_post($request['id']);
758
+		if (is_wp_error($post)) {
759 759
 			return $post;
760 760
 		}
761 761
 
762
-		if ( $post && ! $this->check_delete_permission( $post ) ) {
763
-			return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) );
762
+		if ($post && ! $this->check_delete_permission($post)) {
763
+			return new WP_Error('rest_cannot_delete', __('Sorry, you are not allowed to delete this post.'), array('status' => rest_authorization_required_code()));
764 764
 		}
765 765
 
766 766
 		return true;
@@ -775,18 +775,18 @@  discard block
 block discarded – undo
775 775
 	 * @param WP_REST_Request $request Full details about the request.
776 776
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
777 777
 	 */
778
-	public function delete_item( $request ) {
779
-		$post = $this->get_post( $request['id'] );
780
-		if ( is_wp_error( $post ) ) {
778
+	public function delete_item($request) {
779
+		$post = $this->get_post($request['id']);
780
+		if (is_wp_error($post)) {
781 781
 			return $post;
782 782
 		}
783 783
 
784 784
 		$id    = $post->ID;
785 785
 		$force = (bool) $request['force'];
786 786
 
787
-		$supports_trash = ( EMPTY_TRASH_DAYS > 0 );
787
+		$supports_trash = (EMPTY_TRASH_DAYS > 0);
788 788
 
789
-		if ( 'attachment' === $post->post_type ) {
789
+		if ('attachment' === $post->post_type) {
790 790
 			$supports_trash = $supports_trash && MEDIA_TRASH;
791 791
 		}
792 792
 
@@ -802,41 +802,41 @@  discard block
 block discarded – undo
802 802
 		 * @param bool    $supports_trash Whether the post type support trashing.
803 803
 		 * @param WP_Post $post           The Post object being considered for trashing support.
804 804
 		 */
805
-		$supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post );
805
+		$supports_trash = apply_filters("rest_{$this->post_type}_trashable", $supports_trash, $post);
806 806
 
807
-		if ( ! $this->check_delete_permission( $post ) ) {
808
-			return new WP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) );
807
+		if ( ! $this->check_delete_permission($post)) {
808
+			return new WP_Error('rest_user_cannot_delete_post', __('Sorry, you are not allowed to delete this post.'), array('status' => rest_authorization_required_code()));
809 809
 		}
810 810
 
811
-		$request->set_param( 'context', 'edit' );
811
+		$request->set_param('context', 'edit');
812 812
 
813 813
 
814 814
 		// If we're forcing, then delete permanently.
815
-		if ( $force ) {
816
-			$previous = $this->prepare_item_for_response( $post, $request );
817
-			$result = wp_delete_post( $id, true );
815
+		if ($force) {
816
+			$previous = $this->prepare_item_for_response($post, $request);
817
+			$result = wp_delete_post($id, true);
818 818
 			$response = new WP_REST_Response();
819
-			$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
819
+			$response->set_data(array('deleted' => true, 'previous' => $previous->get_data()));
820 820
 		} else {
821 821
 			// If we don't support trashing for this type, error out.
822
-			if ( ! $supports_trash ) {
823
-				return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
822
+			if ( ! $supports_trash) {
823
+				return new WP_Error('rest_trash_not_supported', __('The post does not support trashing. Set force=true to delete.'), array('status' => 501));
824 824
 			}
825 825
 
826 826
 			// Otherwise, only trash if we haven't already.
827
-			if ( 'trash' === $post->post_status ) {
828
-				return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) );
827
+			if ('trash' === $post->post_status) {
828
+				return new WP_Error('rest_already_trashed', __('The post has already been deleted.'), array('status' => 410));
829 829
 			}
830 830
 
831 831
 			// (Note that internally this falls through to `wp_delete_post` if
832 832
 			// the trash is disabled.)
833
-			$result = wp_trash_post( $id );
834
-			$post = get_post( $id );
835
-			$response = $this->prepare_item_for_response( $post, $request );
833
+			$result = wp_trash_post($id);
834
+			$post = get_post($id);
835
+			$response = $this->prepare_item_for_response($post, $request);
836 836
 		}
837 837
 
838
-		if ( ! $result ) {
839
-			return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) );
838
+		if ( ! $result) {
839
+			return new WP_Error('rest_cannot_delete', __('The post cannot be deleted.'), array('status' => 500));
840 840
 		}
841 841
 
842 842
 		/**
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 		 * @param WP_REST_Response $response The response data.
851 851
 		 * @param WP_REST_Request  $request  The request sent to the API.
852 852
 		 */
853
-		do_action( "rest_delete_{$this->post_type}", $post, $response, $request );
853
+		do_action("rest_delete_{$this->post_type}", $post, $response, $request);
854 854
 
855 855
 		return $response;
856 856
 	}
@@ -866,10 +866,10 @@  discard block
 block discarded – undo
866 866
 	 * @param WP_REST_Request $request       Optional. Full details about the request.
867 867
 	 * @return array Items query arguments.
868 868
 	 */
869
-	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
869
+	protected function prepare_items_query($prepared_args = array(), $request = null) {
870 870
 		$query_args = array();
871 871
 
872
-		foreach ( $prepared_args as $key => $value ) {
872
+		foreach ($prepared_args as $key => $value) {
873 873
 			/**
874 874
 			 * Filters the query_vars used in get_items() for the constructed query.
875 875
 			 *
@@ -879,23 +879,23 @@  discard block
 block discarded – undo
879 879
 			 *
880 880
 			 * @param string $value The query_var value.
881 881
 			 */
882
-			$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value );
882
+			$query_args[$key] = apply_filters("rest_query_var-{$key}", $value);
883 883
 		}
884 884
 
885
-		if ( 'post' !== $this->post_type || ! isset( $query_args['ignore_sticky_posts'] ) ) {
885
+		if ('post' !== $this->post_type || ! isset($query_args['ignore_sticky_posts'])) {
886 886
 			$query_args['ignore_sticky_posts'] = true;
887 887
 		}
888 888
 
889 889
 		// Map to proper WP_Query orderby param.
890
-		if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) {
890
+		if (isset($query_args['orderby']) && isset($request['orderby'])) {
891 891
 			$orderby_mappings = array(
892 892
 				'id'      => 'ID',
893 893
 				'include' => 'post__in',
894 894
 				'slug'    => 'post_name',
895 895
 			);
896 896
 
897
-			if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
898
-				$query_args['orderby'] = $orderby_mappings[ $request['orderby'] ];
897
+			if (isset($orderby_mappings[$request['orderby']])) {
898
+				$query_args['orderby'] = $orderby_mappings[$request['orderby']];
899 899
 			}
900 900
 		}
901 901
 
@@ -913,19 +913,19 @@  discard block
 block discarded – undo
913 913
 	 * @param string|null $date     Optional. Local publication time. Default null.
914 914
 	 * @return string|null ISO8601/RFC3339 formatted datetime.
915 915
 	 */
916
-	protected function prepare_date_response( $date_gmt, $date = null ) {
916
+	protected function prepare_date_response($date_gmt, $date = null) {
917 917
 		// Use the date if passed.
918
-		if ( isset( $date ) ) {
919
-			return mysql_to_rfc3339( $date );
918
+		if (isset($date)) {
919
+			return mysql_to_rfc3339($date);
920 920
 		}
921 921
 
922 922
 		// Return null if $date_gmt is empty/zeros.
923
-		if ( '0000-00-00 00:00:00' === $date_gmt ) {
923
+		if ('0000-00-00 00:00:00' === $date_gmt) {
924 924
 			return null;
925 925
 		}
926 926
 
927 927
 		// Return the formatted datetime.
928
-		return mysql_to_rfc3339( $date_gmt );
928
+		return mysql_to_rfc3339($date_gmt);
929 929
 	}
930 930
 
931 931
 	/**
@@ -937,13 +937,13 @@  discard block
 block discarded – undo
937 937
 	 * @param WP_REST_Request $request Request object.
938 938
 	 * @return stdClass|WP_Error Post object or WP_Error.
939 939
 	 */
940
-	protected function prepare_item_for_database( $request ) {
940
+	protected function prepare_item_for_database($request) {
941 941
 		$prepared_post = new stdClass;
942 942
 
943 943
 		// Post ID.
944
-		if ( isset( $request['id'] ) ) {
945
-			$existing_post = $this->get_post( $request['id'] );
946
-			if ( is_wp_error( $existing_post ) ) {
944
+		if (isset($request['id'])) {
945
+			$existing_post = $this->get_post($request['id']);
946
+			if (is_wp_error($existing_post)) {
947 947
 				return $existing_post;
948 948
 			}
949 949
 
@@ -953,48 +953,48 @@  discard block
 block discarded – undo
953 953
 		$schema = $this->get_item_schema();
954 954
 
955 955
 		// Post title.
956
-		if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) {
957
-			if ( is_string( $request['title'] ) ) {
956
+		if ( ! empty($schema['properties']['title']) && isset($request['title'])) {
957
+			if (is_string($request['title'])) {
958 958
 				$prepared_post->post_title = $request['title'];
959
-			} elseif ( ! empty( $request['title']['raw'] ) ) {
959
+			} elseif ( ! empty($request['title']['raw'])) {
960 960
 				$prepared_post->post_title = $request['title']['raw'];
961 961
 			}
962 962
 		}
963 963
 
964 964
 		// Post content.
965
-		if ( ! empty( $schema['properties']['content'] ) && isset( $request['content'] ) ) {
966
-			if ( is_string( $request['content'] ) ) {
965
+		if ( ! empty($schema['properties']['content']) && isset($request['content'])) {
966
+			if (is_string($request['content'])) {
967 967
 				$prepared_post->post_content = $request['content'];
968
-			} elseif ( isset( $request['content']['raw'] ) ) {
968
+			} elseif (isset($request['content']['raw'])) {
969 969
 				$prepared_post->post_content = $request['content']['raw'];
970 970
 			}
971 971
 		}
972 972
 
973 973
 		// Post excerpt.
974
-		if ( ! empty( $schema['properties']['excerpt'] ) && isset( $request['excerpt'] ) ) {
975
-			if ( is_string( $request['excerpt'] ) ) {
974
+		if ( ! empty($schema['properties']['excerpt']) && isset($request['excerpt'])) {
975
+			if (is_string($request['excerpt'])) {
976 976
 				$prepared_post->post_excerpt = $request['excerpt'];
977
-			} elseif ( isset( $request['excerpt']['raw'] ) ) {
977
+			} elseif (isset($request['excerpt']['raw'])) {
978 978
 				$prepared_post->post_excerpt = $request['excerpt']['raw'];
979 979
 			}
980 980
 		}
981 981
 
982 982
 		// Post type.
983
-		if ( empty( $request['id'] ) ) {
983
+		if (empty($request['id'])) {
984 984
 			// Creating new post, use default type for the controller.
985 985
 			$prepared_post->post_type = $this->post_type;
986 986
 		} else {
987 987
 			// Updating a post, use previous type.
988
-			$prepared_post->post_type = get_post_type( $request['id'] );
988
+			$prepared_post->post_type = get_post_type($request['id']);
989 989
 		}
990 990
 
991
-		$post_type = get_post_type_object( $prepared_post->post_type );
991
+		$post_type = get_post_type_object($prepared_post->post_type);
992 992
 
993 993
 		// Post status.
994
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
995
-			$status = $this->handle_status_param( $request['status'], $post_type );
994
+		if ( ! empty($schema['properties']['status']) && isset($request['status'])) {
995
+			$status = $this->handle_status_param($request['status'], $post_type);
996 996
 
997
-			if ( is_wp_error( $status ) ) {
997
+			if (is_wp_error($status)) {
998 998
 				return $status;
999 999
 			}
1000 1000
 
@@ -1002,36 +1002,36 @@  discard block
 block discarded – undo
1002 1002
 		}
1003 1003
 
1004 1004
 		// Post date.
1005
-		if ( ! empty( $schema['properties']['date'] ) && ! empty( $request['date'] ) ) {
1006
-			$date_data = rest_get_date_with_gmt( $request['date'] );
1005
+		if ( ! empty($schema['properties']['date']) && ! empty($request['date'])) {
1006
+			$date_data = rest_get_date_with_gmt($request['date']);
1007 1007
 
1008
-			if ( ! empty( $date_data ) ) {
1009
-				list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
1008
+			if ( ! empty($date_data)) {
1009
+				list($prepared_post->post_date, $prepared_post->post_date_gmt) = $date_data;
1010 1010
 				$prepared_post->edit_date = true;
1011 1011
 			}
1012
-		} elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) {
1013
-			$date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
1012
+		} elseif ( ! empty($schema['properties']['date_gmt']) && ! empty($request['date_gmt'])) {
1013
+			$date_data = rest_get_date_with_gmt($request['date_gmt'], true);
1014 1014
 
1015
-			if ( ! empty( $date_data ) ) {
1016
-				list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
1015
+			if ( ! empty($date_data)) {
1016
+				list($prepared_post->post_date, $prepared_post->post_date_gmt) = $date_data;
1017 1017
 				$prepared_post->edit_date = true;
1018 1018
 			}
1019 1019
 		}
1020 1020
 
1021 1021
 		// Post slug.
1022
-		if ( ! empty( $schema['properties']['slug'] ) && isset( $request['slug'] ) ) {
1022
+		if ( ! empty($schema['properties']['slug']) && isset($request['slug'])) {
1023 1023
 			$prepared_post->post_name = $request['slug'];
1024 1024
 		}
1025 1025
 
1026 1026
 		// Author.
1027
-		if ( ! empty( $schema['properties']['author'] ) && ! empty( $request['author'] ) ) {
1027
+		if ( ! empty($schema['properties']['author']) && ! empty($request['author'])) {
1028 1028
 			$post_author = (int) $request['author'];
1029 1029
 
1030
-			if ( get_current_user_id() !== $post_author ) {
1031
-				$user_obj = get_userdata( $post_author );
1030
+			if (get_current_user_id() !== $post_author) {
1031
+				$user_obj = get_userdata($post_author);
1032 1032
 
1033
-				if ( ! $user_obj ) {
1034
-					return new WP_Error( 'rest_invalid_author', __( 'Invalid author ID.' ), array( 'status' => 400 ) );
1033
+				if ( ! $user_obj) {
1034
+					return new WP_Error('rest_invalid_author', __('Invalid author ID.'), array('status' => 400));
1035 1035
 				}
1036 1036
 			}
1037 1037
 
@@ -1039,51 +1039,51 @@  discard block
 block discarded – undo
1039 1039
 		}
1040 1040
 
1041 1041
 		// Post password.
1042
-		if ( ! empty( $schema['properties']['password'] ) && isset( $request['password'] ) ) {
1042
+		if ( ! empty($schema['properties']['password']) && isset($request['password'])) {
1043 1043
 			$prepared_post->post_password = $request['password'];
1044 1044
 
1045
-			if ( '' !== $request['password'] ) {
1046
-				if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) {
1047
-					return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) );
1045
+			if ('' !== $request['password']) {
1046
+				if ( ! empty($schema['properties']['sticky']) && ! empty($request['sticky'])) {
1047
+					return new WP_Error('rest_invalid_field', __('A post can not be sticky and have a password.'), array('status' => 400));
1048 1048
 				}
1049 1049
 
1050
-				if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) {
1051
-					return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) );
1050
+				if ( ! empty($prepared_post->ID) && is_sticky($prepared_post->ID)) {
1051
+					return new WP_Error('rest_invalid_field', __('A sticky post can not be password protected.'), array('status' => 400));
1052 1052
 				}
1053 1053
 			}
1054 1054
 		}
1055 1055
 
1056
-		if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) {
1057
-			if ( ! empty( $prepared_post->ID ) && post_password_required( $prepared_post->ID ) ) {
1058
-				return new WP_Error( 'rest_invalid_field', __( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) );
1056
+		if ( ! empty($schema['properties']['sticky']) && ! empty($request['sticky'])) {
1057
+			if ( ! empty($prepared_post->ID) && post_password_required($prepared_post->ID)) {
1058
+				return new WP_Error('rest_invalid_field', __('A password protected post can not be set to sticky.'), array('status' => 400));
1059 1059
 			}
1060 1060
 		}
1061 1061
 
1062 1062
 		// Parent.
1063
-		if ( ! empty( $schema['properties']['parent'] ) && isset( $request['parent'] ) ) {
1064
-			if ( 0 === (int) $request['parent'] ) {
1063
+		if ( ! empty($schema['properties']['parent']) && isset($request['parent'])) {
1064
+			if (0 === (int) $request['parent']) {
1065 1065
 				$prepared_post->post_parent = 0;
1066 1066
 			} else {
1067
-				$parent = get_post( (int) $request['parent'] );
1068
-				if ( empty( $parent ) ) {
1069
-					return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) );
1067
+				$parent = get_post((int) $request['parent']);
1068
+				if (empty($parent)) {
1069
+					return new WP_Error('rest_post_invalid_id', __('Invalid post parent ID.'), array('status' => 400));
1070 1070
 				}
1071 1071
 				$prepared_post->post_parent = (int) $parent->ID;
1072 1072
 			}
1073 1073
 		}
1074 1074
 
1075 1075
 		// Menu order.
1076
-		if ( ! empty( $schema['properties']['menu_order'] ) && isset( $request['menu_order'] ) ) {
1076
+		if ( ! empty($schema['properties']['menu_order']) && isset($request['menu_order'])) {
1077 1077
 			$prepared_post->menu_order = (int) $request['menu_order'];
1078 1078
 		}
1079 1079
 
1080 1080
 		// Comment status.
1081
-		if ( ! empty( $schema['properties']['comment_status'] ) && ! empty( $request['comment_status'] ) ) {
1081
+		if ( ! empty($schema['properties']['comment_status']) && ! empty($request['comment_status'])) {
1082 1082
 			$prepared_post->comment_status = $request['comment_status'];
1083 1083
 		}
1084 1084
 
1085 1085
 		// Ping status.
1086
-		if ( ! empty( $schema['properties']['ping_status'] ) && ! empty( $request['ping_status'] ) ) {
1086
+		if ( ! empty($schema['properties']['ping_status']) && ! empty($request['ping_status'])) {
1087 1087
 			$prepared_post->ping_status = $request['ping_status'];
1088 1088
 		}
1089 1089
 
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 		 *                                       for inserting or updating the database.
1099 1099
 		 * @param WP_REST_Request $request       Request object.
1100 1100
 		 */
1101
-		return apply_filters( "rest_pre_insert_{$this->post_type}", $prepared_post, $request );
1101
+		return apply_filters("rest_pre_insert_{$this->post_type}", $prepared_post, $request);
1102 1102
 
1103 1103
 	}
1104 1104
 
@@ -1112,25 +1112,25 @@  discard block
 block discarded – undo
1112 1112
 	 * @param object $post_type   Post type.
1113 1113
 	 * @return string|WP_Error Post status or WP_Error if lacking the proper permission.
1114 1114
 	 */
1115
-	protected function handle_status_param( $post_status, $post_type ) {
1115
+	protected function handle_status_param($post_status, $post_type) {
1116 1116
 
1117
-		switch ( $post_status ) {
1117
+		switch ($post_status) {
1118 1118
 			case 'draft':
1119 1119
 			case 'pending':
1120 1120
 				break;
1121 1121
 			case 'private':
1122
-				if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
1123
-					return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) );
1122
+				if ( ! current_user_can($post_type->cap->publish_posts)) {
1123
+					return new WP_Error('rest_cannot_publish', __('Sorry, you are not allowed to create private posts in this post type.'), array('status' => rest_authorization_required_code()));
1124 1124
 				}
1125 1125
 				break;
1126 1126
 			case 'publish':
1127 1127
 			case 'future':
1128
-				if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
1129
-					return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) );
1128
+				if ( ! current_user_can($post_type->cap->publish_posts)) {
1129
+					return new WP_Error('rest_cannot_publish', __('Sorry, you are not allowed to publish posts in this post type.'), array('status' => rest_authorization_required_code()));
1130 1130
 				}
1131 1131
 				break;
1132 1132
 			default:
1133
-				if ( ! get_post_status_object( $post_status ) ) {
1133
+				if ( ! get_post_status_object($post_status)) {
1134 1134
 					$post_status = 'draft';
1135 1135
 				}
1136 1136
 				break;
@@ -1149,18 +1149,18 @@  discard block
 block discarded – undo
1149 1149
 	 * @param int $post_id        Post ID.
1150 1150
 	 * @return bool|WP_Error Whether the post thumbnail was successfully deleted, otherwise WP_Error.
1151 1151
 	 */
1152
-	protected function handle_featured_media( $featured_media, $post_id ) {
1152
+	protected function handle_featured_media($featured_media, $post_id) {
1153 1153
 
1154 1154
 		$featured_media = (int) $featured_media;
1155
-		if ( $featured_media ) {
1156
-			$result = set_post_thumbnail( $post_id, $featured_media );
1157
-			if ( $result ) {
1155
+		if ($featured_media) {
1156
+			$result = set_post_thumbnail($post_id, $featured_media);
1157
+			if ($result) {
1158 1158
 				return true;
1159 1159
 			} else {
1160
-				return new WP_Error( 'rest_invalid_featured_media', __( 'Invalid featured media ID.' ), array( 'status' => 400 ) );
1160
+				return new WP_Error('rest_invalid_featured_media', __('Invalid featured media ID.'), array('status' => 400));
1161 1161
 			}
1162 1162
 		} else {
1163
-			return delete_post_thumbnail( $post_id );
1163
+			return delete_post_thumbnail($post_id);
1164 1164
 		}
1165 1165
 
1166 1166
 	}
@@ -1174,11 +1174,11 @@  discard block
 block discarded – undo
1174 1174
 	 * @param string  $template Page template filename.
1175 1175
 	 * @param integer $post_id  Post ID.
1176 1176
 	 */
1177
-	public function handle_template( $template, $post_id ) {
1178
-		if ( in_array( $template, array_keys( wp_get_theme()->get_page_templates( get_post( $post_id ) ) ), true ) ) {
1179
-			update_post_meta( $post_id, '_wp_page_template', $template );
1177
+	public function handle_template($template, $post_id) {
1178
+		if (in_array($template, array_keys(wp_get_theme()->get_page_templates(get_post($post_id))), true)) {
1179
+			update_post_meta($post_id, '_wp_page_template', $template);
1180 1180
 		} else {
1181
-			update_post_meta( $post_id, '_wp_page_template', '' );
1181
+			update_post_meta($post_id, '_wp_page_template', '');
1182 1182
 		}
1183 1183
 	}
1184 1184
 
@@ -1192,19 +1192,19 @@  discard block
 block discarded – undo
1192 1192
 	 * @param WP_REST_Request $request The request object with post and terms data.
1193 1193
 	 * @return null|WP_Error WP_Error on an error assigning any of the terms, otherwise null.
1194 1194
 	 */
1195
-	protected function handle_terms( $post_id, $request ) {
1196
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
1195
+	protected function handle_terms($post_id, $request) {
1196
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
1197 1197
 
1198
-		foreach ( $taxonomies as $taxonomy ) {
1199
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
1198
+		foreach ($taxonomies as $taxonomy) {
1199
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
1200 1200
 
1201
-			if ( ! isset( $request[ $base ] ) ) {
1201
+			if ( ! isset($request[$base])) {
1202 1202
 				continue;
1203 1203
 			}
1204 1204
 
1205
-			$result = wp_set_object_terms( $post_id, $request[ $base ], $taxonomy->name );
1205
+			$result = wp_set_object_terms($post_id, $request[$base], $taxonomy->name);
1206 1206
 
1207
-			if ( is_wp_error( $result ) ) {
1207
+			if (is_wp_error($result)) {
1208 1208
 				return $result;
1209 1209
 			}
1210 1210
 		}
@@ -1219,22 +1219,22 @@  discard block
 block discarded – undo
1219 1219
 	 * @param WP_REST_Request $request The request object with post and terms data.
1220 1220
 	 * @return bool Whether the current user can assign the provided terms.
1221 1221
 	 */
1222
-	protected function check_assign_terms_permission( $request ) {
1223
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
1224
-		foreach ( $taxonomies as $taxonomy ) {
1225
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
1222
+	protected function check_assign_terms_permission($request) {
1223
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
1224
+		foreach ($taxonomies as $taxonomy) {
1225
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
1226 1226
 
1227
-			if ( ! isset( $request[ $base ] ) ) {
1227
+			if ( ! isset($request[$base])) {
1228 1228
 				continue;
1229 1229
 			}
1230 1230
 
1231
-			foreach ( $request[ $base ] as $term_id ) {
1231
+			foreach ($request[$base] as $term_id) {
1232 1232
 				// Invalid terms will be rejected later.
1233
-				if ( ! get_term( $term_id, $taxonomy->name ) ) {
1233
+				if ( ! get_term($term_id, $taxonomy->name)) {
1234 1234
 					continue;
1235 1235
 				}
1236 1236
 
1237
-				if ( ! current_user_can( 'assign_term', (int) $term_id ) ) {
1237
+				if ( ! current_user_can('assign_term', (int) $term_id)) {
1238 1238
 					return false;
1239 1239
 				}
1240 1240
 			}
@@ -1252,12 +1252,12 @@  discard block
 block discarded – undo
1252 1252
 	 * @param object|string $post_type Post type name or object.
1253 1253
 	 * @return bool Whether the post type is allowed in REST.
1254 1254
 	 */
1255
-	protected function check_is_post_type_allowed( $post_type ) {
1256
-		if ( ! is_object( $post_type ) ) {
1257
-			$post_type = get_post_type_object( $post_type );
1255
+	protected function check_is_post_type_allowed($post_type) {
1256
+		if ( ! is_object($post_type)) {
1257
+			$post_type = get_post_type_object($post_type);
1258 1258
 		}
1259 1259
 
1260
-		if ( ! empty( $post_type ) && ! empty( $post_type->show_in_rest ) ) {
1260
+		if ( ! empty($post_type) && ! empty($post_type->show_in_rest)) {
1261 1261
 			return true;
1262 1262
 		}
1263 1263
 
@@ -1275,27 +1275,27 @@  discard block
 block discarded – undo
1275 1275
 	 * @param object $post Post object.
1276 1276
 	 * @return bool Whether the post can be read.
1277 1277
 	 */
1278
-	public function check_read_permission( $post ) {
1279
-		$post_type = get_post_type_object( $post->post_type );
1280
-		if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
1278
+	public function check_read_permission($post) {
1279
+		$post_type = get_post_type_object($post->post_type);
1280
+		if ( ! $this->check_is_post_type_allowed($post_type)) {
1281 1281
 			return false;
1282 1282
 		}
1283 1283
 
1284 1284
 		// Is the post readable?
1285
-		if ( 'publish' === $post->post_status || current_user_can( $post_type->cap->read_post, $post->ID ) ) {
1285
+		if ('publish' === $post->post_status || current_user_can($post_type->cap->read_post, $post->ID)) {
1286 1286
 			return true;
1287 1287
 		}
1288 1288
 
1289
-		$post_status_obj = get_post_status_object( $post->post_status );
1290
-		if ( $post_status_obj && $post_status_obj->public ) {
1289
+		$post_status_obj = get_post_status_object($post->post_status);
1290
+		if ($post_status_obj && $post_status_obj->public) {
1291 1291
 			return true;
1292 1292
 		}
1293 1293
 
1294 1294
 		// Can we read the parent if we're inheriting?
1295
-		if ( 'inherit' === $post->post_status && $post->post_parent > 0 ) {
1296
-			$parent = get_post( $post->post_parent );
1297
-			if ( $parent ) {
1298
-				return $this->check_read_permission( $parent );
1295
+		if ('inherit' === $post->post_status && $post->post_parent > 0) {
1296
+			$parent = get_post($post->post_parent);
1297
+			if ($parent) {
1298
+				return $this->check_read_permission($parent);
1299 1299
 			}
1300 1300
 		}
1301 1301
 
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 		 * If there isn't a parent, but the status is set to inherit, assume
1304 1304
 		 * it's published (as per get_post_status()).
1305 1305
 		 */
1306
-		if ( 'inherit' === $post->post_status ) {
1306
+		if ('inherit' === $post->post_status) {
1307 1307
 			return true;
1308 1308
 		}
1309 1309
 
@@ -1319,14 +1319,14 @@  discard block
 block discarded – undo
1319 1319
 	 * @param object $post Post object.
1320 1320
 	 * @return bool Whether the post can be edited.
1321 1321
 	 */
1322
-	protected function check_update_permission( $post ) {
1323
-		$post_type = get_post_type_object( $post->post_type );
1322
+	protected function check_update_permission($post) {
1323
+		$post_type = get_post_type_object($post->post_type);
1324 1324
 
1325
-		if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
1325
+		if ( ! $this->check_is_post_type_allowed($post_type)) {
1326 1326
 			return false;
1327 1327
 		}
1328 1328
 
1329
-		return current_user_can( $post_type->cap->edit_post, $post->ID );
1329
+		return current_user_can($post_type->cap->edit_post, $post->ID);
1330 1330
 	}
1331 1331
 
1332 1332
 	/**
@@ -1338,14 +1338,14 @@  discard block
 block discarded – undo
1338 1338
 	 * @param object $post Post object.
1339 1339
 	 * @return bool Whether the post can be created.
1340 1340
 	 */
1341
-	protected function check_create_permission( $post ) {
1342
-		$post_type = get_post_type_object( $post->post_type );
1341
+	protected function check_create_permission($post) {
1342
+		$post_type = get_post_type_object($post->post_type);
1343 1343
 
1344
-		if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
1344
+		if ( ! $this->check_is_post_type_allowed($post_type)) {
1345 1345
 			return false;
1346 1346
 		}
1347 1347
 
1348
-		return current_user_can( $post_type->cap->create_posts );
1348
+		return current_user_can($post_type->cap->create_posts);
1349 1349
 	}
1350 1350
 
1351 1351
 	/**
@@ -1357,14 +1357,14 @@  discard block
 block discarded – undo
1357 1357
 	 * @param object $post Post object.
1358 1358
 	 * @return bool Whether the post can be deleted.
1359 1359
 	 */
1360
-	protected function check_delete_permission( $post ) {
1361
-		$post_type = get_post_type_object( $post->post_type );
1360
+	protected function check_delete_permission($post) {
1361
+		$post_type = get_post_type_object($post->post_type);
1362 1362
 
1363
-		if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
1363
+		if ( ! $this->check_is_post_type_allowed($post_type)) {
1364 1364
 			return false;
1365 1365
 		}
1366 1366
 
1367
-		return current_user_can( $post_type->cap->delete_post, $post->ID );
1367
+		return current_user_can($post_type->cap->delete_post, $post->ID);
1368 1368
 	}
1369 1369
 
1370 1370
 	/**
@@ -1377,194 +1377,194 @@  discard block
 block discarded – undo
1377 1377
 	 * @param WP_REST_Request $request Request object.
1378 1378
 	 * @return WP_REST_Response Response object.
1379 1379
 	 */
1380
-	public function prepare_item_for_response( $post, $request ) {
1380
+	public function prepare_item_for_response($post, $request) {
1381 1381
 		$GLOBALS['post'] = $post;
1382 1382
 
1383
-		setup_postdata( $post );
1383
+		setup_postdata($post);
1384 1384
 
1385 1385
 		$schema = $this->get_item_schema();
1386 1386
 
1387 1387
 		// Base fields for every post.
1388 1388
 		$data = array();
1389 1389
 
1390
-		if ( ! empty( $schema['properties']['id'] ) ) {
1390
+		if ( ! empty($schema['properties']['id'])) {
1391 1391
 			$data['id'] = $post->ID;
1392 1392
 		}
1393 1393
 
1394
-		if ( ! empty( $schema['properties']['date'] ) ) {
1395
-			$data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
1394
+		if ( ! empty($schema['properties']['date'])) {
1395
+			$data['date'] = $this->prepare_date_response($post->post_date_gmt, $post->post_date);
1396 1396
 		}
1397 1397
 
1398
-		if ( ! empty( $schema['properties']['date_gmt'] ) ) {
1398
+		if ( ! empty($schema['properties']['date_gmt'])) {
1399 1399
 			// For drafts, `post_date_gmt` may not be set, indicating that the
1400 1400
 			// date of the draft should be updated each time it is saved (see
1401 1401
 			// #38883).  In this case, shim the value based on the `post_date`
1402 1402
 			// field with the site's timezone offset applied.
1403
-			if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
1404
-				$post_date_gmt = get_gmt_from_date( $post->post_date );
1403
+			if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
1404
+				$post_date_gmt = get_gmt_from_date($post->post_date);
1405 1405
 			} else {
1406 1406
 				$post_date_gmt = $post->post_date_gmt;
1407 1407
 			}
1408
-			$data['date_gmt'] = $this->prepare_date_response( $post_date_gmt );
1408
+			$data['date_gmt'] = $this->prepare_date_response($post_date_gmt);
1409 1409
 		}
1410 1410
 
1411
-		if ( ! empty( $schema['properties']['guid'] ) ) {
1411
+		if ( ! empty($schema['properties']['guid'])) {
1412 1412
 			$data['guid'] = array(
1413 1413
 				/** This filter is documented in wp-includes/post-template.php */
1414
-				'rendered' => apply_filters( 'get_the_guid', $post->guid ),
1414
+				'rendered' => apply_filters('get_the_guid', $post->guid),
1415 1415
 				'raw'      => $post->guid,
1416 1416
 			);
1417 1417
 		}
1418 1418
 
1419
-		if ( ! empty( $schema['properties']['modified'] ) ) {
1420
-			$data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified );
1419
+		if ( ! empty($schema['properties']['modified'])) {
1420
+			$data['modified'] = $this->prepare_date_response($post->post_modified_gmt, $post->post_modified);
1421 1421
 		}
1422 1422
 
1423
-		if ( ! empty( $schema['properties']['modified_gmt'] ) ) {
1423
+		if ( ! empty($schema['properties']['modified_gmt'])) {
1424 1424
 			// For drafts, `post_modified_gmt` may not be set (see
1425 1425
 			// `post_date_gmt` comments above).  In this case, shim the value
1426 1426
 			// based on the `post_modified` field with the site's timezone
1427 1427
 			// offset applied.
1428
-			if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) {
1429
-				$post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * 3600 ) );
1428
+			if ('0000-00-00 00:00:00' === $post->post_modified_gmt) {
1429
+				$post_modified_gmt = date('Y-m-d H:i:s', strtotime($post->post_modified) - (get_option('gmt_offset') * 3600));
1430 1430
 			} else {
1431 1431
 				$post_modified_gmt = $post->post_modified_gmt;
1432 1432
 			}
1433
-			$data['modified_gmt'] = $this->prepare_date_response( $post_modified_gmt );
1433
+			$data['modified_gmt'] = $this->prepare_date_response($post_modified_gmt);
1434 1434
 		}
1435 1435
 
1436
-		if ( ! empty( $schema['properties']['password'] ) ) {
1436
+		if ( ! empty($schema['properties']['password'])) {
1437 1437
 			$data['password'] = $post->post_password;
1438 1438
 		}
1439 1439
 
1440
-		if ( ! empty( $schema['properties']['slug'] ) ) {
1440
+		if ( ! empty($schema['properties']['slug'])) {
1441 1441
 			$data['slug'] = $post->post_name;
1442 1442
 		}
1443 1443
 
1444
-		if ( ! empty( $schema['properties']['status'] ) ) {
1444
+		if ( ! empty($schema['properties']['status'])) {
1445 1445
 			$data['status'] = $post->post_status;
1446 1446
 		}
1447 1447
 
1448
-		if ( ! empty( $schema['properties']['type'] ) ) {
1448
+		if ( ! empty($schema['properties']['type'])) {
1449 1449
 			$data['type'] = $post->post_type;
1450 1450
 		}
1451 1451
 
1452
-		if ( ! empty( $schema['properties']['link'] ) ) {
1453
-			$data['link'] = get_permalink( $post->ID );
1452
+		if ( ! empty($schema['properties']['link'])) {
1453
+			$data['link'] = get_permalink($post->ID);
1454 1454
 		}
1455 1455
 
1456
-		if ( ! empty( $schema['properties']['title'] ) ) {
1457
-			add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
1456
+		if ( ! empty($schema['properties']['title'])) {
1457
+			add_filter('protected_title_format', array($this, 'protected_title_format'));
1458 1458
 
1459 1459
 			$data['title'] = array(
1460 1460
 				'raw'      => $post->post_title,
1461
-				'rendered' => get_the_title( $post->ID ),
1461
+				'rendered' => get_the_title($post->ID),
1462 1462
 			);
1463 1463
 
1464
-			remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
1464
+			remove_filter('protected_title_format', array($this, 'protected_title_format'));
1465 1465
 		}
1466 1466
 
1467 1467
 		$has_password_filter = false;
1468 1468
 
1469
-		if ( $this->can_access_password_content( $post, $request ) ) {
1469
+		if ($this->can_access_password_content($post, $request)) {
1470 1470
 			// Allow access to the post, permissions already checked before.
1471
-			add_filter( 'post_password_required', '__return_false' );
1471
+			add_filter('post_password_required', '__return_false');
1472 1472
 
1473 1473
 			$has_password_filter = true;
1474 1474
 		}
1475 1475
 
1476
-		if ( ! empty( $schema['properties']['content'] ) ) {
1476
+		if ( ! empty($schema['properties']['content'])) {
1477 1477
 			$data['content'] = array(
1478 1478
 				'raw'       => $post->post_content,
1479 1479
 				/** This filter is documented in wp-includes/post-template.php */
1480
-				'rendered'  => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ),
1480
+				'rendered'  => post_password_required($post) ? '' : apply_filters('the_content', $post->post_content),
1481 1481
 				'protected' => (bool) $post->post_password,
1482 1482
 			);
1483 1483
 		}
1484 1484
 
1485
-		if ( ! empty( $schema['properties']['excerpt'] ) ) {
1485
+		if ( ! empty($schema['properties']['excerpt'])) {
1486 1486
 			/** This filter is documented in wp-includes/post-template.php */
1487
-			$excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
1487
+			$excerpt = apply_filters('the_excerpt', apply_filters('get_the_excerpt', $post->post_excerpt, $post));
1488 1488
 			$data['excerpt'] = array(
1489 1489
 				'raw'       => $post->post_excerpt,
1490
-				'rendered'  => post_password_required( $post ) ? '' : $excerpt,
1490
+				'rendered'  => post_password_required($post) ? '' : $excerpt,
1491 1491
 				'protected' => (bool) $post->post_password,
1492 1492
 			);
1493 1493
 		}
1494 1494
 
1495
-		if ( $has_password_filter ) {
1495
+		if ($has_password_filter) {
1496 1496
 			// Reset filter.
1497
-			remove_filter( 'post_password_required', '__return_false' );
1497
+			remove_filter('post_password_required', '__return_false');
1498 1498
 		}
1499 1499
 
1500
-		if ( ! empty( $schema['properties']['author'] ) ) {
1500
+		if ( ! empty($schema['properties']['author'])) {
1501 1501
 			$data['author'] = (int) $post->post_author;
1502 1502
 		}
1503 1503
 
1504
-		if ( ! empty( $schema['properties']['featured_media'] ) ) {
1505
-			$data['featured_media'] = (int) get_post_thumbnail_id( $post->ID );
1504
+		if ( ! empty($schema['properties']['featured_media'])) {
1505
+			$data['featured_media'] = (int) get_post_thumbnail_id($post->ID);
1506 1506
 		}
1507 1507
 
1508
-		if ( ! empty( $schema['properties']['parent'] ) ) {
1508
+		if ( ! empty($schema['properties']['parent'])) {
1509 1509
 			$data['parent'] = (int) $post->post_parent;
1510 1510
 		}
1511 1511
 
1512
-		if ( ! empty( $schema['properties']['menu_order'] ) ) {
1512
+		if ( ! empty($schema['properties']['menu_order'])) {
1513 1513
 			$data['menu_order'] = (int) $post->menu_order;
1514 1514
 		}
1515 1515
 
1516
-		if ( ! empty( $schema['properties']['comment_status'] ) ) {
1516
+		if ( ! empty($schema['properties']['comment_status'])) {
1517 1517
 			$data['comment_status'] = $post->comment_status;
1518 1518
 		}
1519 1519
 
1520
-		if ( ! empty( $schema['properties']['ping_status'] ) ) {
1520
+		if ( ! empty($schema['properties']['ping_status'])) {
1521 1521
 			$data['ping_status'] = $post->ping_status;
1522 1522
 		}
1523 1523
 
1524
-		if ( ! empty( $schema['properties']['sticky'] ) ) {
1525
-			$data['sticky'] = is_sticky( $post->ID );
1524
+		if ( ! empty($schema['properties']['sticky'])) {
1525
+			$data['sticky'] = is_sticky($post->ID);
1526 1526
 		}
1527 1527
 
1528
-		if ( ! empty( $schema['properties']['template'] ) ) {
1529
-			if ( $template = get_page_template_slug( $post->ID ) ) {
1528
+		if ( ! empty($schema['properties']['template'])) {
1529
+			if ($template = get_page_template_slug($post->ID)) {
1530 1530
 				$data['template'] = $template;
1531 1531
 			} else {
1532 1532
 				$data['template'] = '';
1533 1533
 			}
1534 1534
 		}
1535 1535
 
1536
-		if ( ! empty( $schema['properties']['format'] ) ) {
1537
-			$data['format'] = get_post_format( $post->ID );
1536
+		if ( ! empty($schema['properties']['format'])) {
1537
+			$data['format'] = get_post_format($post->ID);
1538 1538
 
1539 1539
 			// Fill in blank post format.
1540
-			if ( empty( $data['format'] ) ) {
1540
+			if (empty($data['format'])) {
1541 1541
 				$data['format'] = 'standard';
1542 1542
 			}
1543 1543
 		}
1544 1544
 
1545
-		if ( ! empty( $schema['properties']['meta'] ) ) {
1546
-			$data['meta'] = $this->meta->get_value( $post->ID, $request );
1545
+		if ( ! empty($schema['properties']['meta'])) {
1546
+			$data['meta'] = $this->meta->get_value($post->ID, $request);
1547 1547
 		}
1548 1548
 
1549
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
1549
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
1550 1550
 
1551
-		foreach ( $taxonomies as $taxonomy ) {
1552
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
1551
+		foreach ($taxonomies as $taxonomy) {
1552
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
1553 1553
 
1554
-			if ( ! empty( $schema['properties'][ $base ] ) ) {
1555
-				$terms = get_the_terms( $post, $taxonomy->name );
1556
-				$data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array();
1554
+			if ( ! empty($schema['properties'][$base])) {
1555
+				$terms = get_the_terms($post, $taxonomy->name);
1556
+				$data[$base] = $terms ? array_values(wp_list_pluck($terms, 'term_id')) : array();
1557 1557
 			}
1558 1558
 		}
1559 1559
 
1560
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
1561
-		$data    = $this->add_additional_fields_to_object( $data, $request );
1562
-		$data    = $this->filter_response_by_context( $data, $context );
1560
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
1561
+		$data    = $this->add_additional_fields_to_object($data, $request);
1562
+		$data    = $this->filter_response_by_context($data, $context);
1563 1563
 
1564 1564
 		// Wrap the data in a response object.
1565
-		$response = rest_ensure_response( $data );
1565
+		$response = rest_ensure_response($data);
1566 1566
 
1567
-		$response->add_links( $this->prepare_links( $post ) );
1567
+		$response->add_links($this->prepare_links($post));
1568 1568
 
1569 1569
 		/**
1570 1570
 		 * Filters the post data for a response.
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 		 * @param WP_Post          $post     Post object.
1578 1578
 		 * @param WP_REST_Request  $request  Request object.
1579 1579
 		 */
1580
-		return apply_filters( "rest_prepare_{$this->post_type}", $response, $post, $request );
1580
+		return apply_filters("rest_prepare_{$this->post_type}", $response, $post, $request);
1581 1581
 	}
1582 1582
 
1583 1583
 	/**
@@ -1605,33 +1605,33 @@  discard block
 block discarded – undo
1605 1605
 	 * @param WP_Post $post Post object.
1606 1606
 	 * @return array Links for the given post.
1607 1607
 	 */
1608
-	protected function prepare_links( $post ) {
1609
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1608
+	protected function prepare_links($post) {
1609
+		$base = sprintf('%s/%s', $this->namespace, $this->rest_base);
1610 1610
 
1611 1611
 		// Entity meta.
1612 1612
 		$links = array(
1613 1613
 			'self' => array(
1614
-				'href'   => rest_url( trailingslashit( $base ) . $post->ID ),
1614
+				'href'   => rest_url(trailingslashit($base).$post->ID),
1615 1615
 			),
1616 1616
 			'collection' => array(
1617
-				'href'   => rest_url( $base ),
1617
+				'href'   => rest_url($base),
1618 1618
 			),
1619 1619
 			'about'      => array(
1620
-				'href'   => rest_url( 'wp/v2/types/' . $this->post_type ),
1620
+				'href'   => rest_url('wp/v2/types/'.$this->post_type),
1621 1621
 			),
1622 1622
 		);
1623 1623
 
1624
-		if ( ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'author' ) )
1625
-			&& ! empty( $post->post_author ) ) {
1624
+		if ((in_array($post->post_type, array('post', 'page'), true) || post_type_supports($post->post_type, 'author'))
1625
+			&& ! empty($post->post_author)) {
1626 1626
 			$links['author'] = array(
1627
-				'href'       => rest_url( 'wp/v2/users/' . $post->post_author ),
1627
+				'href'       => rest_url('wp/v2/users/'.$post->post_author),
1628 1628
 				'embeddable' => true,
1629 1629
 			);
1630 1630
 		}
1631 1631
 
1632
-		if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'comments' ) ) {
1633
-			$replies_url = rest_url( 'wp/v2/comments' );
1634
-			$replies_url = add_query_arg( 'post', $post->ID, $replies_url );
1632
+		if (in_array($post->post_type, array('post', 'page'), true) || post_type_supports($post->post_type, 'comments')) {
1633
+			$replies_url = rest_url('wp/v2/comments');
1634
+			$replies_url = add_query_arg('post', $post->ID, $replies_url);
1635 1635
 
1636 1636
 			$links['replies'] = array(
1637 1637
 				'href'       => $replies_url,
@@ -1639,24 +1639,24 @@  discard block
 block discarded – undo
1639 1639
 			);
1640 1640
 		}
1641 1641
 
1642
-		if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
1642
+		if (in_array($post->post_type, array('post', 'page'), true) || post_type_supports($post->post_type, 'revisions')) {
1643 1643
 			$links['version-history'] = array(
1644
-				'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
1644
+				'href' => rest_url(trailingslashit($base).$post->ID.'/revisions'),
1645 1645
 			);
1646 1646
 		}
1647 1647
 
1648
-		$post_type_obj = get_post_type_object( $post->post_type );
1648
+		$post_type_obj = get_post_type_object($post->post_type);
1649 1649
 
1650
-		if ( $post_type_obj->hierarchical && ! empty( $post->post_parent ) ) {
1650
+		if ($post_type_obj->hierarchical && ! empty($post->post_parent)) {
1651 1651
 			$links['up'] = array(
1652
-				'href'       => rest_url( trailingslashit( $base ) . (int) $post->post_parent ),
1652
+				'href'       => rest_url(trailingslashit($base).(int) $post->post_parent),
1653 1653
 				'embeddable' => true,
1654 1654
 			);
1655 1655
 		}
1656 1656
 
1657 1657
 		// If we have a featured media, add that.
1658
-		if ( $featured_media = get_post_thumbnail_id( $post->ID ) ) {
1659
-			$image_url = rest_url( 'wp/v2/media/' . $featured_media );
1658
+		if ($featured_media = get_post_thumbnail_id($post->ID)) {
1659
+			$image_url = rest_url('wp/v2/media/'.$featured_media);
1660 1660
 
1661 1661
 			$links['https://api.w.org/featuredmedia'] = array(
1662 1662
 				'href'       => $image_url,
@@ -1664,34 +1664,34 @@  discard block
 block discarded – undo
1664 1664
 			);
1665 1665
 		}
1666 1666
 
1667
-		if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ), true ) ) {
1668
-			$attachments_url = rest_url( 'wp/v2/media' );
1669
-			$attachments_url = add_query_arg( 'parent', $post->ID, $attachments_url );
1667
+		if ( ! in_array($post->post_type, array('attachment', 'nav_menu_item', 'revision'), true)) {
1668
+			$attachments_url = rest_url('wp/v2/media');
1669
+			$attachments_url = add_query_arg('parent', $post->ID, $attachments_url);
1670 1670
 
1671 1671
 			$links['https://api.w.org/attachment'] = array(
1672 1672
 				'href' => $attachments_url,
1673 1673
 			);
1674 1674
 		}
1675 1675
 
1676
-		$taxonomies = get_object_taxonomies( $post->post_type );
1676
+		$taxonomies = get_object_taxonomies($post->post_type);
1677 1677
 
1678
-		if ( ! empty( $taxonomies ) ) {
1678
+		if ( ! empty($taxonomies)) {
1679 1679
 			$links['https://api.w.org/term'] = array();
1680 1680
 
1681
-			foreach ( $taxonomies as $tax ) {
1682
-				$taxonomy_obj = get_taxonomy( $tax );
1681
+			foreach ($taxonomies as $tax) {
1682
+				$taxonomy_obj = get_taxonomy($tax);
1683 1683
 
1684 1684
 				// Skip taxonomies that are not public.
1685
-				if ( empty( $taxonomy_obj->show_in_rest ) ) {
1685
+				if (empty($taxonomy_obj->show_in_rest)) {
1686 1686
 					continue;
1687 1687
 				}
1688 1688
 
1689
-				$tax_base = ! empty( $taxonomy_obj->rest_base ) ? $taxonomy_obj->rest_base : $tax;
1689
+				$tax_base = ! empty($taxonomy_obj->rest_base) ? $taxonomy_obj->rest_base : $tax;
1690 1690
 
1691 1691
 				$terms_url = add_query_arg(
1692 1692
 					'post',
1693 1693
 					$post->ID,
1694
-					rest_url( 'wp/v2/' . $tax_base )
1694
+					rest_url('wp/v2/'.$tax_base)
1695 1695
 				);
1696 1696
 
1697 1697
 				$links['https://api.w.org/term'][] = array(
@@ -1722,99 +1722,99 @@  discard block
 block discarded – undo
1722 1722
 			// Base properties for every Post.
1723 1723
 			'properties' => array(
1724 1724
 				'date'            => array(
1725
-					'description' => __( "The date the object was published, in the site's timezone." ),
1725
+					'description' => __("The date the object was published, in the site's timezone."),
1726 1726
 					'type'        => 'string',
1727 1727
 					'format'      => 'date-time',
1728
-					'context'     => array( 'view', 'edit', 'embed' ),
1728
+					'context'     => array('view', 'edit', 'embed'),
1729 1729
 				),
1730 1730
 				'date_gmt'        => array(
1731
-					'description' => __( 'The date the object was published, as GMT.' ),
1731
+					'description' => __('The date the object was published, as GMT.'),
1732 1732
 					'type'        => 'string',
1733 1733
 					'format'      => 'date-time',
1734
-					'context'     => array( 'view', 'edit' ),
1734
+					'context'     => array('view', 'edit'),
1735 1735
 				),
1736 1736
 				'guid'            => array(
1737
-					'description' => __( 'The globally unique identifier for the object.' ),
1737
+					'description' => __('The globally unique identifier for the object.'),
1738 1738
 					'type'        => 'object',
1739
-					'context'     => array( 'view', 'edit' ),
1739
+					'context'     => array('view', 'edit'),
1740 1740
 					'readonly'    => true,
1741 1741
 					'properties'  => array(
1742 1742
 						'raw'      => array(
1743
-							'description' => __( 'GUID for the object, as it exists in the database.' ),
1743
+							'description' => __('GUID for the object, as it exists in the database.'),
1744 1744
 							'type'        => 'string',
1745
-							'context'     => array( 'edit' ),
1745
+							'context'     => array('edit'),
1746 1746
 							'readonly'    => true,
1747 1747
 						),
1748 1748
 						'rendered' => array(
1749
-							'description' => __( 'GUID for the object, transformed for display.' ),
1749
+							'description' => __('GUID for the object, transformed for display.'),
1750 1750
 							'type'        => 'string',
1751
-							'context'     => array( 'view', 'edit' ),
1751
+							'context'     => array('view', 'edit'),
1752 1752
 							'readonly'    => true,
1753 1753
 						),
1754 1754
 					),
1755 1755
 				),
1756 1756
 				'id'              => array(
1757
-					'description' => __( 'Unique identifier for the object.' ),
1757
+					'description' => __('Unique identifier for the object.'),
1758 1758
 					'type'        => 'integer',
1759
-					'context'     => array( 'view', 'edit', 'embed' ),
1759
+					'context'     => array('view', 'edit', 'embed'),
1760 1760
 					'readonly'    => true,
1761 1761
 				),
1762 1762
 				'link'            => array(
1763
-					'description' => __( 'URL to the object.' ),
1763
+					'description' => __('URL to the object.'),
1764 1764
 					'type'        => 'string',
1765 1765
 					'format'      => 'uri',
1766
-					'context'     => array( 'view', 'edit', 'embed' ),
1766
+					'context'     => array('view', 'edit', 'embed'),
1767 1767
 					'readonly'    => true,
1768 1768
 				),
1769 1769
 				'modified'        => array(
1770
-					'description' => __( "The date the object was last modified, in the site's timezone." ),
1770
+					'description' => __("The date the object was last modified, in the site's timezone."),
1771 1771
 					'type'        => 'string',
1772 1772
 					'format'      => 'date-time',
1773
-					'context'     => array( 'view', 'edit' ),
1773
+					'context'     => array('view', 'edit'),
1774 1774
 					'readonly'    => true,
1775 1775
 				),
1776 1776
 				'modified_gmt'    => array(
1777
-					'description' => __( 'The date the object was last modified, as GMT.' ),
1777
+					'description' => __('The date the object was last modified, as GMT.'),
1778 1778
 					'type'        => 'string',
1779 1779
 					'format'      => 'date-time',
1780
-					'context'     => array( 'view', 'edit' ),
1780
+					'context'     => array('view', 'edit'),
1781 1781
 					'readonly'    => true,
1782 1782
 				),
1783 1783
 				'slug'            => array(
1784
-					'description' => __( 'An alphanumeric identifier for the object unique to its type.' ),
1784
+					'description' => __('An alphanumeric identifier for the object unique to its type.'),
1785 1785
 					'type'        => 'string',
1786
-					'context'     => array( 'view', 'edit', 'embed' ),
1786
+					'context'     => array('view', 'edit', 'embed'),
1787 1787
 					'arg_options' => array(
1788
-						'sanitize_callback' => array( $this, 'sanitize_slug' ),
1788
+						'sanitize_callback' => array($this, 'sanitize_slug'),
1789 1789
 					),
1790 1790
 				),
1791 1791
 				'status'          => array(
1792
-					'description' => __( 'A named status for the object.' ),
1792
+					'description' => __('A named status for the object.'),
1793 1793
 					'type'        => 'string',
1794
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1795
-					'context'     => array( 'view', 'edit' ),
1794
+					'enum'        => array_keys(get_post_stati(array('internal' => false))),
1795
+					'context'     => array('view', 'edit'),
1796 1796
 				),
1797 1797
 				'type'            => array(
1798
-					'description' => __( 'Type of Post for the object.' ),
1798
+					'description' => __('Type of Post for the object.'),
1799 1799
 					'type'        => 'string',
1800
-					'context'     => array( 'view', 'edit', 'embed' ),
1800
+					'context'     => array('view', 'edit', 'embed'),
1801 1801
 					'readonly'    => true,
1802 1802
 				),
1803 1803
 				'password'        => array(
1804
-					'description' => __( 'A password to protect access to the content and excerpt.' ),
1804
+					'description' => __('A password to protect access to the content and excerpt.'),
1805 1805
 					'type'        => 'string',
1806
-					'context'     => array( 'edit' ),
1806
+					'context'     => array('edit'),
1807 1807
 				),
1808 1808
 			),
1809 1809
 		);
1810 1810
 
1811
-		$post_type_obj = get_post_type_object( $this->post_type );
1811
+		$post_type_obj = get_post_type_object($this->post_type);
1812 1812
 
1813
-		if ( $post_type_obj->hierarchical ) {
1813
+		if ($post_type_obj->hierarchical) {
1814 1814
 			$schema['properties']['parent'] = array(
1815
-				'description' => __( 'The ID for the parent of the object.' ),
1815
+				'description' => __('The ID for the parent of the object.'),
1816 1816
 				'type'        => 'integer',
1817
-				'context'     => array( 'view', 'edit' ),
1817
+				'context'     => array('view', 'edit'),
1818 1818
 			);
1819 1819
 		}
1820 1820
 
@@ -1861,33 +1861,33 @@  discard block
 block discarded – undo
1861 1861
 				'custom-fields',
1862 1862
 			),
1863 1863
 		);
1864
-		foreach ( $post_type_attributes as $attribute ) {
1865
-			if ( isset( $fixed_schemas[ $this->post_type ] ) && ! in_array( $attribute, $fixed_schemas[ $this->post_type ], true ) ) {
1864
+		foreach ($post_type_attributes as $attribute) {
1865
+			if (isset($fixed_schemas[$this->post_type]) && ! in_array($attribute, $fixed_schemas[$this->post_type], true)) {
1866 1866
 				continue;
1867
-			} elseif ( ! isset( $fixed_schemas[ $this->post_type ] ) && ! post_type_supports( $this->post_type, $attribute ) ) {
1867
+			} elseif ( ! isset($fixed_schemas[$this->post_type]) && ! post_type_supports($this->post_type, $attribute)) {
1868 1868
 				continue;
1869 1869
 			}
1870 1870
 
1871
-			switch ( $attribute ) {
1871
+			switch ($attribute) {
1872 1872
 
1873 1873
 				case 'title':
1874 1874
 					$schema['properties']['title'] = array(
1875
-						'description' => __( 'The title for the object.' ),
1875
+						'description' => __('The title for the object.'),
1876 1876
 						'type'        => 'object',
1877
-						'context'     => array( 'view', 'edit', 'embed' ),
1877
+						'context'     => array('view', 'edit', 'embed'),
1878 1878
 						'arg_options' => array(
1879 1879
 							'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
1880 1880
 						),
1881 1881
 						'properties'  => array(
1882 1882
 							'raw' => array(
1883
-								'description' => __( 'Title for the object, as it exists in the database.' ),
1883
+								'description' => __('Title for the object, as it exists in the database.'),
1884 1884
 								'type'        => 'string',
1885
-								'context'     => array( 'edit' ),
1885
+								'context'     => array('edit'),
1886 1886
 							),
1887 1887
 							'rendered' => array(
1888
-								'description' => __( 'HTML title for the object, transformed for display.' ),
1888
+								'description' => __('HTML title for the object, transformed for display.'),
1889 1889
 								'type'        => 'string',
1890
-								'context'     => array( 'view', 'edit', 'embed' ),
1890
+								'context'     => array('view', 'edit', 'embed'),
1891 1891
 								'readonly'    => true,
1892 1892
 							),
1893 1893
 						),
@@ -1896,28 +1896,28 @@  discard block
 block discarded – undo
1896 1896
 
1897 1897
 				case 'editor':
1898 1898
 					$schema['properties']['content'] = array(
1899
-						'description' => __( 'The content for the object.' ),
1899
+						'description' => __('The content for the object.'),
1900 1900
 						'type'        => 'object',
1901
-						'context'     => array( 'view', 'edit' ),
1901
+						'context'     => array('view', 'edit'),
1902 1902
 						'arg_options' => array(
1903 1903
 							'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
1904 1904
 						),
1905 1905
 						'properties'  => array(
1906 1906
 							'raw' => array(
1907
-								'description' => __( 'Content for the object, as it exists in the database.' ),
1907
+								'description' => __('Content for the object, as it exists in the database.'),
1908 1908
 								'type'        => 'string',
1909
-								'context'     => array( 'edit' ),
1909
+								'context'     => array('edit'),
1910 1910
 							),
1911 1911
 							'rendered' => array(
1912
-								'description' => __( 'HTML content for the object, transformed for display.' ),
1912
+								'description' => __('HTML content for the object, transformed for display.'),
1913 1913
 								'type'        => 'string',
1914
-								'context'     => array( 'view', 'edit' ),
1914
+								'context'     => array('view', 'edit'),
1915 1915
 								'readonly'    => true,
1916 1916
 							),
1917 1917
 							'protected'       => array(
1918
-								'description' => __( 'Whether the content is protected with a password.' ),
1918
+								'description' => __('Whether the content is protected with a password.'),
1919 1919
 								'type'        => 'boolean',
1920
-								'context'     => array( 'view', 'edit', 'embed' ),
1920
+								'context'     => array('view', 'edit', 'embed'),
1921 1921
 								'readonly'    => true,
1922 1922
 							),
1923 1923
 						),
@@ -1926,36 +1926,36 @@  discard block
 block discarded – undo
1926 1926
 
1927 1927
 				case 'author':
1928 1928
 					$schema['properties']['author'] = array(
1929
-						'description' => __( 'The ID for the author of the object.' ),
1929
+						'description' => __('The ID for the author of the object.'),
1930 1930
 						'type'        => 'integer',
1931
-						'context'     => array( 'view', 'edit', 'embed' ),
1931
+						'context'     => array('view', 'edit', 'embed'),
1932 1932
 					);
1933 1933
 					break;
1934 1934
 
1935 1935
 				case 'excerpt':
1936 1936
 					$schema['properties']['excerpt'] = array(
1937
-						'description' => __( 'The excerpt for the object.' ),
1937
+						'description' => __('The excerpt for the object.'),
1938 1938
 						'type'        => 'object',
1939
-						'context'     => array( 'view', 'edit', 'embed' ),
1939
+						'context'     => array('view', 'edit', 'embed'),
1940 1940
 						'arg_options' => array(
1941 1941
 							'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
1942 1942
 						),
1943 1943
 						'properties'  => array(
1944 1944
 							'raw' => array(
1945
-								'description' => __( 'Excerpt for the object, as it exists in the database.' ),
1945
+								'description' => __('Excerpt for the object, as it exists in the database.'),
1946 1946
 								'type'        => 'string',
1947
-								'context'     => array( 'edit' ),
1947
+								'context'     => array('edit'),
1948 1948
 							),
1949 1949
 							'rendered' => array(
1950
-								'description' => __( 'HTML excerpt for the object, transformed for display.' ),
1950
+								'description' => __('HTML excerpt for the object, transformed for display.'),
1951 1951
 								'type'        => 'string',
1952
-								'context'     => array( 'view', 'edit', 'embed' ),
1952
+								'context'     => array('view', 'edit', 'embed'),
1953 1953
 								'readonly'    => true,
1954 1954
 							),
1955 1955
 							'protected'       => array(
1956
-								'description' => __( 'Whether the excerpt is protected with a password.' ),
1956
+								'description' => __('Whether the excerpt is protected with a password.'),
1957 1957
 								'type'        => 'boolean',
1958
-								'context'     => array( 'view', 'edit', 'embed' ),
1958
+								'context'     => array('view', 'edit', 'embed'),
1959 1959
 								'readonly'    => true,
1960 1960
 							),
1961 1961
 						),
@@ -1964,44 +1964,44 @@  discard block
 block discarded – undo
1964 1964
 
1965 1965
 				case 'thumbnail':
1966 1966
 					$schema['properties']['featured_media'] = array(
1967
-						'description' => __( 'The ID of the featured media for the object.' ),
1967
+						'description' => __('The ID of the featured media for the object.'),
1968 1968
 						'type'        => 'integer',
1969
-						'context'     => array( 'view', 'edit', 'embed' ),
1969
+						'context'     => array('view', 'edit', 'embed'),
1970 1970
 					);
1971 1971
 					break;
1972 1972
 
1973 1973
 				case 'comments':
1974 1974
 					$schema['properties']['comment_status'] = array(
1975
-						'description' => __( 'Whether or not comments are open on the object.' ),
1975
+						'description' => __('Whether or not comments are open on the object.'),
1976 1976
 						'type'        => 'string',
1977
-						'enum'        => array( 'open', 'closed' ),
1978
-						'context'     => array( 'view', 'edit' ),
1977
+						'enum'        => array('open', 'closed'),
1978
+						'context'     => array('view', 'edit'),
1979 1979
 					);
1980 1980
 					$schema['properties']['ping_status'] = array(
1981
-						'description' => __( 'Whether or not the object can be pinged.' ),
1981
+						'description' => __('Whether or not the object can be pinged.'),
1982 1982
 						'type'        => 'string',
1983
-						'enum'        => array( 'open', 'closed' ),
1984
-						'context'     => array( 'view', 'edit' ),
1983
+						'enum'        => array('open', 'closed'),
1984
+						'context'     => array('view', 'edit'),
1985 1985
 					);
1986 1986
 					break;
1987 1987
 
1988 1988
 				case 'page-attributes':
1989 1989
 					$schema['properties']['menu_order'] = array(
1990
-						'description' => __( 'The order of the object in relation to other object of its type.' ),
1990
+						'description' => __('The order of the object in relation to other object of its type.'),
1991 1991
 						'type'        => 'integer',
1992
-						'context'     => array( 'view', 'edit' ),
1992
+						'context'     => array('view', 'edit'),
1993 1993
 					);
1994 1994
 					break;
1995 1995
 
1996 1996
 				case 'post-formats':
1997 1997
 					// Get the native post formats and remove the array keys.
1998
-					$formats = array_values( get_post_format_slugs() );
1998
+					$formats = array_values(get_post_format_slugs());
1999 1999
 
2000 2000
 					$schema['properties']['format'] = array(
2001
-						'description' => __( 'The format for the object.' ),
2001
+						'description' => __('The format for the object.'),
2002 2002
 						'type'        => 'string',
2003 2003
 						'enum'        => $formats,
2004
-						'context'     => array( 'view', 'edit' ),
2004
+						'context'     => array('view', 'edit'),
2005 2005
 					);
2006 2006
 					break;
2007 2007
 
@@ -2012,36 +2012,36 @@  discard block
 block discarded – undo
2012 2012
 			}
2013 2013
 		}
2014 2014
 
2015
-		if ( 'post' === $this->post_type ) {
2015
+		if ('post' === $this->post_type) {
2016 2016
 			$schema['properties']['sticky'] = array(
2017
-				'description' => __( 'Whether or not the object should be treated as sticky.' ),
2017
+				'description' => __('Whether or not the object should be treated as sticky.'),
2018 2018
 				'type'        => 'boolean',
2019
-				'context'     => array( 'view', 'edit' ),
2019
+				'context'     => array('view', 'edit'),
2020 2020
 			);
2021 2021
 		}
2022 2022
 
2023 2023
 		$schema['properties']['template'] = array(
2024
-			'description' => __( 'The theme file to use to display the object.' ),
2024
+			'description' => __('The theme file to use to display the object.'),
2025 2025
 			'type'        => 'string',
2026
-			'enum'        => array_merge( array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ), array( '' ) ),
2027
-			'context'     => array( 'view', 'edit' ),
2026
+			'enum'        => array_merge(array_keys(wp_get_theme()->get_page_templates(null, $this->post_type)), array('')),
2027
+			'context'     => array('view', 'edit'),
2028 2028
 		);
2029 2029
 
2030
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
2031
-		foreach ( $taxonomies as $taxonomy ) {
2032
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
2033
-			$schema['properties'][ $base ] = array(
2030
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
2031
+		foreach ($taxonomies as $taxonomy) {
2032
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
2033
+			$schema['properties'][$base] = array(
2034 2034
 				/* translators: %s: taxonomy name */
2035
-				'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ),
2035
+				'description' => sprintf(__('The terms assigned to the object in the %s taxonomy.'), $taxonomy->name),
2036 2036
 				'type'        => 'array',
2037 2037
 				'items'       => array(
2038 2038
 					'type'    => 'integer',
2039 2039
 				),
2040
-				'context'     => array( 'view', 'edit' ),
2040
+				'context'     => array('view', 'edit'),
2041 2041
 			);
2042 2042
 		}
2043 2043
 
2044
-		return $this->add_additional_fields_schema( $schema );
2044
+		return $this->add_additional_fields_schema($schema);
2045 2045
 	}
2046 2046
 
2047 2047
 	/**
@@ -2058,14 +2058,14 @@  discard block
 block discarded – undo
2058 2058
 		$query_params['context']['default'] = 'view';
2059 2059
 
2060 2060
 		$query_params['after'] = array(
2061
-			'description'        => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
2061
+			'description'        => __('Limit response to posts published after a given ISO8601 compliant date.'),
2062 2062
 			'type'               => 'string',
2063 2063
 			'format'             => 'date-time',
2064 2064
 		);
2065 2065
 
2066
-		if ( post_type_supports( $this->post_type, 'author' ) ) {
2066
+		if (post_type_supports($this->post_type, 'author')) {
2067 2067
 			$query_params['author'] = array(
2068
-				'description'         => __( 'Limit result set to posts assigned to specific authors.' ),
2068
+				'description'         => __('Limit result set to posts assigned to specific authors.'),
2069 2069
 				'type'                => 'array',
2070 2070
 				'items'               => array(
2071 2071
 					'type'            => 'integer',
@@ -2073,7 +2073,7 @@  discard block
 block discarded – undo
2073 2073
 				'default'             => array(),
2074 2074
 			);
2075 2075
 			$query_params['author_exclude'] = array(
2076
-				'description'         => __( 'Ensure result set excludes posts assigned to specific authors.' ),
2076
+				'description'         => __('Ensure result set excludes posts assigned to specific authors.'),
2077 2077
 				'type'                => 'array',
2078 2078
 				'items'               => array(
2079 2079
 					'type'            => 'integer',
@@ -2083,13 +2083,13 @@  discard block
 block discarded – undo
2083 2083
 		}
2084 2084
 
2085 2085
 		$query_params['before'] = array(
2086
-			'description'        => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
2086
+			'description'        => __('Limit response to posts published before a given ISO8601 compliant date.'),
2087 2087
 			'type'               => 'string',
2088 2088
 			'format'             => 'date-time',
2089 2089
 		);
2090 2090
 
2091 2091
 		$query_params['exclude'] = array(
2092
-			'description'        => __( 'Ensure result set excludes specific IDs.' ),
2092
+			'description'        => __('Ensure result set excludes specific IDs.'),
2093 2093
 			'type'               => 'array',
2094 2094
 			'items'              => array(
2095 2095
 				'type'           => 'integer',
@@ -2098,7 +2098,7 @@  discard block
 block discarded – undo
2098 2098
 		);
2099 2099
 
2100 2100
 		$query_params['include'] = array(
2101
-			'description'        => __( 'Limit result set to specific IDs.' ),
2101
+			'description'        => __('Limit result set to specific IDs.'),
2102 2102
 			'type'               => 'array',
2103 2103
 			'items'              => array(
2104 2104
 				'type'           => 'integer',
@@ -2106,27 +2106,27 @@  discard block
 block discarded – undo
2106 2106
 			'default'            => array(),
2107 2107
 		);
2108 2108
 
2109
-		if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
2109
+		if ('page' === $this->post_type || post_type_supports($this->post_type, 'page-attributes')) {
2110 2110
 			$query_params['menu_order'] = array(
2111
-				'description'        => __( 'Limit result set to posts with a specific menu_order value.' ),
2111
+				'description'        => __('Limit result set to posts with a specific menu_order value.'),
2112 2112
 				'type'               => 'integer',
2113 2113
 			);
2114 2114
 		}
2115 2115
 
2116 2116
 		$query_params['offset'] = array(
2117
-			'description'        => __( 'Offset the result set by a specific number of items.' ),
2117
+			'description'        => __('Offset the result set by a specific number of items.'),
2118 2118
 			'type'               => 'integer',
2119 2119
 		);
2120 2120
 
2121 2121
 		$query_params['order'] = array(
2122
-			'description'        => __( 'Order sort attribute ascending or descending.' ),
2122
+			'description'        => __('Order sort attribute ascending or descending.'),
2123 2123
 			'type'               => 'string',
2124 2124
 			'default'            => 'desc',
2125
-			'enum'               => array( 'asc', 'desc' ),
2125
+			'enum'               => array('asc', 'desc'),
2126 2126
 		);
2127 2127
 
2128 2128
 		$query_params['orderby'] = array(
2129
-			'description'        => __( 'Sort collection by object attribute.' ),
2129
+			'description'        => __('Sort collection by object attribute.'),
2130 2130
 			'type'               => 'string',
2131 2131
 			'default'            => 'date',
2132 2132
 			'enum'               => array(
@@ -2142,15 +2142,15 @@  discard block
 block discarded – undo
2142 2142
 			),
2143 2143
 		);
2144 2144
 
2145
-		if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
2145
+		if ('page' === $this->post_type || post_type_supports($this->post_type, 'page-attributes')) {
2146 2146
 			$query_params['orderby']['enum'][] = 'menu_order';
2147 2147
 		}
2148 2148
 
2149
-		$post_type = get_post_type_object( $this->post_type );
2149
+		$post_type = get_post_type_object($this->post_type);
2150 2150
 
2151
-		if ( $post_type->hierarchical || 'attachment' === $this->post_type ) {
2151
+		if ($post_type->hierarchical || 'attachment' === $this->post_type) {
2152 2152
 			$query_params['parent'] = array(
2153
-				'description'       => __( 'Limit result set to items with particular parent IDs.' ),
2153
+				'description'       => __('Limit result set to items with particular parent IDs.'),
2154 2154
 				'type'              => 'array',
2155 2155
 				'items'             => array(
2156 2156
 					'type'          => 'integer',
@@ -2158,7 +2158,7 @@  discard block
 block discarded – undo
2158 2158
 				'default'           => array(),
2159 2159
 			);
2160 2160
 			$query_params['parent_exclude'] = array(
2161
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.' ),
2161
+				'description'       => __('Limit result set to all items except those of a particular parent ID.'),
2162 2162
 				'type'              => 'array',
2163 2163
 				'items'             => array(
2164 2164
 					'type'          => 'integer',
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
 		}
2169 2169
 
2170 2170
 		$query_params['slug'] = array(
2171
-			'description'       => __( 'Limit result set to posts with one or more specific slugs.' ),
2171
+			'description'       => __('Limit result set to posts with one or more specific slugs.'),
2172 2172
 			'type'              => 'array',
2173 2173
 			'items'             => array(
2174 2174
 				'type'          => 'string',
@@ -2178,23 +2178,23 @@  discard block
 block discarded – undo
2178 2178
 
2179 2179
 		$query_params['status'] = array(
2180 2180
 			'default'           => 'publish',
2181
-			'description'       => __( 'Limit result set to posts assigned one or more statuses.' ),
2181
+			'description'       => __('Limit result set to posts assigned one or more statuses.'),
2182 2182
 			'type'              => 'array',
2183 2183
 			'items'             => array(
2184
-				'enum'          => array_merge( array_keys( get_post_stati() ), array( 'any' ) ),
2184
+				'enum'          => array_merge(array_keys(get_post_stati()), array('any')),
2185 2185
 				'type'          => 'string',
2186 2186
 			),
2187
-			'sanitize_callback' => array( $this, 'sanitize_post_statuses' ),
2187
+			'sanitize_callback' => array($this, 'sanitize_post_statuses'),
2188 2188
 		);
2189 2189
 
2190
-		$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
2190
+		$taxonomies = wp_list_filter(get_object_taxonomies($this->post_type, 'objects'), array('show_in_rest' => true));
2191 2191
 
2192
-		foreach ( $taxonomies as $taxonomy ) {
2193
-			$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
2192
+		foreach ($taxonomies as $taxonomy) {
2193
+			$base = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
2194 2194
 
2195
-			$query_params[ $base ] = array(
2195
+			$query_params[$base] = array(
2196 2196
 				/* translators: %s: taxonomy name */
2197
-				'description'       => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ),
2197
+				'description'       => sprintf(__('Limit result set to all items that have the specified term assigned in the %s taxonomy.'), $base),
2198 2198
 				'type'              => 'array',
2199 2199
 				'items'             => array(
2200 2200
 					'type'          => 'integer',
@@ -2202,9 +2202,9 @@  discard block
 block discarded – undo
2202 2202
 				'default'           => array(),
2203 2203
 			);
2204 2204
 
2205
-			$query_params[ $base . '_exclude' ] = array(
2205
+			$query_params[$base.'_exclude'] = array(
2206 2206
 				/* translators: %s: taxonomy name */
2207
-				'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ),
2207
+				'description' => sprintf(__('Limit result set to all items except those that have the specified term assigned in the %s taxonomy.'), $base),
2208 2208
 				'type'        => 'array',
2209 2209
 				'items'       => array(
2210 2210
 					'type'    => 'integer',
@@ -2213,9 +2213,9 @@  discard block
 block discarded – undo
2213 2213
 			);
2214 2214
 		}
2215 2215
 
2216
-		if ( 'post' === $this->post_type ) {
2216
+		if ('post' === $this->post_type) {
2217 2217
 			$query_params['sticky'] = array(
2218
-				'description'       => __( 'Limit result set to items that are sticky.' ),
2218
+				'description'       => __('Limit result set to items that are sticky.'),
2219 2219
 				'type'              => 'boolean',
2220 2220
 			);
2221 2221
 		}
@@ -2235,7 +2235,7 @@  discard block
 block discarded – undo
2235 2235
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
2236 2236
 		 * @param WP_Post_Type $post_type    Post type object.
2237 2237
 		 */
2238
-		return apply_filters( "rest_{$this->post_type}_collection_params", $query_params, $post_type );
2238
+		return apply_filters("rest_{$this->post_type}_collection_params", $query_params, $post_type);
2239 2239
 	}
2240 2240
 
2241 2241
 	/**
@@ -2250,27 +2250,27 @@  discard block
 block discarded – undo
2250 2250
 	 * @param  string          $parameter Additional parameter to pass to validation.
2251 2251
 	 * @return array|WP_Error A list of valid statuses, otherwise WP_Error object.
2252 2252
 	 */
2253
-	public function sanitize_post_statuses( $statuses, $request, $parameter ) {
2254
-		$statuses = wp_parse_slug_list( $statuses );
2253
+	public function sanitize_post_statuses($statuses, $request, $parameter) {
2254
+		$statuses = wp_parse_slug_list($statuses);
2255 2255
 
2256 2256
 		// The default status is different in WP_REST_Attachments_Controller
2257 2257
 		$attributes = $request->get_attributes();
2258 2258
 		$default_status = $attributes['args']['status']['default'];
2259 2259
 
2260
-		foreach ( $statuses as $status ) {
2261
-			if ( $status === $default_status ) {
2260
+		foreach ($statuses as $status) {
2261
+			if ($status === $default_status) {
2262 2262
 				continue;
2263 2263
 			}
2264 2264
 
2265
-			$post_type_obj = get_post_type_object( $this->post_type );
2265
+			$post_type_obj = get_post_type_object($this->post_type);
2266 2266
 
2267
-			if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
2268
-				$result = rest_validate_request_arg( $status, $request, $parameter );
2269
-				if ( is_wp_error( $result ) ) {
2267
+			if (current_user_can($post_type_obj->cap->edit_posts)) {
2268
+				$result = rest_validate_request_arg($status, $request, $parameter);
2269
+				if (is_wp_error($result)) {
2270 2270
 					return $result;
2271 2271
 				}
2272 2272
 			} else {
2273
-				return new WP_Error( 'rest_forbidden_status', __( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) );
2273
+				return new WP_Error('rest_forbidden_status', __('Status is forbidden.'), array('status' => rest_authorization_required_code()));
2274 2274
 			}
2275 2275
 		}
2276 2276
 
Please login to merge, or discard this patch.
wp-tests-config-sample.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
4
-define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
4
+define('ABSPATH', dirname(__FILE__).'/src/');
5 5
 
6 6
 /*
7 7
  * Path to the theme to test with.
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * The 'default' theme is symlinked from test/phpunit/data/themedir1/default into
10 10
  * the themes directory of the WordPress install defined above.
11 11
  */
12
-define( 'WP_DEFAULT_THEME', 'default' );
12
+define('WP_DEFAULT_THEME', 'default');
13 13
 
14 14
 // Test with multisite enabled.
15 15
 // Alternatively, use the tests/phpunit/multisite.xml configuration file.
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 // define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );
21 21
 
22 22
 // Test with WordPress debug mode (default).
23
-define( 'WP_DEBUG', true );
23
+define('WP_DEBUG', true);
24 24
 
25 25
 // ** MySQL settings ** //
26 26
 
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
 // These tests will DROP ALL TABLES in the database with the prefix named below.
32 32
 // DO NOT use a production database or one that is shared with something else.
33 33
 
34
-define( 'DB_NAME', 'youremptytestdbnamehere' );
35
-define( 'DB_USER', 'yourusernamehere' );
36
-define( 'DB_PASSWORD', 'yourpasswordhere' );
37
-define( 'DB_HOST', 'localhost' );
38
-define( 'DB_CHARSET', 'utf8' );
39
-define( 'DB_COLLATE', '' );
34
+define('DB_NAME', 'youremptytestdbnamehere');
35
+define('DB_USER', 'yourusernamehere');
36
+define('DB_PASSWORD', 'yourpasswordhere');
37
+define('DB_HOST', 'localhost');
38
+define('DB_CHARSET', 'utf8');
39
+define('DB_COLLATE', '');
40 40
 
41
-$table_prefix  = 'wptests_';   // Only numbers, letters, and underscores please!
41
+$table_prefix = 'wptests_'; // Only numbers, letters, and underscores please!
42 42
 
43
-define( 'WP_TESTS_DOMAIN', 'example.org' );
44
-define( 'WP_TESTS_EMAIL', '[email protected]' );
45
-define( 'WP_TESTS_TITLE', 'Test Blog' );
43
+define('WP_TESTS_DOMAIN', 'example.org');
44
+define('WP_TESTS_EMAIL', '[email protected]');
45
+define('WP_TESTS_TITLE', 'Test Blog');
46 46
 
47
-define( 'WP_PHP_BINARY', 'php' );
47
+define('WP_PHP_BINARY', 'php');
48 48
 
49
-define( 'WPLANG', '' );
49
+define('WPLANG', '');
Please login to merge, or discard this patch.
src/wp-content/themes/twentyseventeen/search.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 <div class="wrap">
16 16
 
17 17
 	<header class="page-header">
18
-		<?php if ( have_posts() ) : ?>
19
-			<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyseventeen' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
18
+		<?php if (have_posts()) : ?>
19
+			<h1 class="page-title"><?php printf(__('Search Results for: %s', 'twentyseventeen'), '<span>'.get_search_query().'</span>'); ?></h1>
20 20
 		<?php else : ?>
21
-			<h1 class="page-title"><?php _e( 'Nothing Found', 'twentyseventeen' ); ?></h1>
21
+			<h1 class="page-title"><?php _e('Nothing Found', 'twentyseventeen'); ?></h1>
22 22
 		<?php endif; ?>
23 23
 	</header><!-- .page-header -->
24 24
 
@@ -26,28 +26,28 @@  discard block
 block discarded – undo
26 26
 		<main id="main" class="site-main" role="main">
27 27
 
28 28
 		<?php
29
-		if ( have_posts() ) :
29
+		if (have_posts()) :
30 30
 			/* Start the Loop */
31
-			while ( have_posts() ) : the_post();
31
+			while (have_posts()) : the_post();
32 32
 
33 33
 				/**
34 34
 				 * Run the loop for the search to output the results.
35 35
 				 * If you want to overload this in a child theme then include a file
36 36
 				 * called content-search.php and that will be used instead.
37 37
 				 */
38
-				get_template_part( 'template-parts/post/content', 'excerpt' );
38
+				get_template_part('template-parts/post/content', 'excerpt');
39 39
 
40 40
 			endwhile; // End of the loop.
41 41
 
42
-			the_posts_pagination( array(
43
-				'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
44
-				'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
45
-				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
46
-			) );
42
+			the_posts_pagination(array(
43
+				'prev_text' => twentyseventeen_get_svg(array('icon' => 'arrow-left')).'<span class="screen-reader-text">'.__('Previous page', 'twentyseventeen').'</span>',
44
+				'next_text' => '<span class="screen-reader-text">'.__('Next page', 'twentyseventeen').'</span>'.twentyseventeen_get_svg(array('icon' => 'arrow-right')),
45
+				'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'twentyseventeen').' </span>',
46
+			));
47 47
 
48 48
 		else : ?>
49 49
 
50
-			<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen' ); ?></p>
50
+			<p><?php _e('Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen'); ?></p>
51 51
 			<?php
52 52
 				get_search_form();
53 53
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,11 @@  discard block
 block discarded – undo
17 17
 	<header class="page-header">
18 18
 		<?php if ( have_posts() ) : ?>
19 19
 			<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyseventeen' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
20
-		<?php else : ?>
21
-			<h1 class="page-title"><?php _e( 'Nothing Found', 'twentyseventeen' ); ?></h1>
20
+		<?php else {
21
+	: ?>
22
+			<h1 class="page-title"><?php _e( 'Nothing Found', 'twentyseventeen' );
23
+}
24
+?></h1>
22 25
 		<?php endif; ?>
23 26
 	</header><!-- .page-header -->
24 27
 
@@ -45,9 +48,12 @@  discard block
 block discarded – undo
45 48
 				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
46 49
 			) );
47 50
 
48
-		else : ?>
51
+		else {
52
+			: ?>
49 53
 
50
-			<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen' ); ?></p>
54
+			<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen' );
55
+		}
56
+		?></p>
51 57
 			<?php
52 58
 				get_search_form();
53 59
 
Please login to merge, or discard this patch.
src/wp-content/themes/twentyseventeen/archive.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
 
15 15
 <div class="wrap">
16 16
 
17
-	<?php if ( have_posts() ) : ?>
17
+	<?php if (have_posts()) : ?>
18 18
 		<header class="page-header">
19 19
 			<?php
20
-				the_archive_title( '<h1 class="page-title">', '</h1>' );
21
-				the_archive_description( '<div class="taxonomy-description">', '</div>' );
20
+				the_archive_title('<h1 class="page-title">', '</h1>');
21
+				the_archive_description('<div class="taxonomy-description">', '</div>');
22 22
 			?>
23 23
 		</header><!-- .page-header -->
24 24
 	<?php endif; ?>
@@ -27,29 +27,29 @@  discard block
 block discarded – undo
27 27
 		<main id="main" class="site-main" role="main">
28 28
 
29 29
 		<?php
30
-		if ( have_posts() ) : ?>
30
+		if (have_posts()) : ?>
31 31
 			<?php
32 32
 			/* Start the Loop */
33
-			while ( have_posts() ) : the_post();
33
+			while (have_posts()) : the_post();
34 34
 
35 35
 				/*
36 36
 				 * Include the Post-Format-specific template for the content.
37 37
 				 * If you want to override this in a child theme, then include a file
38 38
 				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
39 39
 				 */
40
-				get_template_part( 'template-parts/post/content', get_post_format() );
40
+				get_template_part('template-parts/post/content', get_post_format());
41 41
 
42 42
 			endwhile;
43 43
 
44
-			the_posts_pagination( array(
45
-				'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
46
-				'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
47
-				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
48
-			) );
44
+			the_posts_pagination(array(
45
+				'prev_text' => twentyseventeen_get_svg(array('icon' => 'arrow-left')).'<span class="screen-reader-text">'.__('Previous page', 'twentyseventeen').'</span>',
46
+				'next_text' => '<span class="screen-reader-text">'.__('Next page', 'twentyseventeen').'</span>'.twentyseventeen_get_svg(array('icon' => 'arrow-right')),
47
+				'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'twentyseventeen').' </span>',
48
+			));
49 49
 
50 50
 		else :
51 51
 
52
-			get_template_part( 'template-parts/post/content', 'none' );
52
+			get_template_part('template-parts/post/content', 'none');
53 53
 
54 54
 		endif; ?>
55 55
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,9 +47,11 @@
 block discarded – undo
47 47
 				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
48 48
 			) );
49 49
 
50
-		else :
50
+		else {
51
+			:
51 52
 
52 53
 			get_template_part( 'template-parts/post/content', 'none' );
54
+		}
53 55
 
54 56
 		endif; ?>
55 57
 
Please login to merge, or discard this patch.
src/wp-content/themes/twentyseventeen/single.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,19 +18,19 @@
 block discarded – undo
18 18
 
19 19
 			<?php
20 20
 			/* Start the Loop */
21
-			while ( have_posts() ) : the_post();
21
+			while (have_posts()) : the_post();
22 22
 
23
-				get_template_part( 'template-parts/post/content', get_post_format() );
23
+				get_template_part('template-parts/post/content', get_post_format());
24 24
 
25 25
 				// If comments are open or we have at least one comment, load up the comment template.
26
-				if ( comments_open() || get_comments_number() ) :
26
+				if (comments_open() || get_comments_number()) :
27 27
 					comments_template();
28 28
 				endif;
29 29
 
30
-				the_post_navigation( array(
31
-					'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>',
32
-					'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>',
33
-				) );
30
+				the_post_navigation(array(
31
+					'prev_text' => '<span class="screen-reader-text">'.__('Previous Post', 'twentyseventeen').'</span><span aria-hidden="true" class="nav-subtitle">'.__('Previous', 'twentyseventeen').'</span> <span class="nav-title"><span class="nav-title-icon-wrapper">'.twentyseventeen_get_svg(array('icon' => 'arrow-left')).'</span>%title</span>',
32
+					'next_text' => '<span class="screen-reader-text">'.__('Next Post', 'twentyseventeen').'</span><span aria-hidden="true" class="nav-subtitle">'.__('Next', 'twentyseventeen').'</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">'.twentyseventeen_get_svg(array('icon' => 'arrow-right')).'</span></span>',
33
+				));
34 34
 
35 35
 			endwhile; // End of the loop.
36 36
 			?>
Please login to merge, or discard this patch.