将文档模式、下载中心、专题聚合、消息中心、前台投稿等非 Zibll 主线能力 收敛为“兼容保留”,默认不再作为主入口暴露,但保留路由/模板/数据/设置键。 - 新增 inc/helpers/aksrt-compat.php 兼容策略中枢: - aksrt_get_messages_url()(补齐此前缺失、被两处模板调用的 helper) - aksrt_pm_frontend_enabled()(前台私信入口开关,默认关闭) - aksrt_show_compat_page_templates()(兼容页面模板下拉开关,默认关闭) - AKSRT_Templates::page_template_map() 拆分为主线/兼容两组,兼容模板默认 移出 wp-admin 页面模板下拉;已分配这些模板的历史页面照常渲染。 - 作者操作条“私信”按钮(停用候选)默认前台隐藏,可经 filter/常量开启。 - 修复 admin-sections.js barrel 未再导出 getAdminSections 的缺陷,该缺陷 会使 router 的兼容分区默认落点重定向在加载时抛错。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
172 lines
6.4 KiB
PHP
172 lines
6.4 KiB
PHP
<?php
|
||
/**
|
||
* AKSRT Page Templates
|
||
*
|
||
* @package AKSRT
|
||
* @since 1.0.0
|
||
*/
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
class AKSRT_Templates {
|
||
|
||
private static $instance = null;
|
||
|
||
private function __construct() {}
|
||
|
||
public static function get_instance(): self {
|
||
if (null === self::$instance) {
|
||
self::$instance = new self();
|
||
}
|
||
|
||
return self::$instance;
|
||
}
|
||
|
||
public function init(): void {
|
||
add_filter('theme_page_templates', [$this, 'register_page_templates']);
|
||
add_filter('template_include', [$this, 'load_page_template']);
|
||
add_filter('template_include', [$this, 'load_taxonomy_template']);
|
||
add_filter('page_template_hierarchy', [$this, 'template_hierarchy']);
|
||
add_filter('aksrt_page_template_hierarchy', [$this, 'template_hierarchy']);
|
||
|
||
// 短代码注册统一在 AKSRT_Shortcodes(registry);本类只提供 archive/profile 渲染实现。
|
||
}
|
||
|
||
/**
|
||
* 主线页面模板:内容 / 用户 / 付费 / 论坛 / 商城主线可选模板。
|
||
*/
|
||
private function mainline_page_template_map(): array {
|
||
return [
|
||
'templates/pages/page-sign.php' => __('AKSRT - 登录/注册', 'aksrt'),
|
||
'templates/pages/page-profile.php' => __('AKSRT - 个人中心', 'aksrt'),
|
||
'templates/pages/page-user-home.php' => __('AKSRT - 用户主页', 'aksrt'),
|
||
'templates/pages/page-archives.php' => __('AKSRT - 文章归档', 'aksrt'),
|
||
'templates/pages/page-categories.php' => __('AKSRT - 分类汇总', 'aksrt'),
|
||
'templates/pages/page-newposts.php' => __('AKSRT - 最新文章', 'aksrt'),
|
||
'templates/pages/page-posts-navs.php' => __('AKSRT - 文章导航', 'aksrt'),
|
||
'templates/pages/page-friends.php' => __('AKSRT - 友情链接', 'aksrt'),
|
||
'templates/pages/page-orders.php' => __('AKSRT - 订单中心', 'aksrt'),
|
||
'templates/pages/page-revenue.php' => __('AKSRT - 收益中心', 'aksrt'),
|
||
'templates/pages/page-cart.php' => __('AKSRT - 购物车', 'aksrt'),
|
||
'templates/pages/page-product.php' => __('AKSRT - 商品详情', 'aksrt'),
|
||
'templates/pages/page-product-edit.php' => __('AKSRT - 商品编辑', 'aksrt'),
|
||
'templates/pages/page-forums.php' => __('AKSRT - 论坛', 'aksrt'),
|
||
'templates/forum/forum-compose.php' => __('AKSRT - 发帖', 'aksrt'),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 兼容保留页面模板:非 Zibll 主线能力(文档模式、下载中心、专题、消息、投稿)。
|
||
*
|
||
* 这些模板文件与已分配它们的历史页面继续正常渲染(见 load_page_template()),
|
||
* 只是默认不再出现在 wp-admin 页面模板下拉中,避免污染主线内容心智。
|
||
* 站点可通过 aksrt_show_compat_page_templates() 重新暴露下拉选项。
|
||
*/
|
||
private function compat_page_template_map(): array {
|
||
return [
|
||
'templates/pages/page-special.php' => __('AKSRT - 专题聚合(兼容)', 'aksrt'),
|
||
'templates/pages/page-documentnav.php' => __('AKSRT - 文档导航(兼容)', 'aksrt'),
|
||
'templates/pages/page-messages.php' => __('AKSRT - 消息中心(兼容)', 'aksrt'),
|
||
'templates/pages/page-download.php' => __('AKSRT - 下载中心(兼容)', 'aksrt'),
|
||
'templates/pages/page-submit.php' => __('AKSRT - 前台投稿(兼容)', 'aksrt'),
|
||
];
|
||
}
|
||
|
||
private function page_template_map(): array {
|
||
$map = $this->mainline_page_template_map();
|
||
|
||
// 兼容页面模板默认隐藏出下拉;仅在站点显式开启时暴露。
|
||
if (function_exists('aksrt_show_compat_page_templates') && aksrt_show_compat_page_templates()) {
|
||
$map = array_merge($map, $this->compat_page_template_map());
|
||
}
|
||
|
||
return $map;
|
||
}
|
||
|
||
/**
|
||
* Register selectable page templates in wp-admin.
|
||
*/
|
||
public function register_page_templates(array $templates): array {
|
||
foreach ($this->page_template_map() as $template_file => $label) {
|
||
$templates[$template_file] = $label;
|
||
}
|
||
|
||
return $templates;
|
||
}
|
||
|
||
/**
|
||
* Resolve theme page templates through the shared page-template router.
|
||
*/
|
||
public function load_page_template(string $template): string {
|
||
global $post;
|
||
|
||
if (!$post) {
|
||
return $template;
|
||
}
|
||
|
||
$page_template_meta = get_post_meta($post->ID, '_wp_page_template', true);
|
||
$resolved_template = function_exists('aksrt_resolve_page_template_file')
|
||
? aksrt_resolve_page_template_file(
|
||
is_string($page_template_meta) ? $page_template_meta : '',
|
||
(string) $post->post_name
|
||
)
|
||
: '';
|
||
|
||
if ($resolved_template !== '' && function_exists('aksrt_locate_template_file')) {
|
||
$resolved_path = aksrt_locate_template_file($resolved_template);
|
||
if ($resolved_path) {
|
||
return $resolved_path;
|
||
}
|
||
}
|
||
|
||
return $template;
|
||
}
|
||
|
||
public function template_hierarchy(array $templates): array {
|
||
return $templates;
|
||
}
|
||
|
||
/**
|
||
* Load dedicated product taxonomy templates.
|
||
*/
|
||
public function load_taxonomy_template(string $template): string {
|
||
if (is_tax('aksrt_product_cat')) {
|
||
$cat_template = AKSRT_DIR . '/templates/shop/product-cat.php';
|
||
if (file_exists($cat_template)) {
|
||
return $cat_template;
|
||
}
|
||
}
|
||
|
||
if (is_tax('aksrt_product_tag')) {
|
||
$tag_template = AKSRT_DIR . '/templates/shop/product-tag.php';
|
||
if (file_exists($tag_template)) {
|
||
return $tag_template;
|
||
}
|
||
}
|
||
|
||
return $template;
|
||
}
|
||
|
||
public function render_archive_shortcode(array $attrs = [], string $content = ''): string {
|
||
$template = AKSRT_DIR . '/templates/shortcodes/archive.php';
|
||
if (!file_exists($template)) {
|
||
return '';
|
||
}
|
||
ob_start();
|
||
include $template;
|
||
return (string) ob_get_clean();
|
||
}
|
||
|
||
public function render_profile_shortcode(array $attrs = [], string $content = ''): string {
|
||
$template = AKSRT_DIR . '/templates/shortcodes/profile.php';
|
||
if (!file_exists($template)) {
|
||
return '';
|
||
}
|
||
ob_start();
|
||
include $template;
|
||
return (string) ob_get_clean();
|
||
}
|
||
}
|
||
|
||
return AKSRT_Templates::get_instance();
|