Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema
AbstractPaymentGatewaySettingsSchema::sanitize_field_value
Sanitize field value based on type.
Method of the class: AbstractPaymentGatewaySettingsSchema{}
No Hooks.
Returns
Mixed. Sanitized value.
Usage
// private - for code of main (parent) class only $result = $this->sanitize_field_value( $type, $value );
- $type(string) (required)
- Field type.
- $value(mixed) (required)
- Field value.
AbstractPaymentGatewaySettingsSchema::sanitize_field_value() AbstractPaymentGatewaySettingsSchema::sanitize field value code WC 10.4.3
private function sanitize_field_value( string $type, $value ) {
switch ( $type ) {
case 'checkbox':
return wc_bool_to_string( $value );
case 'number':
if ( ! is_numeric( $value ) ) {
return '';
}
$int_value = filter_var( $value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE );
return null !== $int_value ? $int_value : floatval( $value );
case 'multiselect':
if ( is_array( $value ) ) {
return array_map( 'sanitize_text_field', $value );
}
return is_string( $value ) ? array( sanitize_text_field( $value ) ) : array();
case 'textarea':
return sanitize_textarea_field( $value );
case 'email':
return sanitize_email( $value );
case 'password':
case 'color':
return sanitize_text_field( $value );
case 'text':
case 'safe_text':
case 'select':
case 'radio':
case 'image_width':
default:
return sanitize_text_field( $value );
}
}