Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema

AbstractPaymentGatewaySettingsSchema::validate_and_sanitize_settingspublicWC 1.0

Validate and sanitize standard gateway settings.

Method of the class: AbstractPaymentGatewaySettingsSchema{}

No Hooks.

Returns

Array|WP_Error. Validated settings or error.

Usage

$AbstractPaymentGatewaySettingsSchema = new AbstractPaymentGatewaySettingsSchema();
$AbstractPaymentGatewaySettingsSchema->validate_and_sanitize_settings( $gateway, $values );
$gateway(WC_Payment_Gateway) (required)
Gateway instance.
$values(array) (required)
Values to validate and sanitize.

AbstractPaymentGatewaySettingsSchema::validate_and_sanitize_settings() code WC 10.4.3

public function validate_and_sanitize_settings( WC_Payment_Gateway $gateway, array $values ) {
	$gateway->init_form_fields();
	$validated = array();

	foreach ( $values as $key => $value ) {
		// Security: only allow valid form fields.
		if ( ! isset( $gateway->form_fields[ $key ] ) ) {
			continue;
		}

		$field      = $gateway->form_fields[ $key ];
		$field_type = $field['type'] ?? 'text';

		// Sanitize by type.
		$sanitized = $this->sanitize_field_value( $field_type, $value );

		// Validate.
		$validation = $this->validate_field_value( $key, $sanitized, $field, $gateway );
		if ( is_wp_error( $validation ) ) {
			return $validation;
		}

		$validated[ $key ] = $sanitized;
	}

	return $validated;
}