wc_rest_validate_reports_request_arg

Validate reports request arguments.

Description

(WP_Error|boolean) wc_rest_validate_reports_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( 'wc_rest_validate_reports_request_arg' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-rest-functions.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 = wc_rest_validate_reports_request_arg($value, $request, $param); 
  15.  

Defined (1)

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

/includes/wc-rest-functions.php  
  1. function wc_rest_validate_reports_request_arg( $value, $request, $param ) { 
  2.  
  3. $attributes = $request->get_attributes(); 
  4. if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) { 
  5. return true; 
  6. $args = $attributes['args'][ $param ]; 
  7.  
  8. if ( 'string' === $args['type'] && ! is_string( $value ) ) { 
  9. return new WP_Error( 'woocommerce_rest_invalid_param', sprintf( __( '%1$s is not of type %2$s', woocommerce ), $param, 'string' ) ); 
  10.  
  11. if ( 'date' === $args['format'] ) { 
  12. $regex = '#^\d{4}-\d{2}-\d{2}$#'; 
  13.  
  14. if ( ! preg_match( $regex, $value, $matches ) ) { 
  15. return new WP_Error( 'woocommerce_rest_invalid_date', __( 'The date you provided is invalid.', woocommerce ) ); 
  16.  
  17. return true;