Automattic\WooCommerce\Internal\Admin\Settings
PaymentsRestController::check_location_arg
Validate the location argument.
Method of the class: PaymentsRestController{}
No Hooks.
Returns
WP_Error|true
. True if the location argument is valid, otherwise a WP_Error object.
Usage
// private - for code of main (parent) class only $result = $this->check_location_arg( $value, $request );
- $value(mixed) (required)
- Value of the argument.
- $request(WP_REST_Request) (required)
- The current request object.
PaymentsRestController::check_location_arg() PaymentsRestController::check location arg code WC 9.9.3
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; }