wc_rest_validate_reports_request_arg()
Validate reports request arguments.
Хуков нет.
Возвращает
WP_Error|true|false
.
Использование
wc_rest_validate_reports_request_arg( $value, $request, $param );
- $value(разное) (обязательный)
- Value to validate.
- $request(WP_REST_Request) (обязательный)
- Request instance.
- $param(строка) (обязательный)
- Param to validate.
Список изменений
С версии 2.6.0 | Введена. |
Код wc_rest_validate_reports_request_arg() wc rest validate reports request arg WC 9.8.1
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 ) ) { /* translators: 1: param 2: type */ 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; }