feat(single): align author bar follow and reward actions with the site flows
- guests get the sign-in trigger instead of a redirect to the login page, for both follow and wallet reward controls - follow requests swap the label for an inline loader and block a second submit; the followed state uses the .actived hook - follower counts sync through data-follow-count on the user homepage (the previous selector matched nothing) and only for the viewed profile - reward button uses the secondary action colour; the reward template is only rendered for signed-in visitors - drop the unused author-hero aria-disabled rule and stale wording in the touched comments Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ad5ef9aff
commit
d40906b4a3
13 files changed
+148
-56
No files matched your search
@@ -142,12 +142,18 @@ if (!function_exists('jio_render_user_identity_chips')) {
|
||||
if (!function_exists('jio_get_user_follow')) {
|
||||
/**
|
||||
* Render the canonical user follow control.
|
||||
*
|
||||
* Guests get the login trigger instead of a follow request; signed-in
|
||||
* visitors get the server-rendered state that follow.js keeps in sync.
|
||||
*/
|
||||
function jio_get_user_follow(string $class, int $follow_id, ?string $text = null, ?string $ok_text = null, ?string $guest_text = null): string {
|
||||
$current_user_id = get_current_user_id();
|
||||
if ($follow_id <= 0 || $current_user_id === $follow_id) {
|
||||
return '';
|
||||
}
|
||||
if (class_exists('\Jio\Settings\Settings') && \Jio\Settings\Settings::close_sign()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$text = $text ?? __('关注', 'jio');
|
||||
$ok_text = $ok_text ?? __('已关注', 'jio');
|
||||
@@ -155,18 +161,20 @@ if (!function_exists('jio_get_user_follow')) {
|
||||
$class = trim($class);
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
$login_url = function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url();
|
||||
return '<a class="' . esc_attr($class) . '" href="' . esc_url($login_url) . '"><i class="fa far fa-heart em09" aria-hidden="true"></i> <span>' . esc_html($guest_text) . '</span></a>';
|
||||
// 游客点击由 auth.js 的全局委托拉起登录弹窗,不直接跳转登录页。
|
||||
return '<a href="javascript:;" class="' . esc_attr($class . ' signin-loader') . '"><i class="fa far fa-heart em09" aria-hidden="true"></i> <span>' . esc_html($guest_text) . '</span></a>';
|
||||
}
|
||||
|
||||
$is_following = class_exists('\Jio\User\Follow')
|
||||
&& \Jio\User\Follow::get_instance()->is_following($current_user_id, $follow_id);
|
||||
$state_class = $is_following ? ' is-following' : '';
|
||||
$state_class = $is_following ? ' actived' : '';
|
||||
$title = $is_following ? __('点击取消关注', 'jio') : __('关注该用户', 'jio');
|
||||
$label = $is_following ? $ok_text : $text;
|
||||
$icon_class = $is_following ? 'fa fas fa-heart em09' : 'fa far fa-heart em09';
|
||||
// 文案随按钮下发,follow.js 切换状态时沿用同一套标签。
|
||||
$labels = ' data-jio-follow-text="' . esc_attr($text) . '" data-jio-follow-ok="' . esc_attr($ok_text) . '"';
|
||||
|
||||
return '<a href="javascript:;" class="' . esc_attr($class . $state_class) . '" data-jio-follow="' . $follow_id . '" title="' . esc_attr($title) . '"><i class="' . esc_attr($icon_class) . '" aria-hidden="true"></i> <span data-jio-follow-label>' . esc_html($label) . '</span></a>';
|
||||
return '<a href="javascript:;" class="' . esc_attr($class . $state_class) . '" data-jio-follow="' . $follow_id . '"' . $labels . ' title="' . esc_attr($title) . '"><i class="' . esc_attr($icon_class) . '" aria-hidden="true"></i> <span data-jio-follow-label>' . esc_html($label) . '</span></a>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +221,7 @@ if (!function_exists('jio_get_user_name')) {
|
||||
$display = $user->display_name;
|
||||
$vip_html = '';
|
||||
if (!empty($args['vip'])) {
|
||||
// 禁封徽章占据 VIP 图标位(参考主题 user_name_badge 过滤器覆盖语义)。
|
||||
// 禁封徽章占据 VIP 图标位(禁封态覆盖会员图标)。
|
||||
$vip_html = function_exists('jio_get_user_ban_name_badge')
|
||||
? jio_get_user_ban_name_badge($user_id)
|
||||
: '';
|
||||
@@ -561,8 +569,8 @@ if (!function_exists('jio_get_worn_medal_icon')) {
|
||||
|
||||
if (!function_exists('jio_is_blog_comment_hot')) {
|
||||
/**
|
||||
* "神评" for ordinary post comments when likes cross the fixed threshold
|
||||
* (参考主题固定 10 赞,主题不再提供该阈值配置).
|
||||
* "神评" for ordinary post comments when likes cross the fixed 10-like
|
||||
* threshold (not configurable).
|
||||
*/
|
||||
function jio_is_blog_comment_hot($comment): bool {
|
||||
$comment_id = $comment instanceof WP_Comment ? (int) $comment->comment_ID : (int) $comment;
|
||||
|
||||
@@ -25,6 +25,17 @@ if (!function_exists('jio_get_rewards_button')) {
|
||||
$settings = \Jio\Settings\Settings::get_post_page_settings();
|
||||
$label = (string) ($settings['rewards_btn_text'] ?? __('赞赏', 'jio'));
|
||||
$icon = function_exists('jio_icon_markup') ? jio_icon_markup('jiosvg-money') : '';
|
||||
|
||||
// 站内余额赞赏必须登录;游客点按钮直接拉起登录弹窗,不在提交后才报错。
|
||||
if (!is_user_logged_in()) {
|
||||
return sprintf(
|
||||
'<a href="javascript:;" class="%1$s signin-loader">%2$s<text>%3$s</text></a>',
|
||||
esc_attr($class),
|
||||
$icon, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed sprite markup.
|
||||
esc_html($label)
|
||||
);
|
||||
}
|
||||
|
||||
$template_id = 'jio-reward-template-' . $user_id . '-' . $post_id;
|
||||
return sprintf(
|
||||
'<button type="button" class="%1$s jio-reward-open" data-jio-reward-open data-template-id="%2$s" data-user-id="%3$d" data-post-id="%4$d">%5$s<text>%6$s</text></button>',
|
||||
@@ -42,7 +53,7 @@ if (!function_exists('jio_render_rewards_template_for_user')) {
|
||||
function jio_render_rewards_template_for_user(int $user_id, int $post_id = 0): void {
|
||||
static $done = [];
|
||||
$key = $user_id . ':' . $post_id;
|
||||
if ($user_id <= 0 || isset($done[$key]) || !jio_rewards_enabled()) {
|
||||
if ($user_id <= 0 || isset($done[$key]) || !jio_rewards_enabled() || !is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
$done[$key] = true;
|
||||
|
||||
@@ -47,7 +47,7 @@ $result = $follow
|
||||
<div class="uc-follow-management__identity"><a href="<?php echo esc_url($home_url); ?>"><?php echo esc_html((string) ($item['display_name'] ?? '')); ?></a><span><?php echo esc_html(sprintf(__('关注于 %s', 'jio'), get_date_from_gmt((string) ($item['created_at'] ?? ''), get_option('date_format')))); ?></span></div>
|
||||
<div class="uc-follow-management__actions">
|
||||
<a class="btn-ghost btn-sm" href="<?php echo esc_url($home_url); ?>"><?php esc_html_e('主页', 'jio'); ?></a>
|
||||
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm is-following" data-jio-follow="<?php echo esc_attr((string) $member_id); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span data-jio-follow-label><?php esc_html_e('已关注', 'jio'); ?></span></button><?php endif; ?>
|
||||
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm actived" data-jio-follow="<?php echo esc_attr((string) $member_id); ?>" data-jio-follow-text="<?php esc_attr_e('关注', 'jio'); ?>" data-jio-follow-ok="<?php esc_attr_e('已关注', 'jio'); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span data-jio-follow-label><?php esc_html_e('已关注', 'jio'); ?></span></button><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
Reference in new issue
Block a user