用户主页再减层:抽出 page context helper 并清理失效 profile CSS

page-user-home 收成薄壳,tab/统计/分页上下文迁入 aksrt_get_user_home_page_context;同步删除 profile-public-contacts 等失效样式,并让 .user-center 宽度规则落到现用 aksrt-profile 壳层。
This commit is contained in:
2026-07-10 22:01:09 +08:00
parent 9f08c9337a
commit 05ee28ed5b
8 changed files with 183 additions and 193 deletions
-22
View File
@@ -246,21 +246,6 @@
padding-top: 68px; padding-top: 68px;
} }
/* 公开主页联系方式(沿用旧选择器) */
.profile-public-contacts {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 10px;
}
.profile-public-contacts .social-icon-link {
color: var(--color-ink);
background: var(--color-line);
}
.profile-public-contacts .social-icon-link:hover {
color: var(--color-ink);
background: var(--color-ink-4);
}
/* 公开主页响应式 */ /* 公开主页响应式 */
@media (max-width: 767px) { @media (max-width: 767px) {
@@ -292,9 +277,6 @@
margin-top: 4px; margin-top: 4px;
} }
.profile-public-contacts {
justify-content: center;
}
} }
@media (max-width: 480px) { @media (max-width: 480px) {
@@ -317,10 +299,6 @@
} }
} }
/* ==================== 页面标题 ==================== */
.profile-page-title {
margin-bottom: 20px;
}
/* ==================== Dashboard Tabs 计数徽章 ==================== */ /* ==================== Dashboard Tabs 计数徽章 ==================== */
.dashboard-tabs__count { .dashboard-tabs__count {
+2 -1
View File
@@ -15,7 +15,8 @@
margin: 0 auto; margin: 0 auto;
} }
.user-center { .user-center,
.aksrt-profile.content-shell {
width: 100%; width: 100%;
padding: 0 0 40px; padding: 0 0 40px;
} }
+2 -1
View File
@@ -195,7 +195,8 @@
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.user-center { .user-center,
.aksrt-profile.content-shell {
padding: 0 12px 32px; padding: 0 12px 32px;
} }
-22
View File
@@ -387,28 +387,6 @@
gap: 18px; gap: 18px;
} }
/* 联系方式增强 */
.aksrt-user-home .profile-public-contacts .social-icon-link {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 6px 12px;
border-radius: 100px;
font-size: 13px;
font-weight: 500;
color: var(--color-ink-2);
background: var(--surface-2);
border: 1px solid var(--color-line-soft, rgba(0,0,0,0.06));
text-decoration: none;
transition: all 0.2s ease;
}
.aksrt-user-home .profile-public-contacts .social-icon-link:hover {
color: var(--color-primary);
background: var(--color-primary-soft);
border-color: var(--color-primary);
transform: translateY(-1px);
}
.aksrt-user-home .aksrt-user-home__layout { .aksrt-user-home .aksrt-user-home__layout {
align-items: start; align-items: start;
+2
View File
@@ -44,8 +44,10 @@ require_once AKSRT_DIR . '/inc/helpers/class-aksrt-nav-walker.php';
require_once AKSRT_DIR . '/inc/helpers/aksrt-transactions.php'; require_once AKSRT_DIR . '/inc/helpers/aksrt-transactions.php';
require_once AKSRT_DIR . '/inc/helpers/aksrt-user-dashboard.php'; require_once AKSRT_DIR . '/inc/helpers/aksrt-user-dashboard.php';
require_once AKSRT_DIR . '/inc/helpers/aksrt-user-center.php'; require_once AKSRT_DIR . '/inc/helpers/aksrt-user-center.php';
require_once AKSRT_DIR . '/inc/helpers/aksrt-user-home.php';
require_once AKSRT_DIR . '/inc/helpers/aksrt-shortcodes.php'; require_once AKSRT_DIR . '/inc/helpers/aksrt-shortcodes.php';
// ============================================================ // ============================================================
// 阶段2:加载类文件(settings 必须在 admin 之前) // 阶段2:加载类文件(settings 必须在 admin 之前)
// ============================================================ // ============================================================
+156
View File
@@ -0,0 +1,156 @@
<?php
/**
* Public user-home template context builder.
*
* Keeps page-user-home.php as a thin shell that only mounts parts.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_get_user_home_page_context')) {
/**
* Build the render context for the public user homepage shell.
*
* @param WP_User $user Target user.
* @return array<string, mixed>
*/
function aksrt_get_user_home_page_context(WP_User $user): array {
$user_id = (int) $user->ID;
$dashboard = function_exists('aksrt_get_user_dashboard_view')
? aksrt_get_user_dashboard_view($user_id, ['viewer_id' => get_current_user_id()])
: [];
$is_own_profile = !empty($dashboard['is_own_profile']);
$user_home_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_user_home_settings()
: [
'tabs' => ['posts', 'comments', 'favorites'],
'sidebar' => true,
'cover' => true,
'follow' => true,
'posts_per_page' => 10,
];
$user_center_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_user_center_settings()
: ['social_links' => true];
$post_count = (int) ($dashboard['post_count'] ?? 0);
$comment_count = (int) ($dashboard['comment_count'] ?? 0);
$favorite_post_ids = $dashboard['favorite_post_ids'] ?? [];
$favorite_count = (int) ($dashboard['favorite_count'] ?? 0);
$user_contacts = $dashboard['user_contacts'] ?? [];
$per_page = max(1, (int) ($user_home_settings['posts_per_page'] ?? 10));
$credits_enabled = !empty($dashboard['credits_enabled']);
$credit_balance = $dashboard['credit_balance'] ?? 0.0;
$currency_name = $dashboard['currency_name'] ?? __('积分', 'aksrt');
$user_home_manager = class_exists('AKSRT_User_Home') ? AKSRT_User_Home::get_instance() : null;
$visible_tabs = $user_home_manager ? $user_home_manager->get_visible_tabs($is_own_profile) : [];
$enabled_tabs = array_keys($visible_tabs);
if (empty($enabled_tabs)) {
$enabled_tabs = ['posts', 'comments', 'favorites'];
}
// Apply admin-configured display order.
$order = $user_home_settings['tabs_order'] ?? [];
$ordered = [];
foreach ((array) $order as $tab_key) {
if (in_array($tab_key, $enabled_tabs, true)) {
$ordered[] = $tab_key;
}
}
foreach ($enabled_tabs as $tab_key) {
if (!in_array($tab_key, $ordered, true)) {
$ordered[] = $tab_key;
}
}
$enabled_tabs = $ordered;
$pc_hide = $user_home_settings['tabs_pc_hide'] ?? [];
$mobile_hide = $user_home_settings['tabs_mobile_hide'] ?? [];
$enabled_tabs_pc = array_values(array_diff($enabled_tabs, (array) $pc_hide));
$enabled_tabs_mobile = array_values(array_diff($enabled_tabs, (array) $mobile_hide));
$is_mobile = function_exists('wp_is_mobile') && wp_is_mobile();
$display_tabs = $is_mobile ? $enabled_tabs_mobile : $enabled_tabs_pc;
$default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0];
$forum_instance = class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
$forum_stats = $forum_instance ? $forum_instance->get_user_forum_stats($user_id) : [];
$forum_topic_count = (int) ($forum_stats['topic_count'] ?? 0);
$forum_followed_count = (int) ($forum_stats['followed_plate_count'] ?? 0);
$tab_counts = [
'posts' => $post_count,
'comments' => $comment_count,
'favorites' => $favorite_count,
'credits' => $credits_enabled && $is_own_profile ? (int) round((float) $credit_balance) : 0,
'product' => 0,
'plate' => 0,
'forum' => $forum_topic_count,
'follow' => $forum_followed_count,
];
$tab_labels = [
'posts' => __('文章', 'aksrt'),
'comments' => __('评论', 'aksrt'),
'favorites' => __('收藏', 'aksrt'),
'credits' => sprintf(__('我的%s', 'aksrt'), $currency_name),
'product' => __('商品', 'aksrt'),
'plate' => __('圈子', 'aksrt'),
'forum' => __('论坛', 'aksrt'),
'follow' => __('关注', 'aksrt'),
];
foreach ($visible_tabs as $tab_key => $tab_config) {
if (!empty($tab_config['label'])) {
$tab_labels[$tab_key] = (string) $tab_config['label'];
}
}
$active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $default_tab;
if (!in_array($active_tab, $enabled_tabs, true)) {
$active_tab = $default_tab;
}
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
return [
'user' => $user,
'user_id' => $user_id,
'dashboard' => $dashboard,
'is_own_profile' => $is_own_profile,
'user_home_settings' => $user_home_settings,
'user_center_settings' => $user_center_settings,
'user_contacts' => $user_contacts,
'post_count' => $post_count,
'comment_count' => $comment_count,
'favorite_post_ids' => $favorite_post_ids,
'favorite_count' => $favorite_count,
'per_page' => $per_page,
'credits_enabled' => $credits_enabled,
'credit_balance' => $credit_balance,
'currency_name' => $currency_name,
'enabled_tabs' => $enabled_tabs,
'tabs_pc_hide' => (array) $pc_hide,
'tabs_mobile_hide' => (array) $mobile_hide,
'default_tab' => $default_tab,
'active_tab' => $active_tab,
'tab_counts' => $tab_counts,
'tab_labels' => $tab_labels,
'forum_instance' => $forum_instance,
'forum_stats' => $forum_stats,
'forum_topic_count' => $forum_topic_count,
'home_url' => $home_url,
'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1),
'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_post' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M9 13h6M9 17h6M9 9h1"/></svg>',
'svg_empty_comment' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
'svg_empty_favorite' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
];
}
}
+20 -147
View File
@@ -2,6 +2,8 @@
/** /**
* Public user homepage template. * Public user homepage template.
* *
* Thin shell: resolve user → build context → mount parts.
*
* @package AKSRT * @package AKSRT
*/ */
@@ -12,124 +14,21 @@ get_header();
$target_user_nicename = get_query_var('user_nicename'); $target_user_nicename = get_query_var('user_nicename');
$user = $target_user_nicename ? get_user_by('slug', $target_user_nicename) : null; $user = $target_user_nicename ? get_user_by('slug', $target_user_nicename) : null;
if (!$user) { if (!$user instanceof WP_User) {
wp_safe_redirect(home_url('/')); wp_safe_redirect(home_url('/'));
exit; exit;
} }
$user_id = (int) $user->ID; if (!function_exists('aksrt_get_user_home_page_context')) {
require_once AKSRT_DIR . '/inc/helpers/aksrt-user-home.php';
// 数据聚合:复用共享 helper
$dashboard = function_exists('aksrt_get_user_dashboard_view')
? aksrt_get_user_dashboard_view($user_id, ['viewer_id' => get_current_user_id()])
: [];
$is_own_profile = !empty($dashboard['is_own_profile']);
$user_home_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_user_home_settings()
: [
'tabs' => ['posts', 'comments', 'favorites'],
'sidebar' => true,
'cover' => true,
'follow' => true,
'posts_per_page' => 10,
];
$post_count = (int) ($dashboard['post_count'] ?? 0);
$comment_count = (int) ($dashboard['comment_count'] ?? 0);
$favorite_post_ids = $dashboard['favorite_post_ids'] ?? [];
$favorite_count = (int) ($dashboard['favorite_count'] ?? 0);
$user_contacts = $dashboard['user_contacts'] ?? [];
$user_center_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_user_center_settings()
: ['social_links' => true];
$per_page = (int) $user_home_settings['posts_per_page'];
$credits_enabled = !empty($dashboard['credits_enabled']);
$credit_balance = $dashboard['credit_balance'] ?? 0.0;
$currency_name = $dashboard['currency_name'] ?? __('积分', 'aksrt');
$user_home_manager = class_exists('AKSRT_User_Home') ? AKSRT_User_Home::get_instance() : null;
$visible_tabs = $user_home_manager ? $user_home_manager->get_visible_tabs($is_own_profile) : [];
$profile_signals = $dashboard['profile_signals'] ?? [];
$profile_notice = $dashboard['profile_notice'] ?? null;
$show_report_button = !empty($dashboard['show_report']);
$enabled_tabs = array_keys($visible_tabs);
if (empty($enabled_tabs)) {
$enabled_tabs = ['posts', 'comments', 'favorites'];
} }
// Apply admin-configured display order $ctx = aksrt_get_user_home_page_context($user);
$_uh_order = $user_home_settings['tabs_order'] ?? []; extract($ctx, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$_uh_ordered = [];
foreach ($_uh_order as $_t) {
if (in_array($_t, $enabled_tabs, true)) {
$_uh_ordered[] = $_t;
}
}
foreach ($enabled_tabs as $_t) {
if (!in_array($_t, $_uh_ordered, true)) {
$_uh_ordered[] = $_t;
}
}
$enabled_tabs = $_uh_ordered;
// Device visibility: build PC/mobile tab arrays
$_uh_pc_hide = $user_home_settings['tabs_pc_hide'] ?? [];
$_uh_mobile_hide = $user_home_settings['tabs_mobile_hide'] ?? [];
$enabled_tabs_pc = array_values(array_diff($enabled_tabs, $_uh_pc_hide));
$enabled_tabs_mobile = array_values(array_diff($enabled_tabs, $_uh_mobile_hide));
$_uh_is_mobile = function_exists('wp_is_mobile') && wp_is_mobile();
$display_tabs = $_uh_is_mobile ? $enabled_tabs_mobile : $enabled_tabs_pc;
$_uh_default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0];
$forum_instance = class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
$forum_stats = $forum_instance ? $forum_instance->get_user_forum_stats($user_id) : [];
$forum_topic_count = (int) ($forum_stats['topic_count'] ?? 0);
$forum_followed_count = (int) ($forum_stats['followed_plate_count'] ?? 0);
$tab_counts = [
'posts' => $post_count,
'comments' => $comment_count,
'favorites' => $favorite_count,
'credits' => $credits_enabled && $is_own_profile ? (int) round($credit_balance) : 0,
'product' => 0,
'plate' => 0,
'forum' => $forum_topic_count,
'follow' => $forum_followed_count,
];
$tab_labels = [
'posts' => __('文章', 'aksrt'),
'comments' => __('评论', 'aksrt'),
'favorites' => __('收藏', 'aksrt'),
'credits' => sprintf(__('我的%s', 'aksrt'), $currency_name),
'product' => __('商品', 'aksrt'),
'plate' => __('圈子', 'aksrt'),
'forum' => __('论坛', 'aksrt'),
'follow' => __('关注', 'aksrt'),
];
foreach ($visible_tabs as $tab_key => $tab_config) {
if (!empty($tab_config['label'])) {
$tab_labels[$tab_key] = (string) $tab_config['label'];
}
}
$active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $_uh_default_tab;
if (!in_array($active_tab, $enabled_tabs, true)) {
$active_tab = $_uh_default_tab;
}
$posts_page = max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1);
$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);
require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php'; require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php';
$svg_empty_post = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M9 13h6M9 17h6M9 9h1"/></svg>';
$svg_empty_comment = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
$svg_empty_favorite = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>';
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
?> ?>
<main id="main-content" class="site-main container content-shell content-shell--stream aksrt-user-home" tabindex="-1"> <main id="main-content" class="site-main container content-shell content-shell--stream aksrt-user-home" tabindex="-1">
<div class="content-wrap"> <div class="content-wrap">
<div class="content-layout<?php echo !empty($user_home_settings['sidebar']) ? '' : ' content-layout--no-sidebar'; ?> aksrt-user-home__layout"> <div class="content-layout<?php echo !empty($user_home_settings['sidebar']) ? '' : ' content-layout--no-sidebar'; ?> aksrt-user-home__layout">
@@ -143,16 +42,18 @@ $home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url
]); ]);
?> ?>
<div class="dashboard dashboard--public" data-default-tab="<?php echo esc_attr($_uh_default_tab); ?>"> <div class="dashboard dashboard--public" data-default-tab="<?php echo esc_attr($default_tab); ?>">
<div class="dashboard-tabs" role="tablist"> <div class="dashboard-tabs" role="tablist">
<?php foreach ($enabled_tabs as $tab_key) : <?php foreach ($enabled_tabs as $tab_key) :
$_tab_class = $tab_key === $active_tab ? 'is-active' : ''; $tab_class = $tab_key === $active_tab ? 'is-active' : '';
$_pc_hidden = in_array($tab_key, $_uh_pc_hide, true); if (in_array($tab_key, $tabs_pc_hide, true)) {
$_mobile_hidden = in_array($tab_key, $_uh_mobile_hide, true); $tab_class .= ' tab-hide-pc';
if ($_pc_hidden) $_tab_class .= ' tab-hide-pc'; }
if ($_mobile_hidden) $_tab_class .= ' tab-hide-mobile'; if (in_array($tab_key, $tabs_mobile_hide, true)) {
$tab_class .= ' tab-hide-mobile';
}
?> ?>
<button type="button" class="<?php echo esc_attr(trim($_tab_class)); ?>" data-tab="<?php echo esc_attr($tab_key); ?>" role="tab"> <button type="button" class="<?php echo esc_attr(trim($tab_class)); ?>" data-tab="<?php echo esc_attr($tab_key); ?>" role="tab">
<?php echo esc_html($tab_labels[$tab_key] ?? ucfirst($tab_key)); ?> <?php echo esc_html($tab_labels[$tab_key] ?? ucfirst($tab_key)); ?>
<span class="dashboard-tabs__count"><?php echo esc_html((string) ($tab_counts[$tab_key] ?? 0)); ?></span> <span class="dashboard-tabs__count"><?php echo esc_html((string) ($tab_counts[$tab_key] ?? 0)); ?></span>
</button> </button>
@@ -160,42 +61,14 @@ $home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url
</div> </div>
<?php <?php
$uh_panel_args = [ get_template_part('templates/parts/user-home/panels', 'core', $ctx);
'user_id' => $user_id, get_template_part('templates/parts/user-home/panel', 'forum', $ctx);
'user' => $user, get_template_part('templates/parts/user-home/panel', 'follow', $ctx);
'home_url' => $home_url,
'active_tab' => $active_tab,
'enabled_tabs' => $enabled_tabs,
'tab_counts' => $tab_counts,
'tab_labels' => $tab_labels,
'per_page' => $per_page,
'posts_page' => $posts_page,
'comments_page' => $comments_page,
'favorites_page' => $favorites_page,
'comment_count' => $comment_count,
'favorite_post_ids' => $favorite_post_ids,
'credits_enabled' => $credits_enabled,
'is_own_profile' => $is_own_profile,
'credit_balance' => $credit_balance,
'currency_name' => $currency_name,
'svg_empty_post' => $svg_empty_post,
'svg_empty_comment' => $svg_empty_comment,
'svg_empty_favorite' => $svg_empty_favorite,
'forum_instance' => $forum_instance,
'forum_topic_count' => $forum_topic_count,
'forum_stats' => $forum_stats,
'user_home_settings' => $user_home_settings,
'user_center_settings' => $user_center_settings,
'user_contacts' => $user_contacts,
];
get_template_part('templates/parts/user-home/panels', 'core', $uh_panel_args);
get_template_part('templates/parts/user-home/panel', 'forum', $uh_panel_args);
get_template_part('templates/parts/user-home/panel', 'follow', $uh_panel_args);
?> ?>
</div> </div>
</div> </div>
<?php get_template_part('templates/parts/user-home/sidebar', null, $uh_panel_args); ?> <?php get_template_part('templates/parts/user-home/sidebar', null, $ctx); ?>
</div> </div>
</div> </div>
</main> </main>
+1
View File
@@ -2,6 +2,7 @@
当前主路径: 当前主路径:
- 壳层:templates/pages/page-user-home.php - 壳层:templates/pages/page-user-home.php
- 上下文:inc/helpers/aksrt-user-home.php(aksrt_get_user_home_page_context)
- 头区:templates/parts/user/author-hero.php - 头区:templates/parts/user/author-hero.php
- 内容面板:panels-core.php / panel-forum.php / panel-follow.php - 内容面板:panels-core.php / panel-forum.php / panel-follow.php
- 侧栏:sidebar.php - 侧栏:sidebar.php