fix(single): restore author follow controls

This commit is contained in:
2026-08-31 13:12:45 +08:00
parent 71444b139a
commit 8eb62e712b
19 changed files with 261 additions and 615 deletions
+40 -109
View File
@@ -1,14 +1,10 @@
<?php
/**
* Shared author info bar for single post content (legacy article-avatar / user-info).
* Article header author bar.
*
* Contract: get_template_part(..., null, $args)
* show_actions bool Follow / PM buttons + meta row
* show_bio bool Append bio after time
* show_time bool Relative publish/update time (default true)
* meta_html string Prebuilt legacy single-metabox HTML
* meta_items array Legacy text meta items (fallback)
* extra_class string
* show_time bool Relative publish/update time (default true)
* meta_html string Prebuilt single-metabox HTML
*
* @package AKSRT
*/
@@ -16,78 +12,61 @@
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
$extra_class = (string) ($args['extra_class'] ?? '');
$show_actions = !empty($args['show_actions']);
$show_bio = !empty($args['show_bio']);
$show_time = !array_key_exists('show_time', $args) || !empty($args['show_time']);
$meta_html = (string) ($args['meta_html'] ?? '');
$meta_items = is_array($args['meta_items'] ?? null) ? array_values(array_filter($args['meta_items'], static function ($meta_item) {
if (is_array($meta_item)) {
return !empty($meta_item['text']);
}
return is_string($meta_item) && $meta_item !== '';
})) : [];
$author_id = (int) get_the_author_meta('ID');
$author_name = get_the_author();
$author_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id);
$modified_ts = (int) get_the_modified_time('U');
$published_ts = (int) get_the_time('U');
$now = (int) current_time('timestamp');
$use_modified = $modified_ts > $published_ts;
$rel_base = $use_modified ? $modified_ts : $published_ts;
$rel_label = $use_modified ? __('更新', 'aksrt') : __('发布', 'aksrt');
$abs_fmt = $use_modified
? sprintf(__('%s更新', 'aksrt'), get_the_modified_time('Y年m月d日 H:i'))
: sprintf(__('%s发布', 'aksrt'), get_the_time('Y年m月d日 H:i'));
$time_text = human_time_diff($rel_base, $now) . $rel_label;
$classes = trim('article-avatar ' . $extra_class);
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
// Identity: aksrt_get_user_name is the canonical renderer (legacy order).
$name_html = '';
if (function_exists('aksrt_get_user_name')) {
$name_html = aksrt_get_user_name([
'id' => $author_id,
'class' => 'name flex ac flex1',
'name_class' => '',
'vip' => true,
'medal' => true,
'auth' => true,
'level' => true,
'follow' => false,
]);
}
$time_text = human_time_diff($rel_base, (int) current_time('timestamp')) . $rel_label;
$description = function_exists('aksrt_get_user_description')
? aksrt_get_user_description($author_id)
: trim((string) get_the_author_meta('description'));
$name_html = aksrt_get_user_name([
'id' => $author_id,
'class' => 'name flex ac flex1',
'name_class' => '',
'vip' => true,
'medal' => true,
'auth' => true,
'level' => true,
'follow' => false,
]);
$follow_html = aksrt_get_user_follow('px12-sm ml10 follow but c-red', $author_id);
$reward_button = get_current_user_id() !== $author_id && function_exists('aksrt_get_rewards_button')
? aksrt_get_rewards_button($author_id, 'ml6 but c-yellow px12-sm', get_the_ID())
: '';
?>
<div class="<?php echo esc_attr($classes); ?>">
<div class="article-avatar">
<div class="user-info flex ac article-avatar">
<a href="<?php echo esc_url($author_url); ?>">
<span class="avatar-img">
<a href="<?php echo esc_url($author_url); ?>">
<span class="avatar-img">
<?php if (function_exists('aksrt_get_avatar_html')) : ?>
<?php echo aksrt_get_avatar_html($author_id, 42, ['class' => 'avatar avatar-id-' . $author_id]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo get_avatar($author_id, 42, '', esc_attr($author_name), ['class' => 'avatar avatar-id-' . $author_id]); ?>
<?php endif; ?>
</span>
</a>
</span>
</a>
<div class="user-right flex flex1 ac jsb ml10">
<div class="flex1">
<?php if ($name_html !== '') : ?>
<?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<span class="name flex ac flex1">
<a class="display-name text-ellipsis" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
</span>
<?php endif; ?>
<?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="px12-sm muted-2-color text-ellipsis">
<?php if ($show_time) : ?>
<span class="icon-circle" title="<?php echo esc_attr($abs_fmt); ?>" data-toggle="tooltip"><?php echo esc_html($time_text); ?></span>
<?php elseif ($description !== '') : ?>
<span class="icon-circle"><?php echo esc_html($description); ?></span>
<?php endif; ?>
<?php
// Article detail IP 归属地 (extension display: post).
$post_city = function_exists('aksrt_get_post_author_city_badge_html')
? aksrt_get_post_author_city_badge_html($author_id, 'badg badg-sm')
: '';
@@ -95,68 +74,20 @@ if (function_exists('aksrt_get_user_name')) {
echo $post_city; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
<?php if ($show_bio) : ?>
<?php $bio = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($author_id) : trim((string) get_the_author_meta('description')); ?>
<?php if ($bio !== '') : ?>
<span class="icon-circle"><?php echo esc_html($bio); ?></span>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<?php if ($show_actions) : ?>
<div class="flex0 user-action">
<?php if (!$is_self) : ?>
<?php if (is_user_logged_in()) : ?>
<?php
// 服务端直接输出真实关注状态(legacy parity: zib_get_user_follow 恒渲染当前态)。
$is_following = class_exists('\AKSRT\User\Follow') && \AKSRT\User\Follow::get_instance()->is_following(get_current_user_id(), $author_id);
$follow_label = $is_following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
$follow_title = $is_following ? __('点击取消关注', 'aksrt') : __('关注该用户', 'aksrt');
?>
<button type="button" class="px12-sm ml10 follow c-red<?php echo $is_following ? ' is-following' : ''; ?>" data-aksrt-follow="<?php echo (int) $author_id; ?>" title="<?php echo esc_attr($follow_title); ?>">
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <span><?php echo esc_html($follow_label); ?></span>
</button>
<?php
$reward_button = function_exists('aksrt_get_rewards_button')
? aksrt_get_rewards_button($author_id, 'ml6 but c-yellow px12-sm', get_the_ID())
: '';
if ($reward_button !== '') {
echo $reward_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
aksrt_render_rewards_modal_for_user($author_id, get_the_ID());
}
?>
<?php else : ?>
<a href="<?php echo esc_url($login_url); ?>" class="px12-sm ml10 follow c-red">
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <?php esc_html_e('关注', 'aksrt'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="flex0 user-action">
<?php echo $follow_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ($reward_button !== '') : ?>
<?php echo $reward_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php aksrt_render_rewards_modal_for_user($author_id, get_the_ID()); ?>
<?php endif; ?>
</div>
</div>
</div>
<?php if ($show_actions) : ?>
<div class="single-meta-row">
<i class="line-form-line" aria-hidden="true"></i>
<?php if ($meta_html !== '') : ?>
<?php echo $meta_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php elseif (!empty($meta_items)) : ?>
<div class="flex ac single-metabox">
<div class="post-metas">
<?php foreach ($meta_items as $meta_item) : ?>
<?php
$meta_text = is_array($meta_item) ? (string) ($meta_item['text'] ?? '') : (string) $meta_item;
$meta_icon = is_array($meta_item) ? (string) ($meta_item['icon'] ?? '') : '';
if ($meta_text === '') {
continue;
}
?>
<span class="item meta-view"><?php if ($meta_icon !== '') : ?><i class="<?php echo esc_attr($meta_icon); ?>" aria-hidden="true"></i> <?php endif; ?><?php echo esc_html($meta_text); ?></span>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="single-meta-row">
<i class="line-form-line" aria-hidden="true"></i>
<?php echo $meta_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>
+2 -17
View File
@@ -156,23 +156,8 @@ $unread_count = $is_own ? aksrt_get_user_unread_notification_count($user_id) : 0
</a>
<?php endif; ?>
<?php else : ?>
<?php if ($show_follow) : ?>
<?php if (is_user_logged_in()) : ?>
<?php
$hero_following = class_exists('\AKSRT\User\Follow')
? \AKSRT\User\Follow::get_instance()->is_following(get_current_user_id(), (int) $user_id)
: false;
?>
<button type="button" class="btn-outline btn-sm aksrt-author-hero__follow-btn<?php echo $hero_following ? ' is-following' : ''; ?>" data-aksrt-follow="<?php echo (int) $user_id; ?>" title="<?php echo $hero_following ? esc_attr__('点击取消关注', 'aksrt') : esc_attr__('关注该用户', 'aksrt'); ?>">
<i class="fa fas fa-heart" aria-hidden="true"></i>
<span><?php echo esc_html($hero_following ? __('已关注', 'aksrt') : __('关注', 'aksrt')); ?></span>
</button>
<?php else : ?>
<a href="<?php echo esc_url(aksrt_get_login_url($home_url)); ?>" class="btn-outline btn-sm aksrt-author-hero__follow-btn">
<i class="fa fas fa-heart" aria-hidden="true"></i>
<span><?php esc_html_e('登录后关注', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php if ($show_follow) : ?>
<?php echo aksrt_get_user_follow('btn-outline btn-sm aksrt-author-hero__follow-btn', (int) $user_id, null, null, __('登录后关注', 'aksrt')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endif; ?>
<?php endif; ?>