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:
1 parent
2c31da1454
commit
9b98080daf
3 files changed
+85
-57
No files matched your search
+14
-2
@@ -68,16 +68,28 @@
|
|||||||
function updateFollowButton(btn, isFollowing, count) {
|
function updateFollowButton(btn, isFollowing, count) {
|
||||||
var icon = btn.querySelector('i');
|
var icon = btn.querySelector('i');
|
||||||
var text = btn.querySelector('span');
|
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) {
|
if (isFollowing) {
|
||||||
btn.classList.add('is-following');
|
btn.classList.add('is-following');
|
||||||
if (icon) icon.className = 'fas fa-heart';
|
if (icon) icon.className = 'fas fa-heart';
|
||||||
if (text) text.textContent = '已关注';
|
setLabel('已关注');
|
||||||
btn.title = '点击取消关注';
|
btn.title = '点击取消关注';
|
||||||
} else {
|
} else {
|
||||||
btn.classList.remove('is-following');
|
btn.classList.remove('is-following');
|
||||||
if (icon) icon.className = 'far fa-heart';
|
if (icon) icon.className = 'far fa-heart';
|
||||||
if (text) text.textContent = '关注';
|
setLabel('关注');
|
||||||
btn.title = '关注该用户';
|
btn.title = '关注该用户';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -299,63 +299,79 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
|||||||
* @param array<string,mixed> $ctx Single context.
|
* @param array<string,mixed> $ctx Single context.
|
||||||
*/
|
*/
|
||||||
function aksrt_single_render_author_card(array $ctx): void {
|
function aksrt_single_render_author_card(array $ctx): void {
|
||||||
$author_id = (int) get_the_author_meta('ID');
|
$author_id = (int) get_the_author_meta('ID');
|
||||||
if ($author_id <= 0) {
|
if ($author_id <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$author_url = get_author_posts_url($author_id);
|
$author_url = get_author_posts_url($author_id);
|
||||||
$author_name = get_the_author();
|
$author_name = get_the_author();
|
||||||
$bio = trim((string) get_the_author_meta('description'));
|
$bio = trim((string) get_the_author_meta('description'));
|
||||||
$identity_chips = function_exists('aksrt_render_user_identity_chips')
|
$identity_chips = function_exists('aksrt_render_user_identity_chips')
|
||||||
? aksrt_render_user_identity_chips($author_id, 'card')
|
? aksrt_render_user_identity_chips($author_id, 'card')
|
||||||
: '';
|
: '';
|
||||||
$avatar = function_exists('aksrt_get_avatar_html')
|
$avatar = function_exists('aksrt_get_avatar_html')
|
||||||
? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg'])
|
? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg'])
|
||||||
: get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']);
|
: get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']);
|
||||||
$recent = get_posts([
|
$recent = get_posts([
|
||||||
'author' => $author_id,
|
'author' => $author_id,
|
||||||
'post_type' => 'post',
|
'post_type' => 'post',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'posts_per_page' => 6,
|
'posts_per_page' => 6,
|
||||||
'orderby' => 'date',
|
'orderby' => 'date',
|
||||||
'order' => 'DESC',
|
'order' => 'DESC',
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
]);
|
]);
|
||||||
?>
|
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
|
||||||
<div class="user-card author zib-widget">
|
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
||||||
<div class="card-content mt10 relative">
|
?>
|
||||||
<div class="user-content">
|
<div class="user-card author zib-widget">
|
||||||
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
<div class="card-content mt10 relative">
|
||||||
<div class="user-info mt20 mb10">
|
<div class="user-content">
|
||||||
<div class="user-name flex jc">
|
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||||
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
<div class="user-info mt20 mb10">
|
||||||
<?php if ($identity_chips !== '') : ?>
|
<div class="user-name flex jc ac">
|
||||||
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
||||||
<?php endif; ?>
|
<?php if ($identity_chips !== '') : ?>
|
||||||
</div>
|
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||||
<?php if ($bio !== '') : ?>
|
|
||||||
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($bio); ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
<div class="user-btns mt20">
|
|
||||||
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($author_url); ?>"><?php esc_html_e('个人主页', 'aksrt'); ?></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php if (!empty($recent)) : ?>
|
|
||||||
<div class="user-card-posts mt10">
|
|
||||||
<ul class="no-thumb">
|
|
||||||
<?php foreach ($recent as $rp) : ?>
|
|
||||||
<?php if ($rp instanceof WP_Post) : ?>
|
|
||||||
<li><a class="icon-circle" href="<?php echo esc_url(get_permalink($rp)); ?>"><?php echo esc_html(get_the_title($rp)); ?></a></li>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endforeach; ?>
|
</div>
|
||||||
</ul>
|
<?php if ($bio !== '') : ?>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php if (!empty($recent)) : ?>
|
||||||
|
<div class="user-card-posts mt10">
|
||||||
|
<ul class="no-thumb">
|
||||||
|
<?php foreach ($recent as $rp) : ?>
|
||||||
|
<?php if ($rp instanceof WP_Post) : ?>
|
||||||
|
<li><a class="icon-circle" href="<?php echo esc_url(get_permalink($rp)); ?>"><?php echo esc_html(get_the_title($rp)); ?></a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?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>
|
</div>
|
||||||
</div>
|
<?php
|
||||||
<?php
|
}
|
||||||
}
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if (!function_exists('aksrt_single_render_prevnext')) :
|
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_self) : ?>
|
||||||
<?php if (is_user_logged_in()) : ?>
|
<?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; ?>">
|
<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>
|
</button>
|
||||||
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
|
<?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">
|
<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