feat(widgets): author card follow button

Add data-aksrt-follow CTA on post author sidebar card for non-self users.
This commit is contained in:
2026-07-19 01:40:45 +08:00
parent c5a0c57697
commit 6bcb16fb8a
2 changed files with 19 additions and 0 deletions
+7
View File
@@ -94,6 +94,13 @@ class WidgetAuthorCard extends \WP_Widget {
echo '<span><b>' . esc_html((string) $followers) . '</b>' . esc_html__('粉丝', 'aksrt') . '</span>';
echo '</div>';
}
$cuid = get_current_user_id();
$show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']);
if ($show_follow && $cuid > 0 && $cuid !== $author_id && class_exists('\AKSRT\User\Follow')) {
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $author_id);
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
echo '<button type="button" class="aksrt-author-card__btn aksrt-author-card__follow' . ($following ? ' is-following' : '') . '" data-aksrt-follow="' . (int) $author_id . '">' . esc_html($label) . '</button>';
}
echo '<a class="aksrt-author-card__btn" href="' . esc_url($home) . '">' . esc_html__('查看主页', 'aksrt') . '</a>';
echo '</div></div>';