Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Products\Schema
ProductSettingsSchema::validate_field_value
Validate and sanitize field value based on its type.
Method of the class: ProductSettingsSchema{}
No Hooks.
Returns
Mixed. Validated value.
Usage
// private - for code of main (parent) class only $result = $this->validate_field_value( $value, $type );
- $value(mixed) (required)
- Field value.
- $type(string) (required)
- Field type.
ProductSettingsSchema::validate_field_value() ProductSettingsSchema::validate field value code WC 10.4.3
private function validate_field_value( $value, string $type ) {
switch ( $type ) {
case 'number':
return is_numeric( $value ) ? (float) $value : 0;
case 'checkbox':
if ( function_exists( 'wc_string_to_bool' ) ) {
return wc_string_to_bool( $value );
}
if ( is_bool( $value ) ) {
return $value;
}
return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
case 'multiselect':
return is_array( $value ) ? $value : array();
case 'text':
case 'select':
default:
return is_string( $value ) ? $value : (string) $value;
}
}