fix(users): keep management inside center
This commit is contained in:
1 parent
c3bfd12c69
commit
ce2b266890
44 files changed
+194
-2584
No files matched your search
@@ -142,6 +142,8 @@ if (!function_exists('aksrt_capture_user_center_view')) {
|
||||
'level' => 'level',
|
||||
'profile' => 'form',
|
||||
'creator' => 'creator',
|
||||
'posts' => 'posts',
|
||||
'follow' => 'follow',
|
||||
'comments' => 'comments',
|
||||
'favorites' => 'favorites',
|
||||
'credits' => 'credits',
|
||||
@@ -173,7 +175,7 @@ if (!function_exists('aksrt_capture_user_center_panel')) {
|
||||
* Capture a built-in or registered user-center panel body.
|
||||
*/
|
||||
function aksrt_capture_user_center_panel(string $tab_key, array $tab, array $context): string {
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
if (in_array($tab_key, $built_in_tabs, true)) {
|
||||
return aksrt_capture_user_center_view($tab_key, $context);
|
||||
}
|
||||
@@ -446,6 +448,26 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
|
||||
$follower_count = class_exists('\AKSRT\User\Follow')
|
||||
? \AKSRT\User\Follow::get_instance()->get_follower_count($user_id)
|
||||
: 0;
|
||||
$following_count = class_exists('\AKSRT\User\Follow')
|
||||
? \AKSRT\User\Follow::get_instance()->get_following_count($user_id)
|
||||
: 0;
|
||||
$allowed_post_statuses = ['publish', 'draft', 'pending', 'private'];
|
||||
$post_status_filter = isset($_GET['post_status']) ? sanitize_key(wp_unslash($_GET['post_status'])) : 'publish';
|
||||
if (!in_array($post_status_filter, array_merge($allowed_post_statuses, ['all']), true)) {
|
||||
$post_status_filter = 'publish';
|
||||
}
|
||||
$user_status_counts = [];
|
||||
foreach ($allowed_post_statuses as $status) {
|
||||
$status_query = new WP_Query([
|
||||
'author' => $user_id,
|
||||
'post_type' => 'post',
|
||||
'post_status' => $status,
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => false,
|
||||
]);
|
||||
$user_status_counts[$status] = (int) $status_query->found_posts;
|
||||
}
|
||||
|
||||
$svgs = aksrt_user_center_empty_svgs();
|
||||
require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php';
|
||||
@@ -478,6 +500,7 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
|
||||
'favorite_post_ids' => $favorite_post_ids,
|
||||
'favorite_count' => $favorite_count,
|
||||
'follower_count' => $follower_count,
|
||||
'following_count' => $following_count,
|
||||
'user_contacts' => $user_contacts,
|
||||
'profile_signals' => $dashboard['profile_signals'] ?? [],
|
||||
'user_background_url' => $user_background_url,
|
||||
@@ -487,13 +510,16 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
|
||||
'messages_url' => $messages_enabled && function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '',
|
||||
'revenue_url' => $revenue_url,
|
||||
'per_page' => 10,
|
||||
'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1),
|
||||
'post_status_filter' => $post_status_filter,
|
||||
'user_status_counts' => $user_status_counts,
|
||||
'new_post_url' => function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : '',
|
||||
'svg_empty_post' => $svgs['post'],
|
||||
'comments_page' => max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1),
|
||||
'favorites_page' => max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1),
|
||||
'svg_empty_comment' => $svgs['comment'],
|
||||
'svg_empty_favorite' => $svgs['favorite'],
|
||||
'orders_url' => function_exists('aksrt_get_user_center_tab_url')
|
||||
? aksrt_get_user_center_tab_url('orders')
|
||||
: (function_exists('aksrt_get_orders_page_url') ? aksrt_get_orders_page_url() : ''),
|
||||
'orders_url' => isset($tabs['tabs']['orders']) ? aksrt_get_user_center_tab_url('orders') : '',
|
||||
'show_vip' => !empty($vip_settings['enabled']),
|
||||
'show_credit_tabs' => $show_credit_tabs,
|
||||
'affiliate_enabled' => $show_credit_tabs && !empty($affiliate_settings['enabled']),
|
||||
|
||||
@@ -99,7 +99,7 @@ if (!function_exists('aksrt_get_header_nav_context')) :
|
||||
? (int) aksrt_get_user_unread_notification_count($user_id)
|
||||
: 0,
|
||||
'messages_url' => function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '',
|
||||
'orders_url' => function_exists('aksrt_get_orders_page_url') ? aksrt_get_orders_page_url() : '',
|
||||
'orders_url' => function_exists('aksrt_get_user_center_tab_url') ? aksrt_get_user_center_tab_url('orders') : '',
|
||||
'publish_url' => function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : admin_url('post-new.php'),
|
||||
'theme_settings_url' => function_exists('aksrt_get_admin_settings_url')
|
||||
? aksrt_get_admin_settings_url('')
|
||||
|
||||
@@ -57,7 +57,12 @@ if ($q->have_posts()) :
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
aksrt_render_profile_pagination((int) $q->max_num_pages, $posts_page, 'posts_page');
|
||||
aksrt_render_profile_pagination(
|
||||
(int) $q->max_num_pages,
|
||||
$posts_page,
|
||||
'posts_page',
|
||||
add_query_arg('post_status', $post_status_filter, aksrt_get_user_center_tab_url('posts'))
|
||||
);
|
||||
wp_reset_postdata();
|
||||
else :
|
||||
aksrt_render_profile_empty(
|
||||
|
||||
@@ -26,10 +26,9 @@ $status_chip_defs = [
|
||||
continue;
|
||||
}
|
||||
$chip_url = add_query_arg([
|
||||
'tab' => 'posts',
|
||||
'post_status' => $status_key,
|
||||
'posts_page' => 1,
|
||||
], remove_query_arg(['posts_page']));
|
||||
], aksrt_get_user_center_tab_url('posts'));
|
||||
$chip_active = ($post_status_filter === $status_key);
|
||||
?>
|
||||
<a href="<?php echo esc_url($chip_url); ?>" class="profile-status-chip<?php echo $chip_active ? ' is-active' : ''; ?>" role="tab" aria-selected="<?php echo $chip_active ? 'true' : 'false'; ?>">
|
||||
|
||||
@@ -44,10 +44,7 @@ if ($show_credits) {
|
||||
|
||||
// Tabbed ledgers (Zibll record tabs).
|
||||
if ($show_wallet || $show_credits) :
|
||||
$active_record = isset($_GET['asset_tab']) ? sanitize_key(wp_unslash($_GET['asset_tab'])) : '';
|
||||
if ($active_record === '' || !in_array($active_record, ['balance', 'points', 'points_free', 'points_date'], true)) {
|
||||
$active_record = $show_wallet ? 'balance' : 'points';
|
||||
}
|
||||
$active_record = $show_wallet ? 'balance' : 'points';
|
||||
$show_tasks = $show_credits && class_exists('\AKSRT\Credits\PointsFree') && \AKSRT\Credits\PointsFree::enabled();
|
||||
?>
|
||||
<div class="uc-asset-tabs">
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Private follow management panel.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
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('\\AKSRT\\User\\Follow') ? \AKSRT\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];
|
||||
$messages_enabled = !empty($messages_url);
|
||||
?>
|
||||
<div class="widget-card uc-follow-management">
|
||||
<div class="profile-list-header">
|
||||
<div>
|
||||
<h2 class="widget-title widget-title--inline"><?php esc_html_e('粉丝与关注', 'aksrt'); ?></h2>
|
||||
<p class="muted-2-color em09"><?php esc_html_e('查看谁关注了你,并管理你关注的作者。', 'aksrt'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="profile-status-filter" role="tablist" aria-label="<?php esc_attr_e('关注关系筛选', 'aksrt'); ?>">
|
||||
<?php foreach (['followers' => __('粉丝', 'aksrt'), 'following' => __('我关注的', 'aksrt')] as $key => $label) :
|
||||
$url = add_query_arg(['follow_list' => $key, 'follow_page' => 1], aksrt_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('aksrt_get_user_home_url') ? aksrt_get_user_home_url($member_id) : '';
|
||||
$message_url = $messages_enabled ? add_query_arg('msg_type', 'conversation', $messages_url) : '';
|
||||
?>
|
||||
<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', 'aksrt'), 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('主页', 'aksrt'); ?></a>
|
||||
<?php if ($messages_enabled) : ?><a class="btn-ghost btn-sm" href="<?php echo esc_url($message_url); ?>"><?php esc_html_e('私信', 'aksrt'); ?></a><?php endif; ?>
|
||||
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm is-following" data-aksrt-follow="<?php echo esc_attr((string) $member_id); ?>"><i class="fas fa-heart" aria-hidden="true"></i><span><?php esc_html_e('已关注', 'aksrt'); ?></span></button><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php aksrt_render_profile_pagination(
|
||||
(int) ($result['total_pages'] ?? 1),
|
||||
$page,
|
||||
'follow_page',
|
||||
add_query_arg('follow_list', $active_list, aksrt_get_user_center_tab_url('follow'))
|
||||
); ?>
|
||||
<?php else : ?>
|
||||
<?php aksrt_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' ? __('还没有粉丝', 'aksrt') : __('还没有关注任何作者', 'aksrt')); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -28,7 +28,7 @@ $points = (float) ($credit_balance ?? 0);
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_credits) : ?>
|
||||
<a class="uc-summary-card uc-summary-card--points" href="<?php echo esc_url(add_query_arg('asset_tab', 'points', $assets_url)); ?>" data-tab="credits">
|
||||
<a class="uc-summary-card uc-summary-card--points" href="<?php echo esc_url($assets_url); ?>" data-tab="credits">
|
||||
<span class="uc-summary-card__head"><?php echo esc_html((string) ($currency_name ?? __('积分', 'aksrt'))); ?><i class="fas fa-angle-right" aria-hidden="true"></i></span>
|
||||
<span class="uc-summary-card__body">
|
||||
<strong><?php echo esc_html(function_exists('aksrt_format_credits') ? aksrt_format_credits((int) $points) : number_format_i18n((int) $points)); ?></strong>
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$public_home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($target_user ?? null) : '';
|
||||
$stats = [
|
||||
[
|
||||
'label' => __('文章', 'aksrt'),
|
||||
'value' => (int) ($post_count ?? 0),
|
||||
'url' => isset($dashboard_tabs['posts']) ? aksrt_get_user_center_tab_url('posts') : $public_home_url,
|
||||
'tab' => isset($dashboard_tabs['posts']) ? 'posts' : '',
|
||||
'url' => aksrt_get_user_center_tab_url('posts'),
|
||||
'tab' => 'posts',
|
||||
],
|
||||
[
|
||||
'label' => __('评论', 'aksrt'),
|
||||
@@ -30,7 +29,8 @@ $stats = [
|
||||
[
|
||||
'label' => __('粉丝', 'aksrt'),
|
||||
'value' => (int) ($follower_count ?? 0),
|
||||
'url' => $public_home_url !== '' ? add_query_arg(['tab' => 'follow', 'follow_sub' => 'followers'], $public_home_url) : '',
|
||||
'url' => aksrt_get_user_center_tab_url('follow'),
|
||||
'tab' => 'follow',
|
||||
],
|
||||
];
|
||||
?>
|
||||
|
||||
Reference in new issue
Block a user