rest_ensure_request

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

Description

(WP_REST_Request) rest_ensure_request( (array|WP_REST_Request) $request ); 

Returns (WP_REST_Request)

REST request instance.

Parameters (1)

0. $request (array|WP_REST_Request)
Request to check.

Usage

  1. if ( !function_exists( 'rest_ensure_request' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4. // Request to check. 
  5. $request = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = rest_ensure_request($request); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/rest-api.php  
  1. function rest_ensure_request( $request ) { 
  2. if ( $request instanceof WP_REST_Request ) { 
  3. return $request; 
  4.  
  5. return new WP_REST_Request( 'GET', '', $request );