Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders\WooPayments
WooPaymentsRestController::check_location_arg
Validate the location argument.
Method of the class: WooPaymentsRestController{}
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.
WooPaymentsRestController::check_location_arg() WooPaymentsRestController::check location arg code WC 10.7.0
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;
}