feat(nav): rewrite top header to zibll 1:1 DOM/CSS/JS contract

Replace hybrid site-nav/drawer shell with zibll navbar-top layouts 1/2/3,
body.mobile-navbar-show drawer, wired NavWalker + aksrt_menu_options meta,
nav_folding/chevron, VIP switches, and SPA/PHP schema parity. No dual-class
compat paths.
This commit is contained in:
2026-07-22 11:18:34 +08:00
parent b8ee6b6a43
commit 259dbdbe04
28 changed files with 2463 additions and 885 deletions
+112
View File
@@ -0,0 +1,112 @@
<?php
/**
* Native WP nav-menu item options (aksrt_menu_options).
*
* @package AKSRT
*/
namespace AKSRT\Admin;
defined('ABSPATH') || exit;
class NavMenuOptions {
public static function init(): void {
add_action('wp_nav_menu_item_custom_fields', [self::class, 'render_fields'], 10, 2);
add_action('wp_update_nav_menu_item', [self::class, 'save'], 10, 2);
}
/**
* @param int $item_id
* @param \WP_Post $item
*/
public static function render_fields($item_id, $item): void {
$item_id = (int) $item_id;
$opts = get_post_meta($item_id, 'aksrt_menu_options', true);
$opts = is_array($opts) ? $opts : [];
$icon = (string) ($opts['icon'] ?? '');
$badge = (string) ($opts['badge'] ?? '');
$badge_class = (string) ($opts['badge_class'] ?? '');
$submenu_s = !empty($opts['submenu_s']);
$submenu_type = (string) ($opts['submenu_type'] ?? '');
?>
<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(如 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); ?>">
</label>
</p>
<p class="field-aksrt-badge description description-thin">
<label for="edit-menu-item-aksrt-badge-<?php echo esc_attr((string) $item_id); ?>">
<?php esc_html_e('徽章文字', 'aksrt'); ?><br>
<input type="text" id="edit-menu-item-aksrt-badge-<?php echo esc_attr((string) $item_id); ?>"
class="widefat" name="aksrt_menu_options[<?php echo esc_attr((string) $item_id); ?>][badge]"
value="<?php echo esc_attr($badge); ?>">
</label>
</p>
<p class="field-aksrt-badge-class description description-thin">
<label for="edit-menu-item-aksrt-badge-class-<?php echo esc_attr((string) $item_id); ?>">
<?php esc_html_e('徽章 class', 'aksrt'); ?><br>
<input type="text" id="edit-menu-item-aksrt-badge-class-<?php echo esc_attr((string) $item_id); ?>"
class="widefat" name="aksrt_menu_options[<?php echo esc_attr((string) $item_id); ?>][badge_class]"
value="<?php echo esc_attr($badge_class); ?>">
</label>
</p>
<p class="field-aksrt-submenu description description-wide">
<label>
<input type="checkbox" name="aksrt_menu_options[<?php echo esc_attr((string) $item_id); ?>][submenu_s]" value="1" <?php checked($submenu_s); ?>>
<?php esc_html_e('启用高级子菜单(一级菜单)', 'aksrt'); ?>
</label>
</p>
<p class="field-aksrt-submenu-type description description-wide">
<label for="edit-menu-item-aksrt-submenu-type-<?php echo esc_attr((string) $item_id); ?>">
<?php esc_html_e('高级子菜单类型', 'aksrt'); ?><br>
<select id="edit-menu-item-aksrt-submenu-type-<?php echo esc_attr((string) $item_id); ?>"
name="aksrt_menu_options[<?php echo esc_attr((string) $item_id); ?>][submenu_type]">
<option value="" <?php selected($submenu_type, ''); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
<option value="graphic_card" <?php selected($submenu_type, 'graphic_card'); ?>><?php esc_html_e('图文卡片', 'aksrt'); ?></option>
<option value="multi_column_links" <?php selected($submenu_type, 'multi_column_links'); ?>><?php esc_html_e('多列链接', 'aksrt'); ?></option>
</select>
</label>
</p>
<p class="description description-wide">
<?php esc_html_e('高级子菜单内容(graphic_card_opts / multi_column_links_opts)可在后续可视化编辑;也可通过 meta 写入 JSON。', 'aksrt'); ?>
</p>
<?php
}
/**
* @param int $menu_id
* @param int $menu_item_db_id
*/
public static function save($menu_id, $menu_item_db_id): void {
$menu_item_db_id = (int) $menu_item_db_id;
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- WP core nav-menu form nonce.
if (empty($_POST['aksrt_menu_options'][ $menu_item_db_id ]) || !is_array($_POST['aksrt_menu_options'][ $menu_item_db_id ])) {
// If fields absent, leave existing meta (WP may not resubmit all fields in bulk edits).
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$raw = wp_unslash($_POST['aksrt_menu_options'][ $menu_item_db_id ]);
$existing = get_post_meta($menu_item_db_id, 'aksrt_menu_options', true);
$existing = is_array($existing) ? $existing : [];
$clean = [
'icon' => sanitize_text_field((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']),
'submenu_type' => sanitize_key((string) ($raw['submenu_type'] ?? '')),
];
// Preserve complex opts not edited by this form.
if (!empty($existing['graphic_card_opts'])) {
$clean['graphic_card_opts'] = $existing['graphic_card_opts'];
}
if (!empty($existing['multi_column_links_opts'])) {
$clean['multi_column_links_opts'] = $existing['multi_column_links_opts'];
}
update_post_meta($menu_item_db_id, 'aksrt_menu_options', $clean);
}
}
+30 -22
View File
@@ -14,10 +14,10 @@ class SchemaPageDisplay {
'domain' => 'page_display',
'title' => '页面&显示',
'sections' => [
'header-nav' => [
'header-nav' => [
'key' => 'header-nav',
'title' => '顶部导航栏',
'version' => '1.0.0',
'version' => '1.1.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'layout', 'title' => '导航栏布局', 'fields' => [
@@ -28,25 +28,7 @@ class SchemaPageDisplay {
['label' => '毛玻璃', 'value' => 'blur'],
]],
['key' => 'header_max_width', 'label' => '导航栏最大宽度', 'type' => 'number', 'default' => 1200, 'min' => 0, 'max' => 1600],
['key' => 'header_scroll_down_hide', 'label' => '下滑隐藏导航栏', 'type' => 'switch', 'default' => false],
]],
['key' => 'components', 'title' => '导航组件', 'fields' => [
['key' => 'header_search_enabled', 'label' => '搜索入口', 'type' => 'switch', 'default' => true],
['key' => 'header_user_menu', 'label' => '用户菜单', 'type' => 'switch', 'default' => true],
['key' => 'header_publish_btn', 'label' => '发布按钮', 'type' => 'switch', 'default' => true],
['key' => 'header_mobile_drawer', 'label' => '移动端抽屉导航', 'type' => 'switch', 'default' => true],
]],
['key' => 'newposts', 'title' => '新文章提示', 'fields' => [
['key' => 'header_newposts_enabled', 'label' => '显示新文章提示', 'type' => 'switch', 'default' => true],
['key' => 'header_newposts_text', 'label' => '提示文案', 'type' => 'input', 'default' => '有新文章'],
['key' => 'header_newposts_radius', 'label' => '圆角', 'type' => 'number', 'default' => 12, 'min' => 0, 'max' => 30],
['key' => 'header_newposts_class', 'label' => '样式类', 'type' => 'input', 'default' => ''],
]],
['key' => 'color', 'title' => '颜色设置', 'fields' => [
['key' => 'header_theme_custom', 'label' => '自定义导航栏颜色', 'type' => 'switch', 'default' => false],
['key' => 'header_theme_bg_custom', 'label' => '自定义背景色', 'type' => 'color', 'default' => ''],
['key' => 'header_theme_bg', 'label' => '背景颜色(备选)', 'type' => 'color', 'default' => ''],
['key' => 'header_theme_color_custom', 'label' => '自定义文字颜色', 'type' => 'color', 'default' => ''],
['key' => 'header_scroll_down_hide', 'label' => '下滑隐藏导航栏', 'type' => 'switch', 'default' => true],
]],
['key' => 'layout-type', 'title' => '布局类型', 'fields' => [
['key' => 'header_layout', 'label' => '桌面端布局', 'type' => 'radio', 'default' => '1', 'options' => [
@@ -64,9 +46,35 @@ class SchemaPageDisplay {
['label' => '右侧滑出', 'value' => 'right'],
]],
]],
['key' => 'components', 'title' => '导航组件', 'fields' => [
['key' => 'header_search_enabled', 'label' => '搜索入口', 'type' => 'switch', 'default' => true],
['key' => 'header_user_menu', 'label' => '用户菜单', 'type' => 'switch', 'default' => true],
['key' => 'header_publish_btn', 'label' => '发布按钮', 'type' => 'switch', 'default' => true],
['key' => 'header_mobile_drawer', 'label' => '移动端抽屉导航', 'type' => 'switch', 'default' => true],
['key' => 'header_nav_pay_vip', 'label' => '导航栏开通会员按钮', 'type' => 'switch', 'default' => true],
['key' => 'header_nav_user_pay_vip', 'label' => '用户框开通会员按钮', 'type' => 'switch', 'default' => true],
]],
['key' => 'newposts', 'title' => '发布按钮', 'fields' => [
['key' => 'header_newposts_enabled', 'label' => '启用发布按钮', 'type' => 'switch', 'default' => true],
['key' => 'header_newposts_text', 'label' => '按钮文案', 'type' => 'input', 'default' => '<i class="fa fa-pencil"></i> 发布'],
['key' => 'header_newposts_radius', 'label' => '圆角', 'type' => 'number', 'default' => 20, 'min' => 0, 'max' => 30],
['key' => 'header_newposts_class', 'label' => '样式类', 'type' => 'input', 'default' => ''],
['key' => 'header_newposts_types', 'label' => '发布类型', 'type' => 'select', 'default' => ['post'], 'options' => [
['label' => '文章', 'value' => 'post'],
['label' => '帖子', 'value' => 'topic'],
['label' => '商品', 'value' => 'product'],
]],
['key' => 'header_user_newposts_text', 'label' => '用户卡发布文案', 'type' => 'input', 'default' => '发布内容'],
]],
['key' => 'color', 'title' => '颜色设置', 'fields' => [
['key' => 'header_theme_custom', 'label' => '自定义导航栏颜色', 'type' => 'switch', 'default' => false],
['key' => 'header_theme_bg_custom', 'label' => '自定义背景色', 'type' => 'color', 'default' => ''],
['key' => 'header_theme_bg', 'label' => '背景颜色(备选)', 'type' => 'color', 'default' => ''],
['key' => 'header_theme_color_custom', 'label' => '自定义文字颜色', 'type' => 'color', 'default' => ''],
]],
],
],
'header-components' => [
'header-components' => [
'key' => 'header-components',
'title' => '顶部多功能组件',
'description' => '配置顶部组件的显示范围、设备规则、轮播参数、搜索覆盖层与图标卡片。幻灯片图片/文案内容请到「Hero 轮播」「Banner 轮播」管理。',
+3 -3
View File
@@ -591,10 +591,10 @@ trait ScriptsPart1c {
],
'shell' => [
'wrapperId' => '',
'navId' => 'site-nav',
'navId' => 'navbar-top',
'searchPanelId' => 'nav-search-panel',
'drawerId' => 'nav-drawer',
'userMenuId' => 'user-dropdown',
'drawerId' => 'mobile-navbar',
'userMenuId' => 'sub-user-box',
'floatActionsId' => 'float-right-btns',
'tabbarId' => 'footer-tabbar',
],
+189 -113
View File
@@ -1,5 +1,7 @@
<?php
/**
* Nav walker — zibll senior submenu + meta decorations.
*
* @package AKSRT
*/
@@ -7,133 +9,207 @@ namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class NavWalker extends Walker_Nav_Menu {
class NavWalker extends \Walker_Nav_Menu {
/**
* @var array Decoration settings from aksrt_get_menu_decoration_settings().
*/
private $settings;
/** @var array<string,mixed> */
private $settings;
public function __construct(array $settings = []) {
$this->settings = $settings;
}
/** @var int[] */
public static $submenu_ids = [];
/**
* 当前处理的菜单项是否为 Mega Menu 容器
* @var bool
*/
private $is_mega_menu = false;
/**
* @param array<string,mixed> $settings
*/
public function __construct(array $settings = []) {
$this->settings = $settings ?: (
function_exists('aksrt_get_menu_decoration_settings')
? aksrt_get_menu_decoration_settings()
: ['icon_enabled' => true, 'badge_enabled' => true]
);
}
/**
* Mega Menu 列数
* @var int
*/
private $mega_columns = 3;
/**
* Skip WP children when parent uses senior submenu.
*/
public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {
if (!empty($element->menu_item_parent) && in_array((int) $element->menu_item_parent, self::$submenu_ids, true)) {
return;
}
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
/**
* Start level: open submenu with appropriate class based on style.
*/
public function start_lvl(&$output, $depth = 0, $args = null): void {
$indent = str_repeat("\t", $depth);
public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0): void {
$title = '<span class="menu-item-title">' . $item->title . '</span>';
if ($this->is_mega_menu && $depth === 0) {
// Mega Menu 子菜单容器
$output .= "\n{$indent}<ul class=\"sub-menu mega-menu__panel mega-menu__columns-{$this->mega_columns}\">\n";
} else {
$output .= "\n{$indent}<ul class=\"sub-menu\">\n";
}
}
$icon_enabled = !empty($this->settings['icon_enabled']);
$badge_enabled = !empty($this->settings['badge_enabled']);
/**
* Start element: add icon, badge, and classes.
*/
public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0): void {
$indent = ($depth) ? str_repeat("\t", $depth) : '';
$icon = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'icon', '') : '';
$badge = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'badge', '') : '';
$badge_class = function_exists('aksrt_menu_pz') ? (string) aksrt_menu_pz((int) $item->ID, 'badge_class', '') : '';
$classes = (array) $item->classes;
$decoration = function_exists('aksrt_get_menu_item_decoration')
? aksrt_get_menu_item_decoration($item)
: ['icon' => '', 'badge_text' => '', 'badge_type' => 'new', 'submenu_style' => ''];
if ($icon && function_exists('aksrt_render_menu_icon')) {
$title = aksrt_render_menu_icon($icon, $icon_enabled) . $title;
}
if ($badge && function_exists('aksrt_render_menu_badge')) {
$title .= aksrt_render_menu_badge($badge, $badge_class, $badge_enabled);
}
// 检测 Mega Menu 标记
$this->is_mega_menu = false;
$this->mega_columns = 3;
if ($depth === 0) {
foreach ($classes as $cls) {
if ($cls === 'mega-menu') {
$this->is_mega_menu = true;
}
if (preg_match('/^mega-menu-columns-(\d)$/', $cls, $m)) {
$this->mega_columns = max(2, min(5, (int) $m[1]));
}
}
}
$item->title = $title;
// Build li classes
$li_classes = ['menu-item', 'menu-item-' . $item->ID];
if (in_array('current-menu-item', $classes, true)) {
$li_classes[] = 'current-menu-item';
}
if (in_array('menu-item-has-children', $classes, true)) {
$li_classes[] = 'menu-item-has-children';
}
if ($this->is_mega_menu) {
$li_classes[] = 'mega-menu-item';
}
$submenu = '';
if (function_exists('aksrt_menu_pz') && aksrt_menu_pz((int) $item->ID, 'submenu_s') && (int) $depth === 0) {
$submenu = $this->submenu((int) $item->ID);
}
if ($submenu) {
$item->classes = is_array($item->classes) ? $item->classes : [];
$item->classes[] = 'menu-item-has-children';
self::$submenu_ids[] = (int) $item->ID;
}
// Add decoration classes
$li_classes[] = 'aksrt-nav__item';
if ($decoration['icon'] !== '' && !empty($this->settings['icon_enabled'])) {
$li_classes[] = 'aksrt-nav__item--has-icon';
}
if ($decoration['badge_text'] !== '' && !empty($this->settings['badge_enabled'])) {
$li_classes[] = 'aksrt-nav__item--has-badge';
}
$hover = $this->settings['hover_effect'] ?? 'underline';
if ($hover !== 'none') {
$li_classes[] = 'aksrt-nav__item--hover-' . $hover;
}
parent::start_el($output, $item, $depth, $args, $id);
$output .= $submenu;
}
$class_str = implode(' ', array_unique($li_classes));
$output .= $indent . '<li class="' . esc_attr($class_str) . '" data-menu-item-id="' . (int) $item->ID . '" data-menu-depth="' . (int) $depth . '"' . (in_array('menu-item-has-children', $classes, true) ? ' data-menu-has-children="1"' : '') . '>';
/**
* @param int $item_id
*/
public function submenu(int $item_id): string {
$type = function_exists('aksrt_menu_pz') ? sanitize_key((string) aksrt_menu_pz($item_id, 'submenu_type', '')) : '';
$method = 'submenu_' . $type;
if ($type !== '' && method_exists($this, $method)) {
return (string) $this->$method($item_id);
}
return '';
}
// Build link content
$icon_html = '';
if ($decoration['icon'] !== '' && !empty($this->settings['icon_enabled'])) {
$icon_html = aksrt_render_menu_icon($decoration['icon'], true);
}
/**
* Graphic card mega menu.
*/
public function submenu_graphic_card(int $item_id): string {
$opts = function_exists('aksrt_menu_pz') ? aksrt_menu_pz($item_id, 'graphic_card_opts', []) : [];
$opts = is_array($opts) ? $opts : [];
$items = is_array($opts['items'] ?? null) ? $opts['items'] : [];
if (!$items) {
return '';
}
$arrangement = (string) ($opts['arrangement'] ?? '');
$lists = '';
$i = 0;
foreach ($items as $item) {
$item_html = $this->submenu_graphic_card_item(is_array($item) ? $item : []);
if ($item_html === '') {
continue;
}
$ani = 'style="--ani-delay:' . ($i * 0.05) . 's;"';
$cls = $arrangement === 'swiper' ? 'swiper-slide' : '';
$lists .= '<div class="' . esc_attr($cls) . '" ' . $ani . '>' . $item_html . '</div>';
$i++;
}
if ($lists === '') {
return '';
}
$align = (string) ($opts['align'] ?? '');
$lists_box = '<div class="graphic-card-items-box flex hh' . ($align ? ' ' . esc_attr($align) : '') . '">' . $lists . '</div>';
if ($arrangement === 'swiper') {
$lists_box = '<div class="swiper-container swiper-scroll"><div class="swiper-wrapper">'
. $lists . '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
}
$size = !empty($opts['size']) ? ' size-' . sanitize_key((string) $opts['size']) : '';
$img_scale = isset($opts['img_scale']) ? (int) $opts['img_scale'] : 0;
$scale_attr = '';
if ($img_scale && $img_scale !== 100) {
$scale_attr = ' style="--img-scale:' . esc_attr((string) round($img_scale / 100, 2)) . ';"';
}
return '<div class="sub-menu senior-submenu submenu-graphic-card' . esc_attr($size) . '"' . $scale_attr . '><div class="container">'
. $lists_box . '</div></div>';
}
$badge_html = '';
if ($decoration['badge_text'] !== '' && !empty($this->settings['badge_enabled'])) {
$badge_html = aksrt_render_menu_badge($decoration['badge_text'], $decoration['badge_type'], true);
}
/**
* @param array<string,mixed> $args
*/
public function submenu_graphic_card_item(array $args): string {
if (empty($args['img'])) {
return '';
}
$link_url = !empty($args['link']['url']) ? esc_url((string) $args['link']['url']) : 'javascript:;';
$link_title = (string) ($args['link']['text'] ?? '');
$link_target = !empty($args['link']['target']) ? ' target="' . esc_attr((string) $args['link']['target']) . '"' : '';
$title = (string) ($args['title'] ?? '');
if ($title === '' && $link_title !== '') {
$title = $link_title;
}
$badge = !empty($args['badge'])
? '<div class="img-badg-box"><span class="badg badg-sm ' . esc_attr((string) ($args['badge_class'] ?? '')) . '">'
. esc_html((string) $args['badge']) . '</span></div>'
: '';
$img_html = '<div class="img-box hover-zoom-img"><img src="' . esc_url((string) $args['img']) . '" alt="" loading="lazy">' . $badge . '</div>';
$title_html = $title !== '' ? '<div class="title mt10 text-ellipsis">' . esc_html($title) . '</div>' : '';
return '<div class="menu-graphic-card-item"><a href="' . $link_url . '"' . $link_target . '>'
. $img_html . $title_html . '</a></div>';
}
// Mega Menu 子项:检查是否有描述文字(用作卡片副标题)
$description_html = '';
if ($this->is_mega_menu && $depth === 1 && !empty($item->description)) {
$description_html = '<span class="mega-menu__item-desc">' . esc_html($item->description) . '</span>';
}
/**
* Multi-column links mega menu.
*/
public function submenu_multi_column_links(int $item_id): string {
$opts = function_exists('aksrt_menu_pz') ? aksrt_menu_pz($item_id, 'multi_column_links_opts', []) : [];
$opts = is_array($opts) ? $opts : [];
$columns = is_array($opts['columns'] ?? null) ? $opts['columns'] : [];
if (!$columns) {
return '';
}
$lists = '';
$i = 1;
foreach ($columns as $column) {
if (!is_array($column)) {
continue;
}
$ani = 'style="--ani-delay:' . ($i * 0.08) . 's;"';
$lists .= '<div class="links-column flex-auto" ' . $ani . '>';
$lists .= $this->submenu_multi_column_links_item($column, 'column-title');
$lists .= '<div class="links-items">';
if (!empty($column['items']) && is_array($column['items'])) {
foreach ($column['items'] as $item) {
if (is_array($item)) {
$lists .= $this->submenu_multi_column_links_item($item, '');
}
}
}
$lists .= '</div></div>';
$i++;
}
return '<div class="sub-menu senior-submenu submenu-multi-column-links"><div class="container"><div class="links-columns-box flex jsa hh">'
. $lists . '</div></div></div>';
}
$atts = [
'href' => $item->url,
'title' => $item->attr_title ?: '',
];
$link_inner = $icon_html . '<span>' . esc_html($item->title) . '</span>' . $description_html . $badge_html;
$output .= '<a';
foreach ($atts as $attr => $value) {
if ('' !== $value) {
$output .= ' ' . $attr . '="' . esc_attr($value) . '"';
}
}
$output .= '>' . $link_inner . '</a>';
}
/**
* End element.
*/
public function end_el(&$output, $item, $depth = 0, $args = null): void {
$output .= "</li>\n";
}
/**
* @param array<string,mixed> $args
*/
public function submenu_multi_column_links_item(array $args, string $class = ''): string {
$title = (string) ($args['title'] ?? '');
$link_url = (string) ($args['link']['url'] ?? '');
$link_title = (string) ($args['link']['text'] ?? '');
if ($title === '' && $link_title !== '') {
$title = $link_title;
}
if ($title === '') {
return '';
}
$icon = '';
if (!empty($args['icon']) && function_exists('aksrt_render_menu_icon')) {
$icon = aksrt_render_menu_icon((string) $args['icon'], true);
}
if (!empty($args['img_icon'])) {
$icon = '<img class="menu-item-icon mr3 fa-fw" src="' . esc_url((string) $args['img_icon']) . '" alt="" loading="lazy">';
}
$title_html = $icon . $title;
$class = trim(($class ? $class . ' ' : '') . 'link-item');
if ($link_url !== '') {
$target = !empty($args['link']['target']) ? ' target="' . esc_attr((string) $args['link']['target']) . '"' : '';
return '<div class="' . esc_attr($class) . '"><a href="' . esc_url($link_url) . '"' . $target . '>'
. $title_html . '<i class="fa fa-angle-double-right icon-hover-show" aria-hidden="true"></i></a></div>';
}
return '<div class="' . esc_attr($class) . '"><a href="javascript:;">' . $title_html . '</a></div>';
}
}
+27 -14
View File
@@ -14,13 +14,17 @@ trait FacadeBulk {
/**
* Header navigation display settings.
*
* @return array{fixed:bool,search_enabled:bool,user_menu:bool,publish_btn:bool,mobile_drawer:bool,nav_style:string,max_width:int,scroll_down_hide:bool,layout:string,mobile_layout:string,mobile_align:string}
* @return array{
* fixed:bool,search_enabled:bool,user_menu:bool,publish_btn:bool,mobile_drawer:bool,
* nav_style:string,max_width:int,scroll_down_hide:bool,layout:string,mobile_layout:string,
* mobile_align:string,nav_pay_vip:bool,nav_user_pay_vip:bool
* }
*/
public static function get_header_nav_settings(): array {
$settings = self::get_all();
$nav_style = sanitize_key((string) ($settings['header_nav_style'] ?? 'default'));
$max_width = (int) ($settings['header_max_width'] ?? 1200);
$layout = sanitize_key((string) ($settings['header_layout'] ?? '2'));
$layout = sanitize_key((string) ($settings['header_layout'] ?? '1'));
$ml = sanitize_key((string) ($settings['mobile_header_layout'] ?? 'center'));
$ma = sanitize_key((string) ($settings['mobile_navbar_align'] ?? 'left'));
@@ -33,17 +37,20 @@ trait FacadeBulk {
}
return [
'fixed' => !isset($settings['header_fixed']) || !empty($settings['header_fixed']),
'search_enabled' => !isset($settings['header_search_enabled']) || !empty($settings['header_search_enabled']),
'user_menu' => !isset($settings['header_user_menu']) || !empty($settings['header_user_menu']),
'publish_btn' => !isset($settings['header_publish_btn']) || !empty($settings['header_publish_btn']),
'mobile_drawer' => !isset($settings['header_mobile_drawer']) || !empty($settings['header_mobile_drawer']),
'nav_style' => $nav_style,
'max_width' => $max_width,
'scroll_down_hide'=> !empty($settings['header_scroll_down_hide']),
'layout' => in_array($layout, ['1', '2', '3'], true) ? $layout : '2',
'mobile_layout' => in_array($ml, ['center', 'left'], true) ? $ml : 'center',
'mobile_align' => in_array($ma, ['top', 'left', 'right'], true) ? $ma : 'left',
'fixed' => !isset($settings['header_fixed']) || !empty($settings['header_fixed']),
'search_enabled' => !isset($settings['header_search_enabled']) || !empty($settings['header_search_enabled']),
'user_menu' => !isset($settings['header_user_menu']) || !empty($settings['header_user_menu']),
'publish_btn' => !isset($settings['header_publish_btn']) || !empty($settings['header_publish_btn']),
'mobile_drawer' => !isset($settings['header_mobile_drawer']) || !empty($settings['header_mobile_drawer']),
'nav_style' => $nav_style,
'max_width' => $max_width,
// Zibll default: true when fixed.
'scroll_down_hide' => !isset($settings['header_scroll_down_hide']) || !empty($settings['header_scroll_down_hide']),
'layout' => in_array($layout, ['1', '2', '3'], true) ? $layout : '1',
'mobile_layout' => in_array($ml, ['center', 'left'], true) ? $ml : 'center',
'mobile_align' => in_array($ma, ['top', 'left', 'right'], true) ? $ma : 'left',
'nav_pay_vip' => !isset($settings['header_nav_pay_vip']) || !empty($settings['header_nav_pay_vip']),
'nav_user_pay_vip' => !isset($settings['header_nav_user_pay_vip']) || !empty($settings['header_nav_user_pay_vip']),
];
}
@@ -52,17 +59,23 @@ trait FacadeBulk {
/**
* Header publish button configuration.
*
* @return array{enabled:bool,text:string,radius:int,class:string}
* @return array{enabled:bool,text:string,radius:int,class:string,types:string[]}
*/
public static function get_header_newposts_config(): array {
$s = self::get_all();
$types = [];
if (!empty($s['header_newposts_types']) && is_array($s['header_newposts_types'])) {
$types = array_values(array_filter(array_map('sanitize_key', $s['header_newposts_types'])));
}
return [
// Default on like zibll nav_newposts when key unset.
'enabled' => !isset($s['header_newposts_enabled']) || !empty($s['header_newposts_enabled']),
'text' => trim((string) ($s['header_newposts_text'] ?? '<i class="fa fa-pencil"></i> 发布')),
'radius' => max(0, min(30, (int) ($s['header_newposts_radius'] ?? 20))),
'class' => sanitize_html_class((string) ($s['header_newposts_class'] ?? '')),
'types' => $types,
];
}