fix(float): repair VIP rail entry front and admin
Always open VIP modal for float pay_vip, drop forced admin link, normalize gem icon, harden pay-vip click binding and SPA form UX.
This commit is contained in:
@@ -55,6 +55,10 @@ endif;
|
||||
if (!function_exists('aksrt_get_float_pay_vip_html')) :
|
||||
/**
|
||||
* Floating VIP open button.
|
||||
*
|
||||
* Always opens the site VIP modal for logged-in non-max VIP users
|
||||
* (class pay-vip → assets/js/pay-vip.js). Guests get signin-loader.
|
||||
* Admin "link/hover" fields are intentionally ignored for this type.
|
||||
*/
|
||||
function aksrt_get_float_pay_vip_html(array $item = []): string {
|
||||
$show_vip = false;
|
||||
@@ -70,15 +74,34 @@ if (!function_exists('aksrt_get_float_pay_vip_html')) :
|
||||
if ($user_id > 0 && function_exists('aksrt_get_user_vip_level')) {
|
||||
$level = (int) aksrt_get_user_vip_level($user_id);
|
||||
}
|
||||
// Hide for max VIP if we only have 2 tiers and already VIP.
|
||||
// Already top tier — no upsell entry on float rail.
|
||||
if ($level >= 2) {
|
||||
return '';
|
||||
}
|
||||
$title = $level === 1 ? __('升级会员', 'aksrt') : __('开通会员', 'aksrt');
|
||||
$icon = !empty($item['icon']) ? (string) $item['icon'] : 'fas fa-gem';
|
||||
$cls = $user_id > 0 ? 'float-btn pay-vip' : 'float-btn signin-loader';
|
||||
// Modal path: .pay-vip opens VIP modal (Batch 2+); guests use signin-loader.
|
||||
$href = 'javascript:;';
|
||||
|
||||
// Prefer admin title; fallback by upgrade vs open.
|
||||
$admin_title = trim((string) ($item['text'] ?? ''));
|
||||
if ($admin_title !== '') {
|
||||
$title = $admin_title;
|
||||
} else {
|
||||
$title = $level === 1 ? __('升级会员', 'aksrt') : __('开通会员', 'aksrt');
|
||||
}
|
||||
|
||||
$icon = trim((string) ($item['icon'] ?? ''));
|
||||
if ($icon === '') {
|
||||
$icon = 'fas fa-gem';
|
||||
}
|
||||
// FA4 leftovers from older admin data.
|
||||
$icon = strtr($icon, [
|
||||
'fa-diamond' => 'fa-gem',
|
||||
'fa fa-' => 'fas fa-',
|
||||
]);
|
||||
if (!preg_match('/\b(fas|far|fab|fal|fad)\b/', $icon)) {
|
||||
$icon = 'fas ' . ltrim(preg_replace('/^fa\s+/', '', $icon) ?? $icon);
|
||||
}
|
||||
|
||||
// Logged-in: open modal. Guest: open login.
|
||||
$cls = $user_id > 0 ? 'float-btn pay-vip nowave' : 'float-btn signin-loader nowave';
|
||||
$style = [];
|
||||
if (!empty($item['color'])) {
|
||||
$style[] = '--this-color:' . esc_attr((string) $item['color']);
|
||||
@@ -86,9 +109,19 @@ if (!function_exists('aksrt_get_float_pay_vip_html')) :
|
||||
if (!empty($item['bg'])) {
|
||||
$style[] = '--this-bg:' . esc_attr((string) $item['bg']);
|
||||
}
|
||||
// Default VIP accent when admin left color empty.
|
||||
if (empty($item['color'])) {
|
||||
$style[] = '--this-color:#f5a623';
|
||||
}
|
||||
$style_attr = $style ? ' style="' . implode(';', $style) . '"' : '';
|
||||
$vip_level_attr = $user_id > 0 ? ' vip-level="' . esc_attr((string) max(1, min(2, $level + 1))) . '"' : '';
|
||||
return '<a class="' . esc_attr($cls) . '" href="' . esc_attr($href) . '" title="' . esc_attr($title) . '"' . $style_attr . $vip_level_attr . '>'
|
||||
|
||||
// Prefer upgrading one tier when already VIP1.
|
||||
$target_level = $user_id > 0 ? max(1, min(2, $level + 1)) : 1;
|
||||
$vip_level_attr = $user_id > 0
|
||||
? ' vip-level="' . esc_attr((string) $target_level) . '" data-vip-level="' . esc_attr((string) $target_level) . '"'
|
||||
: '';
|
||||
|
||||
return '<a class="' . esc_attr($cls) . '" href="javascript:;" role="button" aria-label="' . esc_attr($title) . '" title="' . esc_attr($title) . '"' . $style_attr . $vip_level_attr . '>'
|
||||
. '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>'
|
||||
. '</a>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user