Files
wordpress-theme-aksrt/inc/classes/setup-traits/trait-aksrt-setup-part-2.php
T
kate522 50ca5a6593 feat(admin): expose shop/forum CPTs on native WP sidebar (Phase 0–1)
Align admin ops entry with zibll: product/plate/topic menus and taxonomies
show in the WordPress sidebar when shop_s/bbs_s are enabled, gated by
AKSRT_Settings. Add IA map + gap matrix docs for the full native-ops
migration path. SPA ops pages remain until Phase 2–3 native pages ship.
2026-07-15 01:00:10 +08:00

117 lines
4.0 KiB
PHP

<?php
defined('ABSPATH') || exit;
trait AKSRT_Setup_Part_2 {
/**
* 隐藏默认WordPress菜单项目 + zibll 风格运营菜单分隔线
*/
public function hide_default_menus(): void {
// 移除评论默认菜单(已移除该操作以恢复 Comments 菜单)
// 之前的实现:remove_menu_page('edit-comments.php');
// 移除链接管理(已废弃但仍可能存在)
//remove_menu_page('link-manager.php');
// 移除仪表盘中的不必要组件
remove_meta_box('dashboard_primary', 'dashboard', 'normal');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
// Separators around shop (35) and forum (40) — match zibll admin_menu_separator.
global $menu;
if (!is_array($menu)) {
return;
}
if (!isset($menu[34])) {
$menu[34] = ['', 'read', 'separator-aksrt-shop', '', 'wp-menu-separator'];
}
if (!isset($menu[39])) {
$menu[39] = ['', 'read', 'separator-aksrt-forum', '', 'wp-menu-separator'];
}
}
/**
* Register shop rewrite rules for:
* - /shop/{ID}.html — product detail (ID-based, .html suffix)
* - /shop/{ID}.html/comment-{page} — product comment pagination
* - /{cart_slug}/ — cart page (fixed alias)
*
* Runs at init priority 20 (after CPT registration at priority 1).
*/
public function register_shop_rewrite_rules(): void {
if (!class_exists('AKSRT_Settings')) {
return;
}
$shop = AKSRT_Settings::get_shop_settings();
if (empty($shop['enabled'])) {
return;
}
$rw = $shop['rewrite'] ?? [];
$product_slug = sanitize_key((string) ($rw['product_slug'] ?? 'product'));
$cart_slug = sanitize_key((string) ($rw['cart_slug'] ?? 'cart'));
$suffix_html = !empty($rw['suffix_html']);
// Product ID-based .html routes: /shop/{ID}.html
if ($suffix_html) {
add_rewrite_rule(
'^shop/(\d+)\.html/comment-page-([0-9]{1,})/?$',
'index.php?post_type=aksrt_product&p=$matches[1]&cpage=$matches[2]',
'top'
);
add_rewrite_rule(
'^shop/(\d+)\.html/?$',
'index.php?post_type=aksrt_product&p=$matches[1]',
'top'
);
// Slug-based .html: /{product_slug}/{slug}.html
add_rewrite_rule(
'^' . preg_quote($product_slug) . '/([^/]+)\.html/comment-page-([0-9]{1,})/?$',
'index.php?post_type=aksrt_product&aksrt_product=$matches[1]&cpage=$matches[3]',
'top'
);
add_rewrite_rule(
'^' . preg_quote($product_slug) . '/([^/]+)\.html/?$',
'index.php?post_type=aksrt_product&aksrt_product=$matches[1]',
'top'
);
}
// Cart page: /{cart_slug}/
add_rewrite_rule(
'^' . preg_quote($cart_slug) . '/?$',
'index.php?pagename=' . $cart_slug,
'top'
);
}
/**
* Register shop-specific query vars.
*/
public function register_shop_query_vars(array $vars): array {
$vars[] = 'product_id';
$vars[] = 'shop_action';
return $vars;
}
/**
* Template redirect for shop pages.
*
* - Single aksrt_product: serve page-product.php template
* - Cart page: serve page-cart.php template
*/
public function shop_template_redirect(): void {
// Single product: if the main query resolves to aksrt_product, use our template
if (is_singular('aksrt_product')) {
$tpl = AKSRT_DIR . '/templates/pages/page-product.php';
if (file_exists($tpl)) {
// Set product_id query var for template consumption
set_query_var('product_id', get_queried_object_id());
include $tpl;
exit;
}
}
}
}