- guests get the sign-in trigger instead of a redirect to the login page, for both follow and wallet reward controls - follow requests swap the label for an inline loader and block a second submit; the followed state uses the .actived hook - follower counts sync through data-follow-count on the user homepage (the previous selector matched nothing) and only for the viewed profile - reward button uses the secondary action colour; the reward template is only rendered for signed-in visitors - drop the unused author-hero aria-disabled rule and stale wording in the touched comments Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
65 lines
4.1 KiB
PHP
65 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* Private follow management panel.
|
|
*
|
|
* @package Jio
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
|
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
|
|
|
$follow = class_exists('\\Jio\\User\\Follow') ? \Jio\User\Follow::get_instance() : null;
|
|
$active_list = isset($_GET['follow_list']) ? sanitize_key(wp_unslash($_GET['follow_list'])) : 'followers';
|
|
if (!in_array($active_list, ['followers', 'following'], true)) {
|
|
$active_list = 'followers';
|
|
}
|
|
$page = max(1, isset($_GET['follow_page']) ? (int) $_GET['follow_page'] : 1);
|
|
$result = $follow
|
|
? ($active_list === 'following' ? $follow->get_following((int) $user_id, $page, 20) : $follow->get_followers((int) $user_id, $page, 20))
|
|
: ['items' => [], 'total_pages' => 1];
|
|
?>
|
|
<div class="widget-card uc-follow-management">
|
|
<div class="profile-list-header">
|
|
<div>
|
|
<h2 class="widget-title widget-title--inline"><?php esc_html_e('粉丝与关注', 'jio'); ?></h2>
|
|
<p class="muted-2-color em09"><?php esc_html_e('查看谁关注了你,并管理你关注的作者。', 'jio'); ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="profile-status-filter" role="tablist" aria-label="<?php esc_attr_e('关注关系筛选', 'jio'); ?>">
|
|
<?php foreach (['followers' => __('粉丝', 'jio'), 'following' => __('我关注的', 'jio')] as $key => $label) :
|
|
$url = add_query_arg(['follow_list' => $key, 'follow_page' => 1], jio_get_user_center_tab_url('follow'));
|
|
?>
|
|
<a class="profile-status-chip<?php echo $active_list === $key ? ' is-active' : ''; ?>" href="<?php echo esc_url($url); ?>" data-tab="follow" role="tab" aria-selected="<?php echo $active_list === $key ? 'true' : 'false'; ?>">
|
|
<?php echo esc_html($label); ?> <span class="profile-status-chip__count"><?php echo esc_html(number_format_i18n((int) ($key === 'followers' ? $follower_count : $following_count))); ?></span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if (!empty($result['items'])) : ?>
|
|
<div class="uc-follow-management__list">
|
|
<?php foreach ($result['items'] as $item) :
|
|
$member_id = (int) ($item['user_id'] ?? 0);
|
|
$home_url = function_exists('jio_get_user_home_url') ? jio_get_user_home_url($member_id) : '';
|
|
?>
|
|
<div class="uc-follow-management__item" data-follow-user="<?php echo esc_attr((string) $member_id); ?>">
|
|
<a href="<?php echo esc_url($home_url); ?>" class="uc-follow-management__avatar"><?php echo get_avatar($member_id, 48, '', (string) ($item['display_name'] ?? '')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></a>
|
|
<div class="uc-follow-management__identity"><a href="<?php echo esc_url($home_url); ?>"><?php echo esc_html((string) ($item['display_name'] ?? '')); ?></a><span><?php echo esc_html(sprintf(__('关注于 %s', 'jio'), get_date_from_gmt((string) ($item['created_at'] ?? ''), get_option('date_format')))); ?></span></div>
|
|
<div class="uc-follow-management__actions">
|
|
<a class="btn-ghost btn-sm" href="<?php echo esc_url($home_url); ?>"><?php esc_html_e('主页', 'jio'); ?></a>
|
|
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm actived" data-jio-follow="<?php echo esc_attr((string) $member_id); ?>" data-jio-follow-text="<?php esc_attr_e('关注', 'jio'); ?>" data-jio-follow-ok="<?php esc_attr_e('已关注', 'jio'); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span data-jio-follow-label><?php esc_html_e('已关注', 'jio'); ?></span></button><?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php jio_render_profile_pagination(
|
|
(int) ($result['total_pages'] ?? 1),
|
|
$page,
|
|
'follow_page',
|
|
add_query_arg('follow_list', $active_list, jio_get_user_center_tab_url('follow'))
|
|
); ?>
|
|
<?php else : ?>
|
|
<?php jio_render_profile_empty('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></svg>', $active_list === 'followers' ? __('还没有粉丝', 'jio') : __('还没有关注任何作者', 'jio')); ?>
|
|
<?php endif; ?>
|
|
</div>
|