修复导航栏用户卡片浮层的签到按钮
This commit is contained in:
1 parent
d27c0757f2
commit
d69334b37d
7 files changed
+265
-198
No files matched your search
@@ -9,7 +9,7 @@ defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_header_user_checkin_btn')) :
|
||||
/**
|
||||
* Check-in CTA for header dropdown and compact card placements (uses REST /aksrt/v1/signin).
|
||||
* Check-in CTA for header dropdown and compact card placements.
|
||||
*
|
||||
* @param int $user_id Current user ID.
|
||||
* @param bool $compact Render a short card-friendly label.
|
||||
@@ -26,37 +26,48 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
|
||||
return '';
|
||||
}
|
||||
|
||||
// Lightweight today status via private API if available.
|
||||
$signed = false;
|
||||
try {
|
||||
$signin = \AKSRT\Credits\Signin::get_instance();
|
||||
// Prefer public method if present.
|
||||
if (method_exists($signin, 'is_signed_today')) {
|
||||
$signed = (bool) $signin->is_signed_today($user_id);
|
||||
} else {
|
||||
// Fallback: direct meta/table probe via rest_today logic is heavy; use option day key.
|
||||
$day = wp_date('Y-m-d');
|
||||
$signed = (bool) get_user_meta($user_id, 'aksrt_signin_' . $day, true);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$signed = false;
|
||||
}
|
||||
$signed = \AKSRT\Credits\Signin::get_instance()->is_signed_today($user_id);
|
||||
|
||||
$compact_class = $compact ? ' aksrt-header-checkin--compact' : '';
|
||||
if ($signed) {
|
||||
return '<button type="button" class="but block c-yellow aksrt-header-checkin' . $compact_class . ' is-done" disabled>'
|
||||
return '<button type="button" class="but block c-yellow aksrt-header-checkin' . $compact_class . ' is-done" data-signin-btn data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '" data-signin-done-label="' . esc_attr__('已签到', 'aksrt') . '" disabled>'
|
||||
. '<i class="fa fas fa-calendar-check" aria-hidden="true"></i>'
|
||||
. '<span>' . esc_html($compact ? __('已签到', 'aksrt') : __('今日已签到', 'aksrt')) . '</span>'
|
||||
. '<span data-signin-label>' . esc_html($compact ? __('已签到', 'aksrt') : __('今日已签到', 'aksrt')) . '</span>'
|
||||
. '</button>';
|
||||
}
|
||||
|
||||
return '<button type="button" class="but block c-yellow aksrt-header-checkin' . $compact_class . '" data-aksrt-checkin="1">'
|
||||
return '<button type="button" class="but block c-yellow aksrt-header-checkin' . $compact_class . '" data-signin-btn data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '" data-signin-done-label="' . esc_attr__('已签到', 'aksrt') . '">'
|
||||
. '<i class="fa fas fa-calendar-check" aria-hidden="true"></i>'
|
||||
. '<span>' . esc_html($compact ? __('签到', 'aksrt') : __('签到领取今日奖励', 'aksrt')) . '</span>'
|
||||
. '<span data-signin-label>' . esc_html($compact ? __('签到', 'aksrt') : __('签到领取今日奖励', 'aksrt')) . '</span>'
|
||||
. '</button>';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_signin_captcha')) :
|
||||
/**
|
||||
* Render the single global captcha mount used by every sign-in button.
|
||||
*/
|
||||
function aksrt_render_signin_captcha(): void {
|
||||
if (
|
||||
!is_user_logged_in()
|
||||
|| !class_exists('\AKSRT\Credits\Signin')
|
||||
|| !class_exists('\AKSRT\Settings\Settings')
|
||||
|| empty(\AKSRT\Settings\Settings::get_signin_reward_settings()['enabled'])
|
||||
|| !function_exists('aksrt_is_captcha_enabled_for')
|
||||
|| !function_exists('aksrt_render_captcha')
|
||||
|| !aksrt_is_captcha_enabled_for('signin')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="aksrt-signin-captcha" data-signin-captcha>
|
||||
<?php aksrt_render_captcha('signin'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
add_action('wp_footer', 'aksrt_render_signin_captcha');
|
||||
|
||||
if (!function_exists('aksrt_header_user_wallet_mini')) :
|
||||
/**
|
||||
* Mini wallet strip: credits + cash balance.
|
||||
|
||||
Reference in new issue
Block a user