对小工具进行了一些修复
This commit is contained in:
@@ -51,6 +51,7 @@ final class FormRenderer {
|
||||
case 'radio':
|
||||
case 'button_set':
|
||||
case 'palette':
|
||||
case 'image_select':
|
||||
self::radios($field_id, $field_name, (array) ($field['options'] ?? []), (string) $value, $type);
|
||||
break;
|
||||
case 'select':
|
||||
@@ -65,10 +66,11 @@ final class FormRenderer {
|
||||
self::number($field_id, $field_name, $field, $value, $type);
|
||||
break;
|
||||
case 'textarea':
|
||||
echo '<textarea class="widefat" rows="4" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_name) . '">' . esc_textarea((string) $value) . '</textarea>';
|
||||
$rows = max(1, (int) ($field['attributes']['rows'] ?? 4));
|
||||
echo '<textarea class="widefat" rows="' . $rows . '" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_name) . '">' . esc_textarea((string) $value) . '</textarea>';
|
||||
break;
|
||||
case 'upload':
|
||||
self::upload($field_id, $field_name, (string) $value);
|
||||
self::upload($field_id, $field_name, (string) $value, (string) ($field['library'] ?? ''));
|
||||
break;
|
||||
case 'color':
|
||||
echo '<input class="widefat aksrt-widget-color" type="text" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_name) . '" value="' . esc_attr((string) $value) . '">';
|
||||
@@ -113,7 +115,13 @@ final class FormRenderer {
|
||||
echo '<div class="aksrt-widget-choices aksrt-widget-choices--' . esc_attr($type) . '">';
|
||||
foreach ($options as $key => $label) {
|
||||
$option_id = $id . '-' . sanitize_html_class((string) $key);
|
||||
echo '<label for="' . esc_attr($option_id) . '"><input type="radio" id="' . esc_attr($option_id) . '" name="' . esc_attr($name) . '" value="' . esc_attr((string) $key) . '" ' . checked($value, (string) $key, false) . '><span>' . esc_html((string) $label) . '</span></label>';
|
||||
$image = is_array($label) ? (string) ($label['image'] ?? $label['url'] ?? '') : (string) $label;
|
||||
$text = is_array($label) ? (string) ($label['label'] ?? $label['title'] ?? $key) : (string) $label;
|
||||
if ($type === 'image_select' && $text === $image) $text = (string) $key;
|
||||
$body = $type === 'image_select' && filter_var($image, FILTER_VALIDATE_URL)
|
||||
? '<img src="' . esc_url($image) . '" alt="' . esc_attr($text) . '"><small>' . esc_html($text) . '</small>'
|
||||
: esc_html($text);
|
||||
echo '<label for="' . esc_attr($option_id) . '"><input type="radio" id="' . esc_attr($option_id) . '" name="' . esc_attr($name) . '" value="' . esc_attr((string) $key) . '" ' . checked($value, (string) $key, false) . '><span>' . $body . '</span></label>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
@@ -148,13 +156,14 @@ final class FormRenderer {
|
||||
echo '<div class="aksrt-widget-number"><input class="widefat" type="' . esc_attr($input_type) . '" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr((string) $value) . '"' . $min . $max . $step . '><output>' . esc_html((string) $value) . '</output></div>';
|
||||
}
|
||||
|
||||
private static function upload(string $id, string $name, string $value): void {
|
||||
echo '<div class="aksrt-widget-upload">';
|
||||
private static function upload(string $id, string $name, string $value, string $library = ''): void {
|
||||
$library = in_array($library, ['image', 'video'], true) ? $library : '';
|
||||
echo '<div class="aksrt-widget-upload" data-media-library="' . esc_attr($library) . '">';
|
||||
if ($value !== '') {
|
||||
echo '<img src="' . esc_url($value) . '" alt="">';
|
||||
}
|
||||
echo '<input class="widefat" type="url" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($value) . '">';
|
||||
echo '<button type="button" class="button aksrt-widget-upload__choose">' . esc_html__('选择媒体', 'aksrt') . '</button> <button type="button" class="button-link-delete aksrt-widget-upload__remove">' . esc_html__('移除', 'aksrt') . '</button></div>';
|
||||
echo '<button type="button" class="button aksrt-widget-upload__choose">' . esc_html($library === 'video' ? __('选择视频', 'aksrt') : __('选择图片', 'aksrt')) . '</button> <button type="button" class="button-link-delete aksrt-widget-upload__remove">' . esc_html__('移除', 'aksrt') . '</button></div>';
|
||||
}
|
||||
|
||||
private static function link(SchemaWidget $widget, string $key, array $value): void {
|
||||
@@ -207,7 +216,11 @@ final class FormRenderer {
|
||||
}
|
||||
|
||||
private static function group_row(SchemaWidget $widget, array $field, array $row, string $key, string $index): void {
|
||||
echo '<div class="aksrt-widget-repeater__row"><div class="aksrt-widget-repeater__bar"><span class="dashicons dashicons-move" aria-hidden="true"></span><strong>' . esc_html__('项目', 'aksrt') . '</strong><button type="button" class="button-link-delete aksrt-widget-repeater__remove">' . esc_html__('删除', 'aksrt') . '</button></div><div class="aksrt-widget-repeater__fields">';
|
||||
$prefix = (string) ($field['item_label'] ?? $field['label'] ?? __('项目', 'aksrt'));
|
||||
$number = ctype_digit($index) ? ((int) $index + 1) : 0;
|
||||
$title = $prefix . ($number ? ' ' . $number : '');
|
||||
if (!empty($row['title'])) $title .= ':' . strip_tags((string) $row['title']);
|
||||
echo '<div class="aksrt-widget-repeater__row" data-row-index="' . esc_attr(ctype_digit($index) ? $index : '0') . '"><div class="aksrt-widget-repeater__bar"><span class="dashicons dashicons-move" aria-hidden="true"></span><strong>' . esc_html($title) . '</strong><button type="button" class="button-link-delete aksrt-widget-repeater__remove">' . esc_html__('删除', 'aksrt') . '</button></div><div class="aksrt-widget-repeater__fields">';
|
||||
foreach ((array) ($field['fields'] ?? []) as $child) {
|
||||
$child_id = (string) ($child['id'] ?? '');
|
||||
self::field($widget, $child, $row[$child_id] ?? ($child['default'] ?? ''), $key . '[' . $index . ']');
|
||||
|
||||
Reference in New Issue
Block a user