修复粉丝/关注 TAB 的用户列表渲染

This commit is contained in:
2026-08-23 14:12:42 +08:00
parent c6c2c0af6d
commit 84321801a6
7 changed files with 109 additions and 72 deletions
+25 -31
View File
@@ -2,6 +2,10 @@
/**
* Public user home — follow tab panel (social following/followers).
*
* Legacy parity: 粉丝/关注用户列表复刻 zib_get_follow_user_list + zib_author_card
* (inc/functions/zib-author.php:395-454, 685-716):子切换「粉丝 | 关注」居中文字链接,
* 列表项走 aksrt_author_minicard(.author-minicard 三列 inline-block 卡片流)。
*
* @package AKSRT
*/
@@ -15,8 +19,8 @@ extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_ext
<div id="panel-follow" class="dashboard-panel<?php echo $active_tab === 'follow' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'follow' ? ' hidden' : ''; ?>>
<?php
$follow_page = max(1, isset($_GET['follow_page']) ? (int) $_GET['follow_page'] : 1);
$follow_sub = isset($_GET['follow_sub']) ? sanitize_key(wp_unslash($_GET['follow_sub'])) : 'following';
$follow_sub = in_array($follow_sub, ['following', 'followers'], true) ? $follow_sub : 'following';
$follow_sub = isset($_GET['follow_sub']) ? sanitize_key(wp_unslash($_GET['follow_sub'])) : 'followers';
$follow_sub = in_array($follow_sub, ['following', 'followers'], true) ? $follow_sub : 'followers';
$follow_instance = class_exists('\AKSRT\User\Follow') ? \AKSRT\User\Follow::get_instance() : null;
$following_count = $follow_instance ? (int) $follow_instance->get_following_count((int) $user_id) : 0;
@@ -30,38 +34,28 @@ extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_ext
$items = is_array($list['items'] ?? null) ? $list['items'] : [];
$total_pages = max(1, (int) ($list['total_pages'] ?? 1));
?>
<div class="uh-follow__subtabs">
<a class="uh-follow__subtab<?php echo $follow_sub === 'following' ? ' is-active' : ''; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'following', 'follow_page' => 1], $home_url)); ?>">
<i class="fa fas fa-user-plus"></i> <?php esc_html_e('关注', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $following_count); ?></span>
</a>
<a class="uh-follow__subtab<?php echo $follow_sub === 'followers' ? ' is-active' : ''; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'followers', 'follow_page' => 1], $home_url)); ?>">
<i class="fa fas fa-users"></i> <?php esc_html_e('粉丝', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $follower_count); ?></span>
</a>
</div>
<ul class="uh-follow__subtabs list-inline splitters">
<li>
<a class="uh-follow__subtab<?php echo $follow_sub === 'followers' ? ' is-active focus-color' : ' muted-color'; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'followers', 'follow_page' => 1], $home_url)); ?>">
<?php esc_html_e('粉丝', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $follower_count); ?></span>
</a>
</li>
<li>
<a class="uh-follow__subtab<?php echo $follow_sub === 'following' ? ' is-active focus-color' : ' muted-color'; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'following', 'follow_page' => 1], $home_url)); ?>">
<?php esc_html_e('关注', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $following_count); ?></span>
</a>
</li>
</ul>
<?php if (!empty($items)) : ?>
<div class="uh-follow__list">
<?php foreach ($items as $row) :
$uid = (int) ($row['user_id'] ?? 0);
$name = (string) ($row['display_name'] ?? '');
$avatar = (string) ($row['avatar_url'] ?? '');
$profile = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($uid) : home_url('/');
?>
<a class="uh-follow__item" href="<?php echo esc_url($profile); ?>">
<span class="uh-follow__avatar">
<?php if ($avatar !== '') : ?>
<img<?php echo aksrt_get_lazy_attr('lazy_avatar', (string) $avatar, 'avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" width="48" height="48">
<?php else : ?>
<?php echo get_avatar($uid, 48); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endif; ?>
</span>
<span class="uh-follow__name"><?php echo esc_html($name !== '' ? $name : sprintf(__('用户 #%d', 'aksrt'), $uid)); ?></span>
</a>
<?php endforeach; ?>
echo aksrt_author_minicard((int) ($row['user_id'] ?? 0)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
endforeach; ?>
</div>
<?php if ($total_pages > 1) : ?>
<div class="uh-follow__pagination">
@@ -81,7 +75,7 @@ extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_ext
$empty_msg = $follow_sub === 'followers'
? __('暂无粉丝', 'aksrt')
: __('暂未关注任何人', 'aksrt');
aksrt_render_profile_empty($svg_empty_post, $empty_msg);
aksrt_render_profile_empty($svg_empty_follow ?? $svg_empty_post ?? '', $empty_msg);
?>
<?php endif; ?>
</div>