Files
wordpress-theme-aksrt/functions.php
T
kate522 e0279e1a23 feat(admin): topic governance list columns and native charge-card batching
Add native aksrt_forum_topic list filters/columns/bulk/quick-edit for
sticky/lock/review/plate. Replace SPA charge-card batch link with an
inline batch generator on the 支付中心卡密 page. No build artifacts.
2026-07-15 02:22:41 +08:00

363 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* AKSRT Theme - Main Functions File (v3.2 Restructured)
*
* 精简版入口文件,仅负责:
* 1. 瀹氫箟甯搁噺 & 杈呭姪鍑芥暟(aksrt_get_setting)
* 2. 2. 加载 bootstrap(自动加载所有模块)
* 3. 3. 初始化单例实例
* 4. 4. 主题激活时刷新重写规则
*
* 业务逻辑已拆分至 inc/core-hooks.php 和各独立类文件。
*
* @package AKSRT
* @version 3.2.0
*/
defined('ABSPATH') || exit;
define('AKSRT_VERSION', '3.4.0-dev');
define('AKSRT_DIR', get_template_directory());
define('AKSRT_URI', get_template_directory_uri());
// WordPress 6.7+ 会对 after_setup_theme 之前的翻译调用产生 _load_textdomain_just_in_time 通知,
// 此处抑制该通知以避免前台输出 debug 信息。
add_filter('doing_it_wrong_trigger_error', function ($trigger, $function_name) {
if ($function_name === '_load_textdomain_just_in_time') {
return false;
}
return $trigger;
}, 10, 2);
// ============================================================
// 全局辅助函数(必须在类文件加载之前定义)
// ============================================================
if (!function_exists('aksrt_get_setting')) {
/**
* 获取合并后的主题设置。
* 兼容旧版 aksrt_settings,以及新版 basic / seo 拆分存储。
*
* @return array
*/
function aksrt_get_all_settings() {
if (class_exists('AKSRT_Settings')) {
return AKSRT_Settings::get_all();
}
$settings = get_option('aksrt_settings', array());
return is_array($settings) ? $settings : array();
}
/**
* 获取主题设置项
* @param string $key 璁剧疆閿悕
* @param string $default 榛樿鍊?
* @return mixed
*/
function aksrt_get_setting($key = '', $default = '') {
$all = aksrt_get_all_settings();
if (empty($key)) return $all;
return isset($all[$key]) ? $all[$key] : $default;
}
}
// ============================================================
// 加载 Composer 依赖(OAuth2 客户端库等)
// ============================================================
$composer_autoload = AKSRT_DIR . '/vendor/autoload.php';
if (file_exists($composer_autoload)) {
require_once $composer_autoload;
}
// ============================================================
// 加载 Bootstrap(辅助函数 → 类文件 → 核心钩子)
// ============================================================
require_once AKSRT_DIR . '/inc/bootstrap.php';
// ============================================================
// 主题激活时刷新重写规则
// ============================================================
add_action('after_switch_theme', function () {
flush_rewrite_rules();
});
// §3.4 custom_filter: register custom query vars for archive filter
add_filter('query_vars', function ($vars) {
$vars[] = 'aksrt_filter_cat';
$vars[] = 'aksrt_filter_tag';
// Dynamic aksrt_cf_* vars are handled via $_GET fallback in templates
return $vars;
});
// 主题切换离开时:清理本主题注册的 cron 任务
add_action('switch_theme', function () {
$hooks = ['aksrt_dl_token_cleanup', 'aksrt_email_verification_backfill_batch', 'aksrt_notification_cleanup'];
foreach ($hooks as $hook) {
$next = wp_next_scheduled($hook);
while ($next) {
wp_unschedule_event($next, $hook);
$next = wp_next_scheduled($hook);
}
}
});
// 兜底:检测版本变更时自动刷新重写规则
if (get_option('aksrt_flushed_version') !== AKSRT_VERSION) {
delete_option('rewrite_rules');
add_action('init', function () {
flush_rewrite_rules();
update_option('aksrt_flushed_version', AKSRT_VERSION);
}, 99);
}
// ============================================================
// 初始化所有单例实例
// ============================================================
AKSRT_Setup::get_instance()->init();
AKSRT_Scripts::get_instance()->init();
AKSRT_Admin::get_instance()->init();
AKSRT_OAuth::get_instance()->init();
// 初始化代理登录(根据配置模式选择性加载)
$aksrt_proxy_mode = AKSRT_Settings::oauth_proxy_mode();
if ($aksrt_proxy_mode === 'client' && class_exists('AKSRT_OAuth_Proxy_Client')) {
AKSRT_OAuth_Proxy_Client::get_instance()->init();
}
if ($aksrt_proxy_mode === 'server' && class_exists('AKSRT_OAuth_Proxy_Server')) {
AKSRT_OAuth_Proxy_Server::get_instance()->init();
}
AKSRT_Settings::get_instance()->init();
AKSRT_Auth_Router::get_instance()->init();
AKSRT_Templates::get_instance()->init();
AKSRT_Moderation::get_instance()->init();
// 短代码统一注册入口(registry)
if (class_exists('AKSRT_Shortcodes')) {
add_action('init', function () {
AKSRT_Shortcodes::get_instance()->register();
});
}
// 用户限制/封禁系统
if (class_exists('AKSRT_User_Restriction')) {
AKSRT_User_Restriction::get_instance()->init();
}
// 用户中心 & 公开主页协调类
if (class_exists('AKSRT_User_Center')) {
AKSRT_User_Center::get_instance()->init();
}
if (class_exists('AKSRT_User_Home')) {
AKSRT_User_Home::get_instance()->init();
}
// 数据表迁移器:注册 hook(after_switch_theme + admin_init 双触发)
if (class_exists('AKSRT_DB_Migrator')) {
AKSRT_DB_Migrator::init();
}
// 积分获取入口(注册赠送 / 评论奖励 / 签到 / 邀请)
if (class_exists('AKSRT_Credits_Earn')) {
AKSRT_Credits_Earn::get_instance()->init();
}
if (class_exists('AKSRT_Signin')) {
AKSRT_Signin::get_instance()->init();
}
if (class_exists('AKSRT_Invite')) {
AKSRT_Invite::get_instance()->init();
}
if (class_exists('AKSRT_Creator_Revenue')) {
AKSRT_Creator_Revenue::get_instance()->init();
}
if (class_exists('AKSRT_Download')) {
AKSRT_Download::get_instance()->init();
}
if (class_exists('AKSRT_Content_Pay')) {
AKSRT_Content_Pay::get_instance()->init();
}
if (class_exists('AKSRT_Vip_Service')) {
AKSRT_Vip_Service::get_instance()->init();
}
if (class_exists('AKSRT_Charge_Card')) {
AKSRT_Charge_Card::get_instance()->init();
}
// Download State & Docs Presenter are pure service singletons (no hooks)
if (class_exists('AKSRT_Download_State')) {
AKSRT_Download_State::get_instance();
}
if (class_exists('AKSRT_Docs_Presenter')) {
AKSRT_Docs_Presenter::get_instance();
}
if (class_exists('AKSRT_Content_Visibility')) {
AKSRT_Content_Visibility::get_instance()->init();
}
if (class_exists('AKSRT_SMS')) {
AKSRT_SMS::get_instance()->init();
}
if (class_exists('AKSRT_AI')) {
AKSRT_AI::get_instance(); // config-gated; available when admin enables
}
if (class_exists('AKSRT_WeChat_Notify')) {
AKSRT_WeChat_Notify::get_instance()->init();
}
if (class_exists('AKSRT_Message')) {
AKSRT_Message::get_instance()->init();
}
if (class_exists('AKSRT_Private_Message')) {
AKSRT_Private_Message::get_instance()->init();
}
if (class_exists('AKSRT_Report_Center')) {
AKSRT_Report_Center::get_instance()->init();
}
if (class_exists('AKSRT_Comment_Actions')) {
AKSRT_Comment_Actions::get_instance()->init();
}
if (class_exists('AKSRT_Go_Redirect')) {
AKSRT_Go_Redirect::get_instance()->init();
}
if (class_exists('AKSRT_Site_Notice')) {
AKSRT_Site_Notice::get_instance()->init();
}
if (class_exists('AKSRT_API_Audit')) {
AKSRT_API_Audit::get_instance()->init();
}
if (class_exists('AKSRT_MeiliSearch')) {
AKSRT_MeiliSearch::get_instance()->init();
// Async single post index (debounced)
add_action('aksrt_meilisearch_index_single', function (int $post_id) {
AKSRT_MeiliSearch::get_instance()->index_post($post_id);
});
}
if (class_exists('AKSRT_Search_Push')) {
AKSRT_Search_Push::get_instance()->init();
}
if (class_exists('AKSRT_SEO_Head')) {
AKSRT_SEO_Head::get_instance()->init();
}
if (class_exists('AKSRT_Update_Checker')) {
AKSRT_Update_Checker::get_instance()->init();
}
if (class_exists('AKSRT_Category_Rewrite')) {
AKSRT_Category_Rewrite::get_instance()->init();
}
if (class_exists('AKSRT_Front_Submit')) {
AKSRT_Front_Submit::get_instance()->init();
}
if (class_exists('AKSRT_Order')) {
AKSRT_Order::get_instance()->init();
}
// Register built-in payment gateways
if (class_exists('AKSRT_Payment_Gateway')) {
$gw = AKSRT_Payment_Gateway::get_instance();
// 注册支付回调路由(/payment/{gateway}/notify|return|cancel)。
$gw->init();
if (class_exists('AKSRT_Balance_Gateway')) {
$gw->register('balance', new AKSRT_Balance_Gateway());
}
if (class_exists('AKSRT_Alipay_Gateway')) {
$gw->register('alipay', new AKSRT_Alipay_Gateway());
}
if (class_exists('AKSRT_WechatPay_Gateway')) {
$gw->register('wechatpay', new AKSRT_WechatPay_Gateway());
}
if (class_exists('AKSRT_PayPal_Gateway')) {
$gw->register('paypal', new AKSRT_PayPal_Gateway());
}
if (class_exists('AKSRT_Stripe_Gateway')) {
$gw->register('stripe', new AKSRT_Stripe_Gateway());
}
do_action('aksrt_register_payment_gateways', $gw);
}
if (class_exists('AKSRT_Forum')) {
AKSRT_Forum::get_instance()->init();
}
if (is_admin() && class_exists('AKSRT_Resource_Meta_Box')) {
AKSRT_Resource_Meta_Box::get_instance()->init();
}
// 分类/标签局部配置(term meta 字段)
if (class_exists('AKSRT_Term_Meta')) {
AKSRT_Term_Meta::get_instance()->init();
}
// 商城 taxonomy term meta + shop_discount 优惠活动
if (class_exists('AKSRT_Shop_Term_Meta')) {
AKSRT_Shop_Term_Meta::get_instance()->init();
}
// 商品后台列表自定义列(销量/综合数据/商家/优惠活动)
if (is_admin() && class_exists('AKSRT_Admin_Shop_Controller')) {
AKSRT_Admin_Shop_Controller::get_instance()->init_product_admin_columns();
}
// 商品原生编辑 meta box(价格/库存/发货售后)
if (is_admin() && class_exists('AKSRT_Product_Meta_Box')) {
AKSRT_Product_Meta_Box::get_instance()->init();
}
// 商品原生变体 meta box
if (is_admin() && class_exists('AKSRT_Product_Variants_Meta_Box')) {
AKSRT_Product_Variants_Meta_Box::get_instance()->init();
}
// 论坛版块版主 meta box
if (is_admin() && class_exists('AKSRT_Plate_Meta_Box')) {
AKSRT_Plate_Meta_Box::get_instance()->init();
}
// 论坛帖子原生列表治理列/筛选/批量
if (is_admin() && class_exists('AKSRT_Topic_Admin_List')) {
AKSRT_Topic_Admin_List::get_instance()->init();
}
// 商品评价/评分系统
if (class_exists('AKSRT_Product_Review')) {
AKSRT_Product_Review::get_instance()->init();
}
// 文章局部配置 meta box(仅后台)
if (is_admin() && class_exists('AKSRT_Post_Meta_Box')) {
AKSRT_Post_Meta_Box::get_instance()->init();
}
if (is_admin() && class_exists('AKSRT_SEO_Meta_Box')) {
AKSRT_SEO_Meta_Box::get_instance()->init();
}
// 绔欑偣璁块棶閲忕粺璁?
if (class_exists('AKSRT_Stats_Tracker')) {
AKSRT_Stats_Tracker::init();
}
// Email rollback window (24h): user list row action + admin-post handler.
if (class_exists('AKSRT_Email_Rollback')) {
AKSRT_Email_Rollback::get_instance()->init();
}
// WordPress 原生"用户"菜单:积分管理
if (class_exists('AKSRT_User_Credits_Admin')) {
AKSRT_User_Credits_Admin::get_instance()->init();
}
// WordPress 原生侧栏:支付/订单运营中心(zibll zibpay 对齐)
if (is_admin() && class_exists('AKSRT_Admin_Pay_Menus')) {
AKSRT_Admin_Pay_Menus::get_instance()->init();
}
// WordPress 原生用户菜单:消息/邀请码/认证/禁封(zibll users.php 子菜单对齐)
if (is_admin() && class_exists('AKSRT_Admin_Users_Menus')) {
AKSRT_Admin_Users_Menus::get_instance()->init();
}
// ============================================================
// 主题删除时的数据库清理(仅在用户启用清理选项时生效)
// uninstall.php 会检查 aksrt_cleanup_on_uninstall 选项
// ============================================================
register_deactivation_hook(__FILE__, function () {
// 主题停用时不做任何清理,仅在删除时由 uninstall.php 处理。
// 自定义表(aksrt_*)在主题切换后保留数据,确保重新启用时不丢失。
});