rest_ensure_request() WordPress Function
rest_ensure_request() is a function used to ensure that a request made to the WordPress REST API is valid. This function will check the request method, headers, and body for validity and return an error if any of these are invalid. This function is useful for ensuring that a request made to the WordPress REST API is valid and can be processed by the API.
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 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.3.0 | Accept string argument for the request path. |
4.4.0 | Introduced. |