- assets/vendor 全量迁移: fontawesome5→assets/fontawesome5, css→assets/css, js→assets/js/runtime(避开 14 个同名自有文件), img 合并去重→assets/img, fonts→assets/fonts; 删除 assets/vendor - libs 五个与 widgets/third-party 字节相同的库不重复入库, loader paths 改指向 - 运行时切换: _win.uri=assets 根, loader baseUrl=/js/runtime, enlighter 注入 路径同步; PHP 7 个引用文件切换并改名 $zibll_*→$runtime_* - 去品牌: Qinver 头注释/品牌 console.log/演示链接清除, 默认文案中性化 - 功能标识符改名: zib__→aksrt__, zib_ajax→aksrt_ajax, window.zib→ window.aksrtLegacy, zibllblock/*→aksrtblock/*, .zib-widget→.aksrt-panel, .zib-slider→.aksrt-slider, zib_menu_options meta 键等 - 自有 CSS 改名: legacy-utilities/compat-vars/footer shell - admin SPA 重建; 契约测试同步(路径/断言/文件更名) - 例外保留: tests/visual 对照环境与 fixtures 前缀(外部 Zibll 产品引用) 验证: php -l 133 个改动文件通过; runtime 86 个 JS node --check 通过; 契约测试 68/70(2 个失败经 stash 对照确认为存量问题)
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* Menu decoration helpers — legacy's aksrt_menu_options contract.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/**
|
|
* Read one menu item option from post meta aksrt_menu_options.
|
|
*
|
|
* @param int $id Menu item ID.
|
|
* @param string $key Option key.
|
|
* @param mixed $default Default.
|
|
* @return mixed
|
|
*/
|
|
function aksrt_menu_pz(int $id, string $key = '', $default = '') {
|
|
static $options = [];
|
|
if (!isset($options[$id])) {
|
|
$raw = get_post_meta($id, 'aksrt_menu_options', true);
|
|
$options[$id] = is_array($raw) ? $raw : [];
|
|
}
|
|
if ($key === '') {
|
|
return $options[$id];
|
|
}
|
|
return $options[$id][$key] ?? $default;
|
|
}
|
|
|
|
/**
|
|
* Decoration for a menu item (meta only).
|
|
*
|
|
* @param WP_Post|object $menu_item Menu item.
|
|
* @return array{icon:string,badge_text:string,badge_class:string,submenu_s:bool,submenu_type:string}
|
|
*/
|
|
function aksrt_get_menu_item_decoration($menu_item): array {
|
|
$id = (int) ($menu_item->ID ?? 0);
|
|
return [
|
|
'icon' => (string) aksrt_menu_pz($id, 'icon', ''),
|
|
'badge_text' => (string) aksrt_menu_pz($id, 'badge', ''),
|
|
'badge_class' => (string) aksrt_menu_pz($id, 'badge_class', ''),
|
|
'submenu_s' => !empty(aksrt_menu_pz($id, 'submenu_s', false)),
|
|
'submenu_type' => sanitize_key((string) aksrt_menu_pz($id, 'submenu_type', '')),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param string $icon_class FA5 icon class.
|
|
* @param bool $enabled Global switch.
|
|
*/
|
|
function aksrt_render_menu_icon(string $icon_class, bool $enabled = true): string {
|
|
if (!$enabled || $icon_class === '') {
|
|
return '';
|
|
}
|
|
// legacy uses the Font Awesome 5 `fa` prefix.
|
|
if (strpos($icon_class, 'fa') === false) {
|
|
$icon_class = 'fa fas fa-' . ltrim($icon_class, '-');
|
|
} elseif (strpos($icon_class, 'fa-') === 0 && strpos($icon_class, ' ') === false) {
|
|
$icon_class = 'fa ' . $icon_class;
|
|
}
|
|
return '<i class="' . esc_attr($icon_class) . ' mr3 menu-item-icon" aria-hidden="true"></i>';
|
|
}
|
|
|
|
/**
|
|
* @param string $text Badge text.
|
|
* @param string $class Extra class (jb-red etc.).
|
|
* @param bool $enabled Global switch.
|
|
*/
|
|
function aksrt_render_menu_badge(string $text, string $class = '', bool $enabled = true): string {
|
|
if (!$enabled || $text === '') {
|
|
return '';
|
|
}
|
|
$cls = trim('menu-item-badge ' . $class);
|
|
return ' <badge class="' . esc_attr($cls) . '">' . esc_html($text) . '</badge>';
|
|
}
|