进行了一些小优化
This commit is contained in:
@@ -11,10 +11,11 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
|
||||
/**
|
||||
* 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.
|
||||
* @param int $user_id Current user ID.
|
||||
* @param bool $compact Render a short card-friendly label.
|
||||
* @param string|null $class Override the button classes (keeps data-signin behavior).
|
||||
*/
|
||||
function aksrt_header_user_checkin_btn(int $user_id = 0, bool $compact = false): string {
|
||||
function aksrt_header_user_checkin_btn(int $user_id = 0, bool $compact = false, ?string $class = null): string {
|
||||
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
if ($user_id <= 0 || !class_exists('\AKSRT\Credits\Signin')) {
|
||||
return '';
|
||||
@@ -28,15 +29,15 @@ if (!function_exists('aksrt_header_user_checkin_btn')) :
|
||||
|
||||
$signed = \AKSRT\Credits\Signin::get_instance()->is_signed_today($user_id);
|
||||
|
||||
$compact_class = $compact ? ' aksrt-header-checkin--compact' : '';
|
||||
$classes = $class ?? ('but block c-yellow aksrt-header-checkin' . ($compact ? ' aksrt-header-checkin--compact' : ''));
|
||||
if ($signed) {
|
||||
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>'
|
||||
return '<button type="button" class="' . esc_attr($classes . ' 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 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-signin-btn data-signin-idle-label="' . esc_attr__('签到', 'aksrt') . '" data-signin-done-label="' . esc_attr__('已签到', 'aksrt') . '">'
|
||||
return '<button type="button" class="' . esc_attr($classes) . '" 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 data-signin-label>' . esc_html($compact ? __('签到', 'aksrt') : __('签到领取今日奖励', 'aksrt')) . '</span>'
|
||||
. '</button>';
|
||||
|
||||
@@ -223,10 +223,15 @@ if (!function_exists('aksrt_get_user_name')) {
|
||||
$follow_html = '';
|
||||
if (!empty($args['follow']) && get_current_user_id() !== $user_id) {
|
||||
if (is_user_logged_in()) {
|
||||
$follow_html = '<button type="button" class="focus-color ml10 follow flex0 but" data-aksrt-follow="' . (int) $user_id . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html__('关注', 'aksrt') . '</button>';
|
||||
// 服务端直接输出真实关注状态(legacy parity: zib_get_user_follow 恒渲染当前态)。
|
||||
$is_following = class_exists('\AKSRT\User\Follow') && \AKSRT\User\Follow::get_instance()->is_following(get_current_user_id(), $user_id);
|
||||
$follow_label = $is_following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
|
||||
$follow_title = $is_following ? __('点击取消关注', 'aksrt') : __('关注该用户', 'aksrt');
|
||||
$follow_state = $is_following ? ' is-following' : '';
|
||||
$follow_html = '<button type="button" class="focus-color ml10 follow flex0' . $follow_state . '" data-aksrt-follow="' . (int) $user_id . '" title="' . esc_attr($follow_title) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html($follow_label) . '</button>';
|
||||
} else {
|
||||
$login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url();
|
||||
$follow_html = '<a class="focus-color ml10 follow flex0 but" href="' . esc_url($login) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html__('关注', 'aksrt') . '</a>';
|
||||
$follow_html = '<a class="focus-color ml10 follow flex0" href="' . esc_url($login) . '"><i class="fa fas fa-heart em09" aria-hidden="true"></i> ' . esc_html__('关注', 'aksrt') . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user