rest_ensure_response


rest_ensure_response ( $response )

Parameters:
  • (WP_HTTP_Response|WP_Error|mixed) response Response to check.
Returns:
  • (WP_REST_Response|mixed) If response generated an error, WP_Error, if response is already an instance, WP_HTTP_Response, otherwise returns a new WP_REST_Response instance.
Defined at:

Description

Ensures a REST response is a response object (for consistency).This implements WP_HTTP_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.

Related Functions

rest_ensure_request, rest_filter_response_fields, get_oembed_response_data, rest_filter_response_by_context, wp_remote_retrieve_response_code

Top Google Results

User discussions

wpseek mobile