fix(single): author card follow and identity parity
Add follow CTA to after-box author card, wrap bar label in span, and harden follow.js label updates when span is missing.
This commit is contained in:
+14
-2
@@ -68,16 +68,28 @@
|
||||
function updateFollowButton(btn, isFollowing, count) {
|
||||
var icon = btn.querySelector('i');
|
||||
var text = btn.querySelector('span');
|
||||
function setLabel(label) {
|
||||
if (text) {
|
||||
text.textContent = label;
|
||||
return;
|
||||
}
|
||||
// Fallback when markup has bare text nodes next to the icon.
|
||||
var nodes = Array.prototype.slice.call(btn.childNodes);
|
||||
var textNode = nodes.filter(function (n) { return n.nodeType === 3 && n.textContent.trim() !== ''; })[0];
|
||||
if (textNode) {
|
||||
textNode.textContent = ' ' + label + ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if (isFollowing) {
|
||||
btn.classList.add('is-following');
|
||||
if (icon) icon.className = 'fas fa-heart';
|
||||
if (text) text.textContent = '已关注';
|
||||
setLabel('已关注');
|
||||
btn.title = '点击取消关注';
|
||||
} else {
|
||||
btn.classList.remove('is-following');
|
||||
if (icon) icon.className = 'far fa-heart';
|
||||
if (text) text.textContent = '关注';
|
||||
setLabel('关注');
|
||||
btn.title = '关注该用户';
|
||||
}
|
||||
|
||||
|
||||
@@ -321,13 +321,15 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
'order' => 'DESC',
|
||||
'no_found_rows' => true,
|
||||
]);
|
||||
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
|
||||
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
||||
?>
|
||||
<div class="user-card author zib-widget">
|
||||
<div class="card-content mt10 relative">
|
||||
<div class="user-content">
|
||||
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="user-info mt20 mb10">
|
||||
<div class="user-name flex jc">
|
||||
<div class="user-name flex jc ac">
|
||||
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
||||
<?php if ($identity_chips !== '') : ?>
|
||||
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
@@ -337,6 +339,17 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($bio); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="user-btns mt20">
|
||||
<?php if (!$is_self) : ?>
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<button type="button" class="but pw-1em mr6 c-red follow" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
||||
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<a href="<?php echo esc_url($login_url); ?>" class="but pw-1em mr6 c-red follow">
|
||||
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($author_url); ?>"><?php esc_html_e('个人主页', 'aksrt'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -351,11 +364,14 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="user-card-posts mt10 muted-2-color em09 text-center"><?php esc_html_e('暂无更多文章', 'aksrt'); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_prevnext')) :
|
||||
|
||||
@@ -90,7 +90,7 @@ $identity_chips = function_exists('aksrt_render_user_identity_chips')
|
||||
<?php if (!$is_self) : ?>
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
||||
<i class="fa fa-heart em09" aria-hidden="true"></i> <?php esc_html_e('关注', 'aksrt'); ?>
|
||||
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</button>
|
||||
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
|
||||
<a href="<?php echo esc_url(add_query_arg('msg_type', 'conversation', $aksrt_msg_url)); ?>" class="ml6 but c-blue px12-sm">
|
||||
|
||||
Reference in New Issue
Block a user