From 9b98080daf4340c51150188e99125497a9aec6c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Jul 2026 22:32:03 +0800 Subject: [PATCH] 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. --- assets/js/follow.js | 16 +++- inc/helpers/aksrt-single-render.php | 124 +++++++++++++++----------- templates/parts/single-author-bar.php | 2 +- 3 files changed, 85 insertions(+), 57 deletions(-) diff --git a/assets/js/follow.js b/assets/js/follow.js index 6c7b2c7b..e5b9788f 100644 --- a/assets/js/follow.js +++ b/assets/js/follow.js @@ -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 = '关注该用户'; } diff --git a/inc/helpers/aksrt-single-render.php b/inc/helpers/aksrt-single-render.php index 8a57a170..5572ba7b 100644 --- a/inc/helpers/aksrt-single-render.php +++ b/inc/helpers/aksrt-single-render.php @@ -299,63 +299,79 @@ if (!function_exists('aksrt_single_render_author_card')) : * @param array $ctx Single context. */ function aksrt_single_render_author_card(array $ctx): void { - $author_id = (int) get_the_author_meta('ID'); - if ($author_id <= 0) { - return; - } - $author_url = get_author_posts_url($author_id); - $author_name = get_the_author(); - $bio = trim((string) get_the_author_meta('description')); - $identity_chips = function_exists('aksrt_render_user_identity_chips') - ? aksrt_render_user_identity_chips($author_id, 'card') - : ''; - $avatar = function_exists('aksrt_get_avatar_html') - ? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg']) - : get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']); - $recent = get_posts([ - 'author' => $author_id, - 'post_type' => 'post', - 'post_status' => 'publish', - 'posts_per_page' => 6, - 'orderby' => 'date', - 'order' => 'DESC', - 'no_found_rows' => true, - ]); - ?> -
-
-
-
- -
- -
-
    - - -
  • + $author_id = (int) get_the_author_meta('ID'); + if ($author_id <= 0) { + return; + } + $author_url = get_author_posts_url($author_id); + $author_name = get_the_author(); + $bio = trim((string) get_the_author_meta('description')); + $identity_chips = function_exists('aksrt_render_user_identity_chips') + ? aksrt_render_user_identity_chips($author_id, 'card') + : ''; + $avatar = function_exists('aksrt_get_avatar_html') + ? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg']) + : get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']); + $recent = get_posts([ + 'author' => $author_id, + 'post_type' => 'post', + 'post_status' => 'publish', + 'posts_per_page' => 6, + 'orderby' => 'date', + '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()); + ?> +
    +
    +
    +
    +
+
+ +
+ +
+ + + + + + + + +
+
- + +
+
    + + +
  • + + +
+
+ +
+ + - -