- Trait-split content-pay, vip-service, balance-service, order-repository - Procedural split of user module into user-parts/* - Split scripts enqueue_public into part-1b/1c; settings bulk trait - Bootstrap: explicit notifications, widgets glob-only, home-modules init - ADR: freeze domain placement for pay/revenue/notify boundaries
70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* AKSRT Scripts & Styles
|
|
*
|
|
* 前端资源加载:CSS、JS、内联样式变量
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class AKSRT_Scripts {
|
|
use AKSRT_Scripts_Part_1b;
|
|
use AKSRT_Scripts_Part_1c;
|
|
use AKSRT_Scripts_Part_2;
|
|
|
|
|
|
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_action('wp_enqueue_scripts', [$this, 'enqueue_public']);
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueue_admin']);
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueue_passive_polyfill'], 1);
|
|
add_action('wp_head', [$this, 'inline_css_vars']);
|
|
add_action('wp_head', [$this, 'output_custom_codes']);
|
|
add_action('wp_body_open', [$this, 'output_loading_overlay'], 1);
|
|
add_action('wp_footer', [$this, 'output_custom_footer_codes'], 99);
|
|
add_action('wp_ajax_aksrt_frontend_debug', [$this, 'handle_frontend_debug']);
|
|
add_action('wp_ajax_nopriv_aksrt_frontend_debug', [$this, 'handle_frontend_debug']);
|
|
add_action('wp_ajax_aksrt_search_history', [$this, 'handle_search_history']);
|
|
add_action('wp_ajax_aksrt_search_suggestions', [$this, 'handle_search_suggestions']);
|
|
add_action('wp_ajax_nopriv_aksrt_search_suggestions', [$this, 'handle_search_suggestions']);
|
|
add_filter('body_class', [$this, 'body_classes']);
|
|
add_filter('wp_resource_hints', [$this, 'resource_hints'], 10, 2);
|
|
}
|
|
|
|
/**
|
|
* 字体 CDN 的 preconnect 提示(提前 DNS + TLS 握手,加速首屏字体加载)
|
|
*/
|
|
public function resource_hints(array $hints, string $relation): array {
|
|
if ('preconnect' === $relation) {
|
|
$hints[] = [
|
|
'href' => 'https://fonts.googleapis.com',
|
|
'crossorigin',
|
|
];
|
|
$hints[] = [
|
|
'href' => 'https://fonts.gstatic.com',
|
|
'crossorigin',
|
|
];
|
|
$hints[] = [
|
|
'href' => 'https://cdn.jsdelivr.net',
|
|
'crossorigin',
|
|
];
|
|
}
|
|
return $hints;
|
|
}
|
|
|
|
}
|
|
|
|
return AKSRT_Scripts::get_instance();
|