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;
|
||||
|
||||
@@ -473,6 +473,14 @@ class ProductsController
|
||||
update_post_meta($product->get_id(), '_woonoow_subscription_signup_fee', self::sanitize_number($data['subscription_signup_fee']));
|
||||
}
|
||||
|
||||
// Affiliate meta
|
||||
if (isset($data['affiliate_enabled'])) {
|
||||
update_post_meta($product->get_id(), '_woonoow_affiliate_enabled', $data['affiliate_enabled'] ? 'yes' : 'no');
|
||||
}
|
||||
if (isset($data['affiliate_commission_rate'])) {
|
||||
update_post_meta($product->get_id(), '_woonoow_affiliate_commission_rate', self::sanitize_number($data['affiliate_commission_rate']));
|
||||
}
|
||||
|
||||
// Handle variations for variable products
|
||||
if ($type === 'variable' && !empty($data['attributes']) && is_array($data['attributes'])) {
|
||||
self::save_product_attributes($product, $data['attributes']);
|
||||
@@ -644,6 +652,14 @@ class ProductsController
|
||||
update_post_meta($product->get_id(), '_woonoow_subscription_signup_fee', self::sanitize_number($data['subscription_signup_fee']));
|
||||
}
|
||||
|
||||
// Affiliate meta
|
||||
if (isset($data['affiliate_enabled'])) {
|
||||
update_post_meta($product->get_id(), '_woonoow_affiliate_enabled', $data['affiliate_enabled'] ? 'yes' : 'no');
|
||||
}
|
||||
if (isset($data['affiliate_commission_rate'])) {
|
||||
update_post_meta($product->get_id(), '_woonoow_affiliate_commission_rate', self::sanitize_number($data['affiliate_commission_rate']));
|
||||
}
|
||||
|
||||
// Allow plugins to perform additional updates (Level 1 compatibility)
|
||||
do_action('woonoow/product_updated', $product, $data, $request);
|
||||
|
||||
@@ -857,6 +873,10 @@ class ProductsController
|
||||
$data['subscription_trial_days'] = get_post_meta($product->get_id(), '_woonoow_subscription_trial_days', true) ?: '';
|
||||
$data['subscription_signup_fee'] = get_post_meta($product->get_id(), '_woonoow_subscription_signup_fee', true) ?: '';
|
||||
|
||||
// Affiliate fields
|
||||
$data['affiliate_enabled'] = get_post_meta($product->get_id(), '_woonoow_affiliate_enabled', true) === 'yes';
|
||||
$data['affiliate_commission_rate'] = get_post_meta($product->get_id(), '_woonoow_affiliate_commission_rate', true) ?: '';
|
||||
|
||||
// Images array (URLs) for frontend - featured + gallery
|
||||
$images = [];
|
||||
$featured_image_id = $product->get_image_id();
|
||||
|
||||
Reference in New Issue
Block a user