rest_ensure_request( array|string|WP_REST_Request $request )

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

Description Description

Parameters Parameters


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

Top ↑

Return Return

(WP_REST_Request) REST request instance.

Top ↑

Source 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 );

Top ↑

Changelog Changelog

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

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.