Files
wordpress-theme-aksrt/inc/helpers/aksrt-runtime-win.php
T

79 lines
2.5 KiB
PHP

<?php
/**
* Float button commerce types.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
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;
if (class_exists('\AKSRT\Settings\Settings')) {
$vs = \AKSRT\Settings\Settings::get_payment_vip_settings();
$show_vip = !empty($vs['enabled']);
}
if (!$show_vip) {
return '';
}
$user_id = get_current_user_id();
$level = 0;
if ($user_id > 0 && function_exists('aksrt_get_user_vip_level')) {
$level = (int) aksrt_get_user_vip_level($user_id);
}
// Already top tier — no upsell entry on float rail.
if ($level >= 2) {
return '';
}
// 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 = 'fa fas fa-gem';
}
if (!preg_match('/^fa\s+(?:fas|far|fab)\s+fa-[a-z0-9-]+(?:\s+fa-[a-z0-9-]+)*$/i', $icon)) {
$icon = 'fa fas fa-gem';
}
// 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']);
}
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) . '"' : '';
// 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>';
}
endif;