wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
rest_ensure_response › WordPress Function
Seit4.4.0
Veraltetn/v
› rest_ensure_response ( $response )
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Ensures a REST response is a response object (for consistency).
This implements WP_REST_Response, allowing usage ofset_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.Quellcode
function rest_ensure_response( $response ) {
if ( is_wp_error( $response ) ) {
return $response;
}
if ( $response instanceof WP_REST_Response ) {
return $response;
}
/*
* While WP_HTTP_Response is the base class of WP_REST_Response, it doesn't provide
* all the required methods used in WP_REST_Server::dispatch().
*/
if ( $response instanceof WP_HTTP_Response ) {
return new WP_REST_Response(
$response->get_data(),
$response->get_status(),
$response->get_headers()
);
}
return new WP_REST_Response( $response );
}