导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait AKSRT_Setup_Part_2 {
|
||||
|
||||
|
||||
/**
|
||||
* 隐藏默认WordPress菜单项目
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user