对小工具进行了一些修复
This commit is contained in:
@@ -84,6 +84,9 @@ final class FieldSchema {
|
||||
return !empty($field['allow_html']) ? wp_kses_post((string) $value) : sanitize_textarea_field((string) $value);
|
||||
case 'text':
|
||||
default:
|
||||
if (($field['sanitize'] ?? '') === 'url') {
|
||||
return esc_url_raw((string) $value);
|
||||
}
|
||||
if (($field['sanitize'] ?? '') === 'ids') {
|
||||
return implode(',', array_values(array_unique(array_filter(array_map('absint', preg_split('/[,,\s]+/', (string) $value))))));
|
||||
}
|
||||
@@ -122,7 +125,21 @@ final class FieldSchema {
|
||||
}
|
||||
|
||||
private static function choice(array $field, $value) {
|
||||
$options = (array) ($field['options'] ?? []);
|
||||
$raw_options = $field['options'] ?? [];
|
||||
// Reference-theme AJAX selects declare an option source (for example
|
||||
// `post` or `categories`) instead of an inline option map. Preserve the
|
||||
// selected IDs until the remote picker resolves their labels.
|
||||
if (!is_array($raw_options)) {
|
||||
if (!empty($field['multiple'])) {
|
||||
$values = is_array($value) ? $value : preg_split('/[,,\s]+/', (string) $value, -1, PREG_SPLIT_NO_EMPTY);
|
||||
return array_values(array_unique(array_filter(array_map(static function ($item): string {
|
||||
$item = trim((string) $item);
|
||||
return preg_match('/^\d+$/', $item) ? (string) (int) $item : '';
|
||||
}, $values ?: []))));
|
||||
}
|
||||
return sanitize_text_field((string) $value);
|
||||
}
|
||||
$options = $raw_options;
|
||||
if (!empty($field['multiple'])) {
|
||||
$values = is_array($value) ? $value : [];
|
||||
return array_values(array_filter(array_map('strval', $values), static fn($item) => array_key_exists($item, $options)));
|
||||
|
||||
Reference in New Issue
Block a user