fix(navigation): align mega-menu rendering and menu-item backend with the reference
Renderer: - Graphic-card images carry fit-cover so they crop into the fixed card box instead of stretching it and pushing the title out of alignment. - Mega-menu link icons use fa-fw (fixed glyph column) instead of the undefined menu-item-icon class, so link titles line up. Backend: - Restore show_policy (login / vip / vip_2 / auth) on menu items; the field was missing entirely, so items could not be gated by identity. - Default submenu_type to graphic_card, badge_class to jb-red, arrangement to swiper, size to md. - Clamp img_scale to 20-300 to match the reference's spinner bounds. - Drop the now-meaningless "none" submenu_type option: the senior-submenu switch is itself the on/off control. - Admin JS gains the align control (left/center/space-around). Cleanup: - Remove the unused header_actions nav menu location. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
55423403a6
commit
e6d9ff49a2
6 files changed
+113
-29
No files matched your search
@@ -46,8 +46,9 @@ class NavMenuOptions {
|
||||
$icon = (string) ($opts['icon'] ?? '');
|
||||
$badge = (string) ($opts['badge'] ?? '');
|
||||
$badge_class = (string) ($opts['badge_class'] ?? '');
|
||||
$show_policy = (string) ($opts['show_policy'] ?? '');
|
||||
$submenu_s = !empty($opts['submenu_s']);
|
||||
$submenu_type = (string) ($opts['submenu_type'] ?? '');
|
||||
$submenu_type = (string) ($opts['submenu_type'] ?? 'graphic_card');
|
||||
$graphic_json = !empty($opts['graphic_card_opts'])
|
||||
? wp_json_encode($opts['graphic_card_opts'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
||||
: self::sample_graphic_json();
|
||||
@@ -83,6 +84,19 @@ class NavMenuOptions {
|
||||
value="<?php echo esc_attr($badge_class); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p class="field-jio-show-policy description description-wide">
|
||||
<label for="edit-menu-item-jio-show-policy-<?php echo esc_attr((string) $item_id); ?>">
|
||||
<?php esc_html_e('显示限制', 'jio'); ?><br>
|
||||
<select id="edit-menu-item-jio-show-policy-<?php echo esc_attr((string) $item_id); ?>"
|
||||
class="widefat" name="jio_menu_options[<?php echo esc_attr((string) $item_id); ?>][show_policy]">
|
||||
<option value="" <?php selected($show_policy, ''); ?>><?php esc_html_e('不限制', 'jio'); ?></option>
|
||||
<option value="signin" <?php selected($show_policy, 'signin'); ?>><?php esc_html_e('登录后显示', 'jio'); ?></option>
|
||||
<option value="vip" <?php selected($show_policy, 'vip'); ?>><?php esc_html_e('所有会员显示', 'jio'); ?></option>
|
||||
<option value="vip_2" <?php selected($show_policy, 'vip_2'); ?>><?php esc_html_e('二级会员显示', 'jio'); ?></option>
|
||||
<option value="auth" <?php selected($show_policy, 'auth'); ?>><?php esc_html_e('认证用户显示', 'jio'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p class="field-jio-submenu description description-wide">
|
||||
<label>
|
||||
<input type="checkbox" name="jio_menu_options[<?php echo esc_attr((string) $item_id); ?>][submenu_s]" value="1" <?php checked($submenu_s); ?>>
|
||||
@@ -94,9 +108,8 @@ class NavMenuOptions {
|
||||
<?php esc_html_e('高级子菜单类型', 'jio'); ?><br>
|
||||
<select id="edit-menu-item-jio-submenu-type-<?php echo esc_attr((string) $item_id); ?>"
|
||||
name="jio_menu_options[<?php echo esc_attr((string) $item_id); ?>][submenu_type]">
|
||||
<option value="" <?php selected($submenu_type, ''); ?>><?php esc_html_e('无', 'jio'); ?></option>
|
||||
<option value="graphic_card" <?php selected($submenu_type, 'graphic_card'); ?>><?php esc_html_e('图文卡片', 'jio'); ?></option>
|
||||
<option value="multi_column_links" <?php selected($submenu_type, 'multi_column_links'); ?>><?php esc_html_e('多列链接', 'jio'); ?></option>
|
||||
<option value="multi_column_links" <?php selected($submenu_type, 'multi_column_links'); ?>><?php esc_html_e('多栏目链接', 'jio'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
@@ -134,6 +147,7 @@ class NavMenuOptions {
|
||||
'icon' => jio_sanitize_icon_value((string) ($raw['icon'] ?? '')),
|
||||
'badge' => sanitize_text_field((string) ($raw['badge'] ?? '')),
|
||||
'badge_class' => sanitize_html_class((string) ($raw['badge_class'] ?? '')),
|
||||
'show_policy' => self::sanitize_show_policy((string) ($raw['show_policy'] ?? '')),
|
||||
'submenu_s' => !empty($raw['submenu_s']),
|
||||
'submenu_type' => sanitize_key((string) ($raw['submenu_type'] ?? '')),
|
||||
];
|
||||
@@ -150,6 +164,15 @@ class NavMenuOptions {
|
||||
update_post_meta($menu_item_db_id, 'jio_menu_options', $clean);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $policy
|
||||
*/
|
||||
private static function sanitize_show_policy(string $policy): string {
|
||||
$allowed = ['', 'signin', 'vip', 'vip_2', 'auth'];
|
||||
$policy = sanitize_key($policy);
|
||||
return in_array($policy, $allowed, true) ? $policy : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
@@ -177,7 +200,7 @@ class NavMenuOptions {
|
||||
'img' => esc_url_raw((string) ($item['img'] ?? '')),
|
||||
'title' => sanitize_text_field((string) ($item['title'] ?? '')),
|
||||
'badge' => sanitize_text_field((string) ($item['badge'] ?? '')),
|
||||
'badge_class' => sanitize_html_class((string) ($item['badge_class'] ?? '')),
|
||||
'badge_class' => sanitize_html_class((string) ($item['badge_class'] ?? 'jb-red')),
|
||||
'link' => [
|
||||
'url' => esc_url_raw((string) ($item['link']['url'] ?? '')),
|
||||
'text' => sanitize_text_field((string) ($item['link']['text'] ?? '')),
|
||||
@@ -186,10 +209,10 @@ class NavMenuOptions {
|
||||
];
|
||||
}
|
||||
return [
|
||||
'arrangement' => sanitize_key((string) ($opts['arrangement'] ?? '')),
|
||||
'arrangement' => sanitize_key((string) ($opts['arrangement'] ?? 'swiper')),
|
||||
'align' => sanitize_key((string) ($opts['align'] ?? '')),
|
||||
'size' => sanitize_key((string) ($opts['size'] ?? '')),
|
||||
'img_scale' => max(0, min(200, (int) ($opts['img_scale'] ?? 100))),
|
||||
'size' => sanitize_key((string) ($opts['size'] ?? 'md')),
|
||||
'img_scale' => max(20, min(300, (int) ($opts['img_scale'] ?? 100))),
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
@@ -240,7 +263,7 @@ class NavMenuOptions {
|
||||
|
||||
private static function sample_graphic_json(): string {
|
||||
$sample = [
|
||||
'arrangement' => '',
|
||||
'arrangement' => 'swiper',
|
||||
'size' => 'md',
|
||||
'img_scale' => 100,
|
||||
'items' => [
|
||||
|
||||
Reference in new issue
Block a user