wp/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   502 	/**
   502 	/**
   503 	 * Retrieves all of the registered additional fields for a given object-type.
   503 	 * Retrieves all of the registered additional fields for a given object-type.
   504 	 *
   504 	 *
   505 	 * @since 4.7.0
   505 	 * @since 4.7.0
   506 	 *
   506 	 *
       
   507 	 * @global array $wp_rest_additional_fields Holds registered fields, organized by object type.
       
   508 	 *
   507 	 * @param string $object_type Optional. The object type.
   509 	 * @param string $object_type Optional. The object type.
   508 	 * @return array Registered additional fields (if any), empty array if none or if the object type could
   510 	 * @return array Registered additional fields (if any), empty array if none or if the object type
   509 	 *               not be inferred.
   511 	 *               could not be inferred.
   510 	 */
   512 	 */
   511 	protected function get_additional_fields( $object_type = null ) {
   513 	protected function get_additional_fields( $object_type = null ) {
       
   514 		global $wp_rest_additional_fields;
   512 
   515 
   513 		if ( ! $object_type ) {
   516 		if ( ! $object_type ) {
   514 			$object_type = $this->get_object_type();
   517 			$object_type = $this->get_object_type();
   515 		}
   518 		}
   516 
   519 
   517 		if ( ! $object_type ) {
   520 		if ( ! $object_type ) {
   518 			return array();
   521 			return array();
   519 		}
   522 		}
   520 
       
   521 		global $wp_rest_additional_fields;
       
   522 
   523 
   523 		if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
   524 		if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
   524 			return array();
   525 			return array();
   525 		}
   526 		}
   526 
   527 
   594 			$requested_fields[] = 'id';
   595 			$requested_fields[] = 'id';
   595 		}
   596 		}
   596 		// Return the list of all requested fields which appear in the schema.
   597 		// Return the list of all requested fields which appear in the schema.
   597 		return array_reduce(
   598 		return array_reduce(
   598 			$requested_fields,
   599 			$requested_fields,
   599 			function( $response_fields, $field ) use ( $fields ) {
   600 			static function( $response_fields, $field ) use ( $fields ) {
   600 				if ( in_array( $field, $fields, true ) ) {
   601 				if ( in_array( $field, $fields, true ) ) {
   601 					$response_fields[] = $field;
   602 					$response_fields[] = $field;
   602 					return $response_fields;
   603 					return $response_fields;
   603 				}
   604 				}
   604 				// Check for nested fields if $field is not a direct match.
   605 				// Check for nested fields if $field is not a direct match.