Completed
Pull Request — trunk (#916)
by
unknown
180:08 queued 165:09
created
includes/shim/WP_REST_Controller.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		}
191 191
 
192 192
 		if ( ! empty( $links ) ) {
193
-			$data['_links'] = $links;
193
+			$data[ '_links' ] = $links;
194 194
 		}
195 195
 
196 196
 		return $data;
@@ -207,21 +207,21 @@  discard block
 block discarded – undo
207 207
 
208 208
 		$schema = $this->get_item_schema();
209 209
 		foreach ( $data as $key => $value ) {
210
-			if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
210
+			if ( empty( $schema[ 'properties' ][ $key ] ) || empty( $schema[ 'properties' ][ $key ][ 'context' ] ) ) {
211 211
 				continue;
212 212
 			}
213 213
 
214
-			if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) {
214
+			if ( ! in_array( $context, $schema[ 'properties' ][ $key ][ 'context' ] ) ) {
215 215
 				unset( $data[ $key ] );
216 216
 				continue;
217 217
 			}
218 218
 
219
-			if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) {
220
-				foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) {
221
-					if ( empty( $details['context'] ) ) {
219
+			if ( 'object' === $schema[ 'properties' ][ $key ][ 'type' ] && ! empty( $schema[ 'properties' ][ $key ][ 'properties' ] ) ) {
220
+				foreach ( $schema[ 'properties' ][ $key ][ 'properties' ] as $attribute => $details ) {
221
+					if ( empty( $details[ 'context' ] ) ) {
222 222
 						continue;
223 223
 					}
224
-					if ( ! in_array( $context, $details['context'] ) ) {
224
+					if ( ! in_array( $context, $details[ 'context' ] ) ) {
225 225
 						if ( isset( $data[ $key ][ $attribute ] ) ) {
226 226
 							unset( $data[ $key ][ $attribute ] );
227 227
 						}
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 
252 252
 		$schema = $this->get_item_schema();
253 253
 
254
-		foreach ( $schema['properties'] as &$property ) {
255
-			if ( isset( $property['arg_options'] ) ) {
256
-				unset( $property['arg_options'] );
254
+		foreach ( $schema[ 'properties' ] as &$property ) {
255
+			if ( isset( $property[ 'arg_options' ] ) ) {
256
+				unset( $property[ 'arg_options' ] );
257 257
 			}
258 258
 		}
259 259
 
@@ -310,18 +310,18 @@  discard block
 block discarded – undo
310 310
 			'validate_callback'  => 'rest_validate_request_arg',
311 311
 		);
312 312
 		$schema = $this->get_item_schema();
313
-		if ( empty( $schema['properties'] ) ) {
313
+		if ( empty( $schema[ 'properties' ] ) ) {
314 314
 			return array_merge( $param_details, $args );
315 315
 		}
316 316
 		$contexts = array();
317
-		foreach ( $schema['properties'] as $attributes ) {
318
-			if ( ! empty( $attributes['context'] ) ) {
319
-				$contexts = array_merge( $contexts, $attributes['context'] );
317
+		foreach ( $schema[ 'properties' ] as $attributes ) {
318
+			if ( ! empty( $attributes[ 'context' ] ) ) {
319
+				$contexts = array_merge( $contexts, $attributes[ 'context' ] );
320 320
 			}
321 321
 		}
322 322
 		if ( ! empty( $contexts ) ) {
323
-			$param_details['enum'] = array_unique( $contexts );
324
-			rsort( $param_details['enum'] );
323
+			$param_details[ 'enum' ] = array_unique( $contexts );
324
+			rsort( $param_details[ 'enum' ] );
325 325
 		}
326 326
 		return array_merge( $param_details, $args );
327 327
 	}
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
 
340 340
 		foreach ( $additional_fields as $field_name => $field_options ) {
341 341
 
342
-			if ( ! $field_options['get_callback'] ) {
342
+			if ( ! $field_options[ 'get_callback' ] ) {
343 343
 				continue;
344 344
 			}
345 345
 
346
-			$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
346
+			$object[ $field_name ] = call_user_func( $field_options[ 'get_callback' ], $object, $field_name, $request, $this->get_object_type() );
347 347
 		}
348 348
 
349 349
 		return $object;
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
 		foreach ( $additional_fields as $field_name => $field_options ) {
363 363
 
364
-			if ( ! $field_options['update_callback'] ) {
364
+			if ( ! $field_options[ 'update_callback' ] ) {
365 365
 				continue;
366 366
 			}
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				continue;
371 371
 			}
372 372
 
373
-			call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() );
373
+			call_user_func( $field_options[ 'update_callback' ], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() );
374 374
 		}
375 375
 	}
376 376
 
@@ -382,23 +382,23 @@  discard block
 block discarded – undo
382 382
 	 * @param array $schema Schema array.
383 383
 	 */
384 384
 	protected function add_additional_fields_schema( $schema ) {
385
-		if ( empty( $schema['title'] ) ) {
385
+		if ( empty( $schema[ 'title' ] ) ) {
386 386
 			return $schema;
387 387
 		}
388 388
 
389 389
 		/**
390 390
 		 * Can't use $this->get_object_type otherwise we cause an inf loop.
391 391
 		 */
392
-		$object_type = $schema['title'];
392
+		$object_type = $schema[ 'title' ];
393 393
 
394 394
 		$additional_fields = $this->get_additional_fields( $object_type );
395 395
 
396 396
 		foreach ( $additional_fields as $field_name => $field_options ) {
397
-			if ( ! $field_options['schema'] ) {
397
+			if ( ! $field_options[ 'schema' ] ) {
398 398
 				continue;
399 399
 			}
400 400
 
401
-			$schema['properties'][ $field_name ] = $field_options['schema'];
401
+			$schema[ 'properties' ][ $field_name ] = $field_options[ 'schema' ];
402 402
 		}
403 403
 
404 404
 		return $schema;
@@ -437,11 +437,11 @@  discard block
 block discarded – undo
437 437
 	protected function get_object_type() {
438 438
 		$schema = $this->get_item_schema();
439 439
 
440
-		if ( ! $schema || ! isset( $schema['title'] ) ) {
440
+		if ( ! $schema || ! isset( $schema[ 'title' ] ) ) {
441 441
 			return null;
442 442
 		}
443 443
 
444
-		return $schema['title'];
444
+		return $schema[ 'title' ];
445 445
 	}
446 446
 
447 447
 	/**
@@ -457,13 +457,13 @@  discard block
 block discarded – undo
457 457
 	public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
458 458
 
459 459
 		$schema                = $this->get_item_schema();
460
-		$schema_properties     = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
460
+		$schema_properties     = ! empty( $schema[ 'properties' ] ) ? $schema[ 'properties' ] : array();
461 461
 		$endpoint_args = array();
462 462
 
463 463
 		foreach ( $schema_properties as $field_id => $params ) {
464 464
 
465 465
 			// Arguments specified as `readonly` are not allowed to be set.
466
-			if ( ! empty( $params['readonly'] ) ) {
466
+			if ( ! empty( $params[ 'readonly' ] ) ) {
467 467
 				continue;
468 468
 			}
469 469
 
@@ -472,16 +472,16 @@  discard block
 block discarded – undo
472 472
 				'sanitize_callback' => 'rest_sanitize_request_arg',
473 473
 			);
474 474
 
475
-			if ( isset( $params['description'] ) ) {
476
-				$endpoint_args[ $field_id ]['description'] = $params['description'];
475
+			if ( isset( $params[ 'description' ] ) ) {
476
+				$endpoint_args[ $field_id ][ 'description' ] = $params[ 'description' ];
477 477
 			}
478 478
 
479
-			if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
480
-				$endpoint_args[ $field_id ]['default'] = $params['default'];
479
+			if ( WP_REST_Server::CREATABLE === $method && isset( $params[ 'default' ] ) ) {
480
+				$endpoint_args[ $field_id ][ 'default' ] = $params[ 'default' ];
481 481
 			}
482 482
 
483
-			if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) {
484
-				$endpoint_args[ $field_id ]['required'] = true;
483
+			if ( WP_REST_Server::CREATABLE === $method && ! empty( $params[ 'required' ] ) ) {
484
+				$endpoint_args[ $field_id ][ 'required' ] = true;
485 485
 			}
486 486
 
487 487
 			foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) {
@@ -491,17 +491,17 @@  discard block
 block discarded – undo
491 491
 			}
492 492
 
493 493
 			// Merge in any options provided by the schema property.
494
-			if ( isset( $params['arg_options'] ) ) {
494
+			if ( isset( $params[ 'arg_options' ] ) ) {
495 495
 
496 496
 				// Only use required / default from arg_options on CREATABLE endpoints.
497 497
 				if ( WP_REST_Server::CREATABLE !== $method ) {
498
-					$params['arg_options'] = array_diff_key( $params['arg_options'], array(
498
+					$params[ 'arg_options' ] = array_diff_key( $params[ 'arg_options' ], array(
499 499
 						'required' => '',
500 500
 						'default' => '',
501 501
 					) );
502 502
 				}
503 503
 
504
-				$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] );
504
+				$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params[ 'arg_options' ] );
505 505
 			}
506 506
 		}// End foreach().
507 507
 
Please login to merge, or discard this patch.