69 lines
2.0 KiB
PHP
69 lines
2.0 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;
|
|
}
|
|
|
|
/**
|
|
* @param string $icon_class Icon-picker value (FA5 class, zibsvg- or customsvg-).
|
|
* @param bool $enabled Global switch.
|
|
*/
|
|
function aksrt_render_menu_icon(string $icon_class, bool $enabled = true): string {
|
|
if (!$enabled || $icon_class === '') {
|
|
return '';
|
|
}
|
|
|
|
// Sprite/inline values must reach aksrt_icon_markup untouched — the legacy
|
|
// FA class padding below would corrupt them (zibsvg-hot → fa fas fa-zibsvg-hot).
|
|
if (str_starts_with($icon_class, 'zibsvg-')) {
|
|
return aksrt_icon_markup($icon_class, 'icon mr3 menu-item-icon');
|
|
}
|
|
if (str_starts_with($icon_class, 'customsvg-')) {
|
|
return aksrt_icon_markup($icon_class, 'mr3 menu-item-icon');
|
|
}
|
|
|
|
// 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 aksrt_icon_markup($icon_class, 'mr3 menu-item-icon');
|
|
}
|
|
|
|
/**
|
|
* @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>';
|
|
}
|