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.
99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Menu decoration helpers — aksrt_menu_options meta only (zibll zib_menu_pz).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/**
|
|
* Global decoration switches (SPA). Per-item data is always from meta.
|
|
*
|
|
* @return array<string,mixed>
|
|
*/
|
|
function aksrt_get_menu_decoration_settings(): array {
|
|
static $cache = null;
|
|
if ($cache !== null) {
|
|
return $cache;
|
|
}
|
|
|
|
$all = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_all()
|
|
: [];
|
|
|
|
$cache = [
|
|
'icon_enabled' => !isset($all['menu_icon_enabled']) || !empty($all['menu_icon_enabled']),
|
|
'badge_enabled' => !isset($all['menu_badge_enabled']) || !empty($all['menu_badge_enabled']),
|
|
];
|
|
|
|
return $cache;
|
|
}
|
|
|
|
/**
|
|
* 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 '';
|
|
}
|
|
// Allow bare "fa-home" → "fas fa-home".
|
|
if (strpos($icon_class, 'fa') === false) {
|
|
$icon_class = 'fas fa-' . ltrim($icon_class, '-');
|
|
} elseif (strpos($icon_class, 'fa-') === 0 && strpos($icon_class, ' ') === false) {
|
|
$icon_class = 'fas ' . $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>';
|
|
}
|