تابع wc_rest_validate_reports_request_arg اعتبارسنجی داده های گزارش شده

تابع ووکامرسی wc_rest_validate_reports_request_arg – اعتبارسنجی داده های گزارش شده
Syntax – سینتکس
(WP_Error|boolean) wc_rest_validate_reports_request_arg( (mixed) $value, (WP_REST_Request) $request, (string) $param );
Parameters – پارامتر ها (3)
- 1- $value (mixed)
- 2- $request (WP_REST_Request)
- 3- $param (string)
Usage – نحوه استفاده
if ( !function_exists( 'wc_rest_validate_reports_request_arg' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-rest-functions.php';
}
// The value.
$value = null;
// The request.
$request = null;
// The param.
$param = '';
// NOTICE! Understand what this does before running.
$result = wc_rest_validate_reports_request_arg($value, $request, $param);
Defined – محل تعریف
/includes/wc-rest-functions.php
function wc_rest_validate_reports_request_arg( $value, $request, $param ) {
$attributes = $request->get_attributes();
if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
return true;
}
$args = $attributes['args'][ $param ];
if ( 'string' === $args['type'] && ! is_string( $value ) ) {
return new WP_Error( 'woocommerce_rest_invalid_param', sprintf( __( '%1$s is not of type %2$s', woocommerce ), $param, 'string' ) );
}
if ( 'date' === $args['format'] ) {
$regex = '#^\d{4}-\d{2}-\d{2}$#';
if ( ! preg_match( $regex, $value, $matches ) ) {
return new WP_Error( 'woocommerce_rest_invalid_date', __( 'The date you provided is invalid.', woocommerce ) );
}
}
return true;
}
versions – نسخه ها
از نسخه : 2.6.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر