Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\General\Schema
GeneralSettingsSchema::validate_field_value
Validate and sanitize field value based on its type.
Метод класса: GeneralSettingsSchema{}
Хуков нет.
Возвращает
mixed. Validated value.
Использование
// private - только в коде основоного (родительского) класса $result = $this->validate_field_value( $value, $type );
- $value(разное) (обязательный)
- Field value.
- $type(строка) (обязательный)
- Field type.
Код GeneralSettingsSchema::validate_field_value() GeneralSettingsSchema::validate field value WC 11.2.2
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':
if ( ! is_array( $value ) ) {
return array();
}
return array_map( 'sanitize_text_field', $value );
case 'text':
case 'select':
default:
return is_string( $value ) ? $value : (string) $value;
}
}