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>
113 lines
3.2 KiB
PHP
113 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Menu decoration helpers — legacy's jio_menu_options contract.
|
|
*
|
|
* @package Jio
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/**
|
|
* Read one menu item option from post meta jio_menu_options.
|
|
*
|
|
* @param int $id Menu item ID.
|
|
* @param string $key Option key.
|
|
* @param mixed $default Default.
|
|
* @return mixed
|
|
*/
|
|
function jio_menu_pz(int $id, string $key = '', $default = '') {
|
|
static $options = [];
|
|
if (!isset($options[$id])) {
|
|
$raw = get_post_meta($id, 'jio_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, jiosvg- or customsvg-).
|
|
* @param bool $enabled Global switch.
|
|
* @param string $extra_classes Classes appended to the glyph. Top-level menu
|
|
* titles use the default; mega-menu link lists use
|
|
* `mr3 fa-fw` so every row's glyph is the same width.
|
|
*/
|
|
function jio_render_menu_icon(string $icon_class, bool $enabled = true, string $extra_classes = 'mr3 menu-item-icon'): string {
|
|
if (!$enabled || $icon_class === '') {
|
|
return '';
|
|
}
|
|
|
|
$extra = trim($extra_classes);
|
|
|
|
// Sprite/inline values must reach jio_icon_markup untouched — the legacy
|
|
// FA class padding below would corrupt them (jiosvg-hot → fa fas fa-jiosvg-hot).
|
|
if (str_starts_with($icon_class, 'jiosvg-')) {
|
|
return jio_icon_markup($icon_class, $extra === '' ? 'icon' : 'icon ' . $extra);
|
|
}
|
|
if (str_starts_with($icon_class, 'customsvg-')) {
|
|
return jio_icon_markup($icon_class, $extra);
|
|
}
|
|
|
|
// 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 jio_icon_markup($icon_class, $extra);
|
|
}
|
|
|
|
/**
|
|
* Whether a menu item passes its display policy (show_policy).
|
|
*
|
|
* @param int $menu_item_id Menu item ID.
|
|
* @return bool
|
|
*/
|
|
function jio_menu_item_match_show_policy(int $menu_item_id): bool {
|
|
$policy = (string) jio_menu_pz($menu_item_id, 'show_policy', '');
|
|
if ($policy === '') {
|
|
return true;
|
|
}
|
|
|
|
$user_id = get_current_user_id();
|
|
if ($user_id <= 0) {
|
|
return false;
|
|
}
|
|
|
|
switch ($policy) {
|
|
case 'signin':
|
|
return true;
|
|
case 'vip':
|
|
return function_exists('jio_is_vip') && jio_is_vip($user_id);
|
|
case 'vip_2':
|
|
return function_exists('jio_is_vip2') && jio_is_vip2($user_id);
|
|
case 'auth':
|
|
if (!function_exists('jio_get_user_identity_signals')) {
|
|
return false;
|
|
}
|
|
foreach (jio_get_user_identity_signals($user_id) as $signal) {
|
|
if ((string) ($signal['type'] ?? '') === 'verify') {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @param string $text Badge text.
|
|
* @param string $class Extra class (jb-red etc.).
|
|
* @param bool $enabled Global switch.
|
|
*/
|
|
function jio_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>';
|
|
}
|