feat(widgets): render icon fields with the universal icon picker
The widget FormRenderer icon case and the nav-menu item icon field now emit the shared picker (preview + choose/clear + editable text input, delegated events so lazy forms and repeater rows work). Icon values are sanitized through aksrt_sanitize_icon_value on both save paths so inline customsvg- markup survives; the widget admin screen enqueues the picker.
This commit is contained in:
@@ -21,18 +21,18 @@ class NavMenuOptions {
|
||||
if ($hook !== 'nav-menus.php') {
|
||||
return;
|
||||
}
|
||||
$path = get_template_directory() . '/assets/js/admin-nav-menu-senior.js';
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script(
|
||||
'aksrt-admin-nav-menu-senior',
|
||||
get_template_directory_uri() . '/assets/js/admin-nav-menu-senior.js',
|
||||
['jquery'],
|
||||
(string) filemtime($path),
|
||||
true
|
||||
);
|
||||
aksrt_icon_picker_assets();
|
||||
$path = get_template_directory() . '/assets/js/admin-nav-menu-senior.js';
|
||||
if (file_exists($path)) {
|
||||
wp_enqueue_script(
|
||||
'aksrt-admin-nav-menu-senior',
|
||||
get_template_directory_uri() . '/assets/js/admin-nav-menu-senior.js',
|
||||
['jquery'],
|
||||
(string) filemtime($path),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,11 +57,15 @@ class NavMenuOptions {
|
||||
?>
|
||||
<p class="field-aksrt-icon description description-wide">
|
||||
<label for="edit-menu-item-aksrt-icon-<?php echo esc_attr((string) $item_id); ?>">
|
||||
<?php esc_html_e('图标 class(如 fa fas fa-home)', 'aksrt'); ?><br>
|
||||
<input type="text" id="edit-menu-item-aksrt-icon-<?php echo esc_attr((string) $item_id); ?>"
|
||||
class="widefat" name="aksrt_menu_options[<?php echo esc_attr((string) $item_id); ?>][icon]"
|
||||
value="<?php echo esc_attr($icon); ?>">
|
||||
<?php esc_html_e('图标', 'aksrt'); ?>
|
||||
</label>
|
||||
<?php
|
||||
echo aksrt_icon_picker_field(
|
||||
sprintf('aksrt_menu_options[%d][icon]', $item_id),
|
||||
sprintf('edit-menu-item-aksrt-icon-%d', $item_id),
|
||||
$icon
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p class="field-aksrt-badge description description-thin">
|
||||
<label for="edit-menu-item-aksrt-badge-<?php echo esc_attr((string) $item_id); ?>">
|
||||
@@ -127,7 +131,7 @@ class NavMenuOptions {
|
||||
$raw = wp_unslash($_POST['aksrt_menu_options'][ $menu_item_db_id ]);
|
||||
|
||||
$clean = [
|
||||
'icon' => sanitize_text_field((string) ($raw['icon'] ?? '')),
|
||||
'icon' => aksrt_sanitize_icon_value((string) ($raw['icon'] ?? '')),
|
||||
'badge' => sanitize_text_field((string) ($raw['badge'] ?? '')),
|
||||
'badge_class' => sanitize_html_class((string) ($raw['badge_class'] ?? '')),
|
||||
'submenu_s' => !empty($raw['submenu_s']),
|
||||
|
||||
@@ -802,6 +802,10 @@ class SchemaProvider {
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
case 'icon':
|
||||
return function_exists('aksrt_sanitize_icon_value')
|
||||
? aksrt_sanitize_icon_value((string) $value)
|
||||
: sanitize_text_field((string) $value);
|
||||
default:
|
||||
return sanitize_text_field((string) $value);
|
||||
}
|
||||
@@ -993,7 +997,7 @@ class SchemaProvider {
|
||||
// 自定义面板(验证码服务商等)按对象存储
|
||||
'custom' => 'array',
|
||||
'color' => 'string',
|
||||
'icon' => 'string',
|
||||
'icon' => 'icon',
|
||||
'media' => 'url',
|
||||
'upload' => 'url',
|
||||
'gallery' => 'attachment_ids',
|
||||
|
||||
@@ -28,6 +28,7 @@ final class AdminFormController {
|
||||
wp_enqueue_script('jquery-ui-sortable');
|
||||
wp_enqueue_style('aksrt-widget-admin', AKSRT_URI . '/assets/widgets/admin.css', ['wp-color-picker'], AKSRT_VERSION);
|
||||
wp_enqueue_style('aksrt-widget-preview', AKSRT_URI . '/assets/widgets/frontend.css', [], AKSRT_VERSION);
|
||||
aksrt_icon_picker_assets(['wp-color-picker']);
|
||||
wp_enqueue_script('aksrt-widget-admin-core', AKSRT_URI . '/assets/widgets/admin-core.js', [], AKSRT_VERSION, true);
|
||||
wp_enqueue_script('aksrt-widget-admin', AKSRT_URI . '/assets/widgets/admin.js', ['jquery', 'jquery-ui-sortable', 'wp-color-picker', 'aksrt-widget-admin-core'], AKSRT_VERSION, true);
|
||||
wp_localize_script('aksrt-widget-admin', 'aksrtWidgetAdmin', [
|
||||
|
||||
@@ -81,7 +81,9 @@ final class FieldSchema {
|
||||
case 'color':
|
||||
return self::color((string) $value);
|
||||
case 'icon':
|
||||
return sanitize_text_field((string) $value);
|
||||
return function_exists('aksrt_sanitize_icon_value')
|
||||
? aksrt_sanitize_icon_value((string) $value)
|
||||
: sanitize_text_field((string) $value);
|
||||
case 'textarea':
|
||||
return !empty($field['allow_html']) ? wp_kses_post((string) $value) : sanitize_textarea_field((string) $value);
|
||||
case 'text':
|
||||
|
||||
@@ -79,7 +79,7 @@ final class FormRenderer {
|
||||
echo '<input class="widefat aksrt-widget-color" type="text" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_name) . '" value="' . esc_attr((string) $value) . '">';
|
||||
break;
|
||||
case 'icon':
|
||||
echo '<div class="aksrt-widget-icon"><i class="' . esc_attr((string) $value) . '" aria-hidden="true"></i><input class="widefat" type="text" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_name) . '" value="' . esc_attr((string) $value) . '" placeholder="fa fas fa-star"></div>';
|
||||
echo aksrt_icon_picker_field($field_name, $field_id, (string) $value);
|
||||
break;
|
||||
case 'link':
|
||||
self::link($widget, $key, is_array($value) ? $value : []);
|
||||
|
||||
Reference in New Issue
Block a user