500] ); } require_once $composer_autoload; // Theme classes live under src/AKSRT/ and only load via Composer PSR-4. // Stale vendor/ (e.g. install before composer.json gained "AKSRT\\") leaves // autoload_psr4 without AKSRT\ and fatals on the first DomainModel reference. if (!class_exists(\AKSRT\Core\DomainModel::class, true)) { wp_die( esc_html__( 'AKSRT class autoload is incomplete: AKSRT\\Core\\DomainModel was not found. In the theme directory run "composer install" (or "composer dump-autoload -o"), then clear any opcode cache (opcache_reset / php-fpm reload).', 'aksrt' ), esc_html__('AKSRT theme', 'aksrt'), ['response' => 500] ); } // ============================================================ // 加载 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\Core\Setup::get_instance()->init(); \AKSRT\Core\Scripts::get_instance()->init(); \AKSRT\Admin\Admin::get_instance()->init(); \AKSRT\Auth\OAuth::get_instance()->init(); // 初始化代理登录(根据配置模式选择性加载) $aksrt_proxy_mode = \AKSRT\Settings\Settings::oauth_proxy_mode(); if ($aksrt_proxy_mode === 'client' && class_exists('\AKSRT\Auth\OAuthProxyClient')) { \AKSRT\Auth\OAuthProxyClient::get_instance()->init(); } if ($aksrt_proxy_mode === 'server' && class_exists('\AKSRT\Auth\OAuthProxyServer')) { \AKSRT\Auth\OAuthProxyServer::get_instance()->init(); } \AKSRT\Settings\Settings::get_instance()->init(); \AKSRT\Auth\Router::get_instance()->init(); \AKSRT\Core\Templates::get_instance()->init(); \AKSRT\Auth\Moderation::get_instance()->init(); // 短代码统一注册入口(registry) if (class_exists('\AKSRT\Core\Shortcodes')) { add_action('init', function () { \AKSRT\Core\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\Core\DBMigrator')) { \AKSRT\Core\DBMigrator::init(); } // 积分获取入口(注册赠送 / 评论奖励 / 签到 / 邀请) if (class_exists('\AKSRT\Credits\Earn')) { \AKSRT\Credits\Earn::get_instance()->init(); } if (class_exists('\AKSRT\Credits\Signin')) { \AKSRT\Credits\Signin::get_instance()->init(); } if (class_exists('\AKSRT\Credits\Invite')) { \AKSRT\Credits\Invite::get_instance()->init(); } if (class_exists('AKSRT\\Payment\\CreatorRevenue')) { \AKSRT\Payment\CreatorRevenue::get_instance()->init(); } if (class_exists('\AKSRT\Content\Download')) { \AKSRT\Content\Download::get_instance()->init(); } if (class_exists('\AKSRT\Content\Pay')) { \AKSRT\Content\Pay::get_instance()->init(); } if (class_exists('\AKSRT\Forum\TopicPay')) { \AKSRT\Forum\TopicPay::get_instance()->init(); } if (class_exists('\AKSRT\Forum\PlateFollowPay')) { \AKSRT\Forum\PlateFollowPay::get_instance()->init(); } if (class_exists('\AKSRT\Content\VipService')) { \AKSRT\Content\VipService::get_instance()->init(); } if (class_exists('\AKSRT\Payment\ChargeCard')) { \AKSRT\Payment\ChargeCard::get_instance()->init(); } if (class_exists('\AKSRT\Credits\BalanceService')) { \AKSRT\Credits\BalanceService::get_instance()->init(); } // Download State & Docs Presenter are pure service singletons (no hooks) if (class_exists('\AKSRT\Content\DownloadState')) { \AKSRT\Content\DownloadState::get_instance(); } if (class_exists('\AKSRT\Core\DocsPresenter')) { \AKSRT\Core\DocsPresenter::get_instance(); } // Homepage module preview REST + query var (render still via helpers / static methods) if (class_exists('\AKSRT\Core\HomeModules')) { \AKSRT\Core\HomeModules::get_instance()->init(); } if (class_exists('\AKSRT\Content\Visibility')) { \AKSRT\Content\Visibility::get_instance()->init(); } if (class_exists('\AKSRT\Sms\SMS')) { \AKSRT\Sms\SMS::get_instance()->init(); } if (class_exists('\AKSRT\Ai\AI')) { \AKSRT\Ai\AI::get_instance(); // config-gated; available when admin enables } if (class_exists('\AKSRT\Payment\WeChatNotify')) { \AKSRT\Payment\WeChatNotify::get_instance()->init(); } if (class_exists('\AKSRT\Messages\Message')) { \AKSRT\Messages\Message::get_instance()->init(); } if (class_exists('\AKSRT\Messages\PrivateMessage')) { \AKSRT\Messages\PrivateMessage::get_instance()->init(); } if (class_exists('\AKSRT\Messages\ReportCenter')) { \AKSRT\Messages\ReportCenter::get_instance()->init(); } if (class_exists('\AKSRT\Core\CommentActions')) { \AKSRT\Core\CommentActions::get_instance()->init(); } if (class_exists('\AKSRT\Core\GoRedirect')) { \AKSRT\Core\GoRedirect::get_instance()->init(); } if (class_exists('\AKSRT\Core\LinksSubmit')) { \AKSRT\Core\LinksSubmit::get_instance()->init(); } if (class_exists('\AKSRT\Core\LinksPageMeta')) { \AKSRT\Core\LinksPageMeta::get_instance()->init(); } if (class_exists('\AKSRT\Core\PostsNavs')) { \AKSRT\Core\PostsNavs::get_instance()->init(); } if (class_exists('\AKSRT\User\AuthApply')) { \AKSRT\User\AuthApply::get_instance()->init(); } if (class_exists('\AKSRT\Messages\SiteNotice')) { \AKSRT\Messages\SiteNotice::get_instance()->init(); } if (class_exists('\AKSRT\Extensions\APIAudit')) { \AKSRT\Extensions\APIAudit::get_instance()->init(); } if (class_exists('\AKSRT\Extensions\MeiliSearch')) { \AKSRT\Extensions\MeiliSearch::get_instance()->init(); // Async single post index (debounced) add_action('aksrt_meilisearch_index_single', function (int $post_id) { \AKSRT\Extensions\MeiliSearch::get_instance()->index_post($post_id); }); } if (class_exists('\AKSRT\Extensions\SearchPush')) { \AKSRT\Extensions\SearchPush::get_instance()->init(); } if (class_exists('\AKSRT\Core\SEOHead')) { \AKSRT\Core\SEOHead::get_instance()->init(); } if (class_exists('\AKSRT\Core\UpdateChecker')) { \AKSRT\Core\UpdateChecker::get_instance()->init(); } if (class_exists('\AKSRT\Core\CategoryRewrite')) { \AKSRT\Core\CategoryRewrite::get_instance()->init(); } if (class_exists('\AKSRT\Core\FrontSubmit')) { \AKSRT\Core\FrontSubmit::get_instance()->init(); } if (class_exists('\AKSRT\Payment\Order')) { \AKSRT\Payment\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\Payment\BalanceGateway')) { $gw->register('balance', new \AKSRT\Payment\BalanceGateway()); } if (class_exists('\AKSRT\Payment\Gateways\AlipayGateway')) { $gw->register('alipay', new \AKSRT\Payment\Gateways\AlipayGateway()); } if (class_exists('\AKSRT\Payment\Gateways\WechatPayGateway')) { $gw->register('wechatpay', new \AKSRT\Payment\Gateways\WechatPayGateway()); } if (class_exists('\AKSRT\Payment\Gateways\PayPalGateway')) { $gw->register('paypal', new \AKSRT\Payment\Gateways\PayPalGateway()); } if (class_exists('\AKSRT\Payment\Gateways\StripeGateway')) { $gw->register('stripe', new \AKSRT\Payment\Gateways\StripeGateway()); } do_action('aksrt_register_payment_gateways', $gw); } if (class_exists('\AKSRT\Forum\Forum')) { \AKSRT\Forum\Forum::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Core\ResourceMetaBox')) { \AKSRT\Core\ResourceMetaBox::get_instance()->init(); } // 分类/标签局部配置(term meta 字段) if (class_exists('\AKSRT\Core\TermMeta')) { \AKSRT\Core\TermMeta::get_instance()->init(); } // 商城 taxonomy term meta + shop_discount 优惠活动 if (class_exists('\AKSRT\Shop\TermMeta')) { \AKSRT\Shop\TermMeta::get_instance()->init(); } // 商品后台列表自定义列(销量/综合数据/商家/优惠活动) if (is_admin() && class_exists('\AKSRT\Admin\ShopController')) { \AKSRT\Admin\ShopController::get_instance()->init_product_admin_columns(); } // 商品原生编辑 meta box(价格/库存/发货售后) if (is_admin() && class_exists('\AKSRT\Shop\ProductMetaBox')) { \AKSRT\Shop\ProductMetaBox::get_instance()->init(); } // 商品原生变体 meta box if (is_admin() && class_exists('\AKSRT\Shop\ProductVariantsMetaBox')) { \AKSRT\Shop\ProductVariantsMetaBox::get_instance()->init(); } // 论坛版块版主 meta box if (is_admin() && class_exists('\AKSRT\Forum\PlateMetaBox')) { \AKSRT\Forum\PlateMetaBox::get_instance()->init(); } // 论坛帖子原生列表治理列/筛选/批量 if (is_admin() && class_exists('\AKSRT\Forum\TopicAdminList')) { \AKSRT\Forum\TopicAdminList::get_instance()->init(); } // 论坛帖子治理 meta box if (is_admin() && class_exists('\AKSRT\Forum\TopicMetaBox')) { \AKSRT\Forum\TopicMetaBox::get_instance()->init(); } // 论坛版块列表列 if (is_admin() && class_exists('\AKSRT\Forum\PlateAdminList')) { \AKSRT\Forum\PlateAdminList::get_instance()->init(); } // 商品评价/评分系统 if (class_exists('\AKSRT\Shop\ProductReview')) { \AKSRT\Shop\ProductReview::get_instance()->init(); } // 文章局部配置 meta box(仅后台) if (is_admin() && class_exists('\AKSRT\Core\PostMetaBox')) { \AKSRT\Core\PostMetaBox::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Core\SEOMetaBox')) { \AKSRT\Core\SEOMetaBox::get_instance()->init(); } // 绔欑偣璁块棶閲忕粺璁? if (class_exists('\AKSRT\Core\StatsTracker')) { \AKSRT\Core\StatsTracker::init(); } // Email rollback window (24h): user list row action + admin-post handler. if (class_exists('\AKSRT\Auth\EmailRollback')) { \AKSRT\Auth\EmailRollback::get_instance()->init(); } // WordPress 原生"用户"菜单:积分管理 if (class_exists('\AKSRT\User\CreditsAdmin')) { \AKSRT\User\CreditsAdmin::get_instance()->init(); } if (class_exists('\AKSRT\User\BalanceAdmin')) { \AKSRT\User\BalanceAdmin::get_instance()->init(); } if (class_exists('\AKSRT\User\Badges')) { \AKSRT\User\Badges::get_instance()->init(); } if (class_exists('\AKSRT\User\BadgesAdmin')) { \AKSRT\User\BadgesAdmin::get_instance()->init(); } if (class_exists('\AKSRT\User\Level')) { \AKSRT\User\Level::get_instance()->init(); } if (class_exists('\AKSRT\User\Metrics')) { \AKSRT\User\Metrics::get_instance()->init(); } // WordPress 原生侧栏:支付/订单运营中心(zibll zibpay 对齐) if (is_admin() && class_exists('\AKSRT\Admin\Native\PayMenus')) { \AKSRT\Admin\Native\PayMenus::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayCoupons')) { \AKSRT\Admin\Native\PayCoupons::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayChargeCards')) { \AKSRT\Admin\Native\PayChargeCards::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayShipping')) { \AKSRT\Admin\Native\PayShipping::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayAfterSale')) { \AKSRT\Admin\Native\PayAfterSale::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayOrders')) { \AKSRT\Admin\Native\PayOrders::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayProducts')) { \AKSRT\Admin\Native\PayProducts::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayDownloadLogs')) { \AKSRT\Admin\Native\PayDownloadLogs::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayWithdrawals')) { \AKSRT\Admin\Native\PayWithdrawals::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayIncome')) { \AKSRT\Admin\Native\PayIncome::get_instance()->init(); } if (is_admin() && class_exists('\AKSRT\Admin\Native\PayRebate')) { \AKSRT\Admin\Native\PayRebate::get_instance()->init(); } // WordPress 原生用户菜单:消息/邀请码/认证/禁封(zibll users.php 子菜单对齐) if (is_admin() && class_exists('\AKSRT\Admin\Native\UsersMenus')) { \AKSRT\Admin\Native\UsersMenus::get_instance()->init(); } // ============================================================ // 主题删除时的数据库清理(仅在用户启用清理选项时生效) // uninstall.php 会检查 aksrt_cleanup_on_uninstall 选项 // ============================================================ register_deactivation_hook(__FILE__, function () { // 主题停用时不做任何清理,仅在删除时由 uninstall.php 处理。 // 自定义表(aksrt_*)在主题切换后保留数据,确保重新启用时不丢失。 });