Ensures a REST response is a response object (for consistency).
Description
This implements WP_REST_Response, allowing usage of set_status/header/etc without needing to double-check the object. Will also allow WP_Error to indicate error responses, so users should immediately check for this value.
690functionrest_ensure_response($response){691if(is_wp_error($response)){692return$response;693}694695if($responseinstanceofWP_REST_Response){696return$response;697}698699/*700 * While WP_HTTP_Response is the base class of WP_REST_Response, it doesn't provide701 * all the required methods used in WP_REST_Server::dispatch().702 */703if($responseinstanceofWP_HTTP_Response){704returnnewWP_REST_Response(705$response->get_data(),706$response->get_status(),707$response->get_headers()708);709}710711returnnewWP_REST_Response($response);712}
History
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/rest-api.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.