$v) { // Preserve numeric keys (e.g. lists) if (is_int($k)) { $key = $k; } else { $key = sanitize_key((string) $k); } $out[$key] = a11ybridge_sanitize_deep($v); } return $out; } if (is_string($value)) { return sanitize_text_field($value); } if (is_bool($value) || is_int($value) || is_float($value) || $value === null) { return $value; } // fallback: stringify then sanitize return sanitize_text_field((string) $value); } } if (!function_exists('a11ybridge_sanitize_option_array')) { /** * Sanitizer suitable for most option arrays saved via Settings API. * * @param mixed $value * @return array */ function a11ybridge_sanitize_option_array($value): array { $unslashed = wp_unslash($value); if (!is_array($unslashed)) { return []; } $clean = a11ybridge_sanitize_deep($unslashed); return is_array($clean) ? $clean : []; } } if (!function_exists('a11ybridge_sanitize_simplification_settings')) { /** * Dedicated sanitization/validation for a11ybridge_simplification_settings. * Enforces booleans/ints and whitelisted enum values. */ function a11ybridge_sanitize_simplification_settings($input): array { $in = is_array($input) ? $input : []; $out = []; $out['enable_text_simplification'] = !empty($in['enable_text_simplification']) ? 1 : 0; $out['show_toolbar_button'] = !empty($in['show_toolbar_button']) ? 1 : 0; $out['consent_required'] = !empty($in['consent_required']) ? 1 : 0; $out['consent_ttl_hours'] = isset($in['consent_ttl_hours']) ? max(0, intval($in['consent_ttl_hours'])) : 24; // Use catalog canonicalization if available, otherwise fall back to safe defaults. $out['default_level'] = function_exists('a11ybridge_catalog_canonical') ? a11ybridge_catalog_canonical('textSimplification.level', (string)($in['default_level'] ?? ''), 'basic') : 'basic'; $out['target_language'] = function_exists('a11ybridge_catalog_canonical') ? a11ybridge_catalog_canonical('textSimplification.targetLanguage', (string)($in['target_language'] ?? ''), 'original') : 'original'; return $out; } }