Automattic\WooCommerce\Internal\Admin\Settings
PaymentsRestController::check_location_arg()
Validate the location argument.
Метод класса: PaymentsRestController{}
Хуков нет.
Возвращает
WP_Error|true
. True if the location argument is valid, otherwise a WP_Error object.
Использование
// private - только в коде основоного (родительского) класса $result = $this->check_location_arg( $value, $request );
- $value(разное) (обязательный)
- Value of the argument.
- $request(WP_REST_Request) (обязательный)
- The current request object.
Код PaymentsRestController::check_location_arg() PaymentsRestController::check location arg WC 9.6.1
private function check_location_arg( $value, WP_REST_Request $request ) { // If the 'location' argument is not a string return an error. if ( ! is_string( $value ) ) { return new WP_Error( 'rest_invalid_param', esc_html__( 'The location argument must be a string.', 'woocommerce' ), array( 'status' => 400 ) ); } // Get the registered attributes for this endpoint request. $attributes = $request->get_attributes(); // Grab the location param schema. $args = $attributes['args']['location']; // If the location param doesn't match the regex pattern then we should return an error as well. if ( ! preg_match( '/^' . $args['pattern'] . '$/', $value ) ) { return new WP_Error( 'rest_invalid_param', esc_html__( 'The location argument must be a valid ISO3166 alpha-2 country code.', 'woocommerce' ), array( 'status' => 400 ) ); } return true; }