rest_ensure_response

Advertisement

Summery Summery

Ensures a REST response is a response object (for consistency).

Syntax Syntax

rest_ensure_response( WP_HTTP_Response|WP_Error|mixed $response )

Description Description

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.

Parameters Parameters

$response

(Required) Response to check.

Return Return

(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.

Source Source

File: wp-includes/rest-api.php

 *
 * @since 4.4.0
 * @since 5.3.0 Accept string argument for the request path.
 *
 * @param array|string|WP_REST_Request $request Request to check.
 * @return WP_REST_Request REST request instance.
 */
function rest_ensure_request( $request ) {
	if ( $request instanceof WP_REST_Request ) {
		return $request;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

Advertisement

Leave a Reply