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

AccountSettingsSchema::validate_field_value │ private │ WC 1.0

Validate and sanitize field value based on its type.

Метод класса: AccountSettingsSchema{}

Хуков нет.

Возвращает

mixed. Validated value.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->validate_field_value( $value, $type );
$value(разное) (обязательный)
Field value.
$type(строка) (обязательный)
Field type.

Код AccountSettingsSchema::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 'textarea':
			return sanitize_textarea_field( $value );
		case 'text':
		case 'select':
		default:
			return sanitize_text_field( $value );
	}
}