用户域一次性收口:统一公开主页资源归属并折叠作者页双路径

把 uh-forum 样式收进 user-home 路由、author.php 收成 301 回退、公开主页脚本以 author.js 为唯一实现,并去掉 enqueue/body class 中的 is_author 分叉。
This commit is contained in:
2026-07-10 22:11:44 +08:00
parent c28c1226ac
commit f76d4650e5
9 changed files with 157 additions and 360 deletions
+18 -123
View File
@@ -1,136 +1,31 @@
<?php
/**
* Author Archive Template — 作者归档页
* Author archive fallback.
*
* 渲染 /author/{nicename}/ 的完整作者归档页面:
* - 作者 Hero 区(头图、头像、身份、统计、操作按钮)
* - 作者文章列表(WordPress 主循环)
* - 可扩展挂载点:aksrt_author_before_content / aksrt_author_after_content
*
* 数据聚合复用 aksrt_get_user_dashboard_view(),与 page-user-home.php 同源。
* Canonical public profile is /user/{nicename}/ (page-user-home.php).
* class-aksrt-user.php already 301-redirects is_author() there; this file
* remains only as a last-resort template if rewrite/redirect is bypassed.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
global $wp_query;
$author_id = (int) get_query_var('author');
$author = $author_id ? get_userdata($author_id) : null;
if (!$author || is_wp_error($author)) {
wp_safe_redirect(home_url('/'));
exit;
$author_id = (int) get_queried_object_id();
if (!$author_id) {
$author_id = (int) get_query_var('author');
}
get_header();
$user = $author_id ? get_userdata($author_id) : null;
if ($user instanceof WP_User && function_exists('aksrt_get_user_home_url')) {
wp_safe_redirect(aksrt_get_user_home_url($user), 301);
exit;
}
$user_id = (int) $author->ID;
$dashboard = function_exists('aksrt_get_user_dashboard_view')
? aksrt_get_user_dashboard_view($user_id, ['viewer_id' => get_current_user_id()])
: [];
if ($user instanceof WP_User) {
wp_safe_redirect(home_url('/user/' . trailingslashit($user->user_nicename)), 301);
exit;
}
$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,
];
require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php';
?>
<main id="main-content" class="site-main container content-shell content-shell--stream aksrt-author-page" tabindex="-1">
<div class="content-wrap">
<div class="content-layout<?php echo !empty($user_home_settings['sidebar']) ? '' : ' content-layout--no-sidebar'; ?> aksrt-author-page__layout">
<div class="content-layout__primary">
<?php
get_template_part('templates/parts/user/author-hero', null, [
'user' => $author,
'dashboard' => $dashboard,
'user_home_settings' => $user_home_settings,
'is_author_page' => true,
]);
?>
<?php do_action('aksrt_author_before_content', $user_id); ?>
<div class="aksrt-author-page__content aksrt-theme-box">
<div class="aksrt-author-page__content-header">
<h2 class="aksrt-author-page__section-title">
<i class="fas fa-file-alt" aria-hidden="true"></i>
<?php esc_html_e('发布的文章', 'aksrt'); ?>
</h2>
</div>
<?php if (have_posts()) : ?>
<div class="aksrt-author-page__posts">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/parts/content', 'profile-list-item', [
'action' => [
'type' => 'view',
'url' => get_permalink(),
'label' => __('阅读', 'aksrt'),
],
]); ?>
<?php endwhile; ?>
</div>
<?php
$total_pages = (int) $wp_query->max_num_pages;
$current_page = max(1, (int) get_query_var('paged'));
if ($total_pages > 1) :
?>
<div class="aksrt-author-page__pagination">
<?php
echo paginate_links([
'total' => $total_pages,
'current' => $current_page,
'mid_size' => 2,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-author-page__empty">
<div class="aksrt-author-page__empty-icon">
<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" width="30" height="30"><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>
</div>
<p class="aksrt-author-page__empty-title"><?php esc_html_e('暂无文章', 'aksrt'); ?></p>
<p class="aksrt-author-page__empty-desc"><?php echo esc_html(sprintf(__('%s 还没有发布任何文章。', 'aksrt'), $author->display_name)); ?></p>
</div>
<?php endif; ?>
</div>
<?php do_action('aksrt_author_after_content', $user_id); ?>
</div>
<?php if (!empty($user_home_settings['sidebar'])) : ?>
<aside class="content-layout__aside sidebar aksrt-author-page__aside" role="complementary" aria-label="<?php esc_attr_e('作者页侧栏', 'aksrt'); ?>">
<?php
$sidebar_id = is_active_sidebar('author-sidebar') ? 'author-sidebar' : 'sidebar-blog';
if (is_active_sidebar('all_sidebar_top')) {
dynamic_sidebar('all_sidebar_top');
}
if (is_active_sidebar($sidebar_id)) {
dynamic_sidebar($sidebar_id);
}
if (is_active_sidebar('all_sidebar_bottom')) {
dynamic_sidebar('all_sidebar_bottom');
}
?>
</aside>
<?php endif; ?>
</div>
</div>
</main>
<?php get_footer(); ?>
wp_safe_redirect(home_url('/'), 302);
exit;