Changeset 47849 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 05/23/2020 02:34:38 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47842 r47849 507 507 * Ensures a REST response is a response object (for consistency). 508 508 * 509 * This implements WP_ HTTP_Response, allowing usage of `set_status`/`header`/etc509 * This implements WP_REST_Response, allowing usage of `set_status`/`header`/etc 510 510 * without needing to double-check the object. Will also allow WP_Error to indicate error 511 511 * responses, so users should immediately check for this value. … … 513 513 * @since 4.4.0 514 514 * 515 * @param WP_ HTTP_Response|WP_Error|mixed $response Response to check.516 * @return WP_REST_Response| mixedIf response generated an error, WP_Error, if response517 * is already an instance, WP_HTTP_Response, otherwise518 * returns a new WP_REST_Response instance.515 * @param WP_REST_Response|WP_Error|WP_HTTP_Response|mixed $response Response to check. 516 * @return WP_REST_Response|WP_Error If response generated an error, WP_Error, if response 517 * is already an instance, WP_REST_Response, otherwise 518 * returns a new WP_REST_Response instance. 519 519 */ 520 520 function rest_ensure_response( $response ) { … … 523 523 } 524 524 525 if ( $response instanceof WP_REST_Response ) { 526 return $response; 527 } 528 529 // While WP_HTTP_Response is the base class of WP_REST_Response, it doesn't provide 530 // all the required methods used in WP_REST_Server::dispatch(). 525 531 if ( $response instanceof WP_HTTP_Response ) { 526 return $response; 532 return new WP_REST_Response( 533 $response->get_data(), 534 $response->get_status(), 535 $response->get_headers() 536 ); 527 537 } 528 538
Note: See TracChangeset
for help on using the changeset viewer.