rest_validate_request_arg

Validate a request argument based on details registered to the route.

Description

(WP_Error|boolean) rest_validate_request_arg( (mixed) $value, (WP_REST_Request) $request, (string) $param ); 

Returns (WP_Error|boolean)

Parameters (3)

0. $value (mixed)
The value.
1. $request (WP_REST_Request)
The request.
2. $param (string)
The param.

Usage

  1. if ( !function_exists( 'rest_validate_request_arg' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4. // The value. 
  5. $value = null; 
  6.  
  7. // The request. 
  8. $request = null; 
  9.  
  10. // The param. 
  11. $param = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = rest_validate_request_arg($value, $request, $param); 
  15.  

Defined (1)

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

/wp-includes/rest-api.php  
  1. function rest_validate_request_arg( $value, $request, $param ) { 
  2. $attributes = $request->get_attributes(); 
  3. if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) { 
  4. return true; 
  5. $args = $attributes['args'][ $param ]; 
  6.  
  7. return rest_validate_value_from_schema( $value, $args, $param );