chore: batch supporting UI, settings schema, templates, and docs updates
This commit is contained in:
@@ -249,6 +249,9 @@ class ModuleSettingsController extends WP_REST_Controller {
|
||||
|
||||
// Type validation
|
||||
$type = $field['type'] ?? 'text';
|
||||
$min = isset($field['min']) ? $field['min'] : null;
|
||||
$max = isset($field['max']) ? $field['max'] : null;
|
||||
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
case 'textarea':
|
||||
@@ -256,9 +259,39 @@ class ModuleSettingsController extends WP_REST_Controller {
|
||||
case 'url':
|
||||
$validated[$key] = sanitize_text_field($value);
|
||||
break;
|
||||
|
||||
|
||||
case 'number':
|
||||
$validated[$key] = floatval($value);
|
||||
// Handle empty string as valid for numbers (if min allows 0)
|
||||
if ($value === '' || $value === null) {
|
||||
// Only allow empty if there's a default
|
||||
if (isset($field['default'])) {
|
||||
$validated[$key] = $field['default'];
|
||||
} elseif ($min !== null && $min === 0) {
|
||||
$validated[$key] = 0;
|
||||
} else {
|
||||
$errors[$key] = sprintf(
|
||||
__('%s cannot be empty', 'woonoow'),
|
||||
$field['label'] ?? $key
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$num_value = floatval($value);
|
||||
if ($min !== null && $num_value < $min) {
|
||||
$errors[$key] = sprintf(
|
||||
__('%s must be at least %s', 'woonoow'),
|
||||
$field['label'] ?? $key,
|
||||
$min
|
||||
);
|
||||
} elseif ($max !== null && $num_value > $max) {
|
||||
$errors[$key] = sprintf(
|
||||
__('%s must be at most %s', 'woonoow'),
|
||||
$field['label'] ?? $key,
|
||||
$max
|
||||
);
|
||||
} else {
|
||||
$validated[$key] = $num_value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'toggle':
|
||||
@@ -277,6 +310,21 @@ class ModuleSettingsController extends WP_REST_Controller {
|
||||
$validated[$key] = sanitize_text_field($value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'multiselect':
|
||||
// Validate array of values against allowed options
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$allowed_options = $field['options'] ?? [];
|
||||
$valid_values = [];
|
||||
foreach ($value as $v) {
|
||||
if (isset($allowed_options[$v])) {
|
||||
$valid_values[] = sanitize_text_field($v);
|
||||
}
|
||||
}
|
||||
$validated[$key] = $valid_values;
|
||||
break;
|
||||
|
||||
default:
|
||||
$validated[$key] = $value;
|
||||
|
||||
Reference in New Issue
Block a user