W3cubDocs

/WordPress

rest_ensure_request( array|string|WP_REST_Request $request )

Ensures request arguments are a request object (for consistency).

Parameters

$request

(array|string|WP_REST_Request) (Required) Request to check.

Return

(WP_REST_Request) REST request instance.

Source

File: wp-includes/rest-api.php

function rest_ensure_request( $request ) {
	if ( $request instanceof WP_REST_Request ) {
		return $request;
	}

	if ( is_string( $request ) ) {
		return new WP_REST_Request( 'GET', $request );
	}

	return new WP_REST_Request( 'GET', '', $request );
}

Changelog

Version Description
5.3.0 Accept string argument for the request path.
4.4.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_ensure_request