mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-03 02:48:45 +08:00
Added new service classes: Maintenance, Acceleration, Adblock, Avatar, Database, Fonts, Performance, and related templates and assets. Updated Service/Base.php to conditionally instantiate service classes only if they exist. Improved Service/Memory.php and Service/Monitor.php with better settings handling and update logic. Enhanced Service/Setting.php to simplify framework title usage. These changes modularize features and improve plugin extensibility and reliability.
46 lines
No EOL
1 KiB
PHP
Executable file
46 lines
No EOL
1 KiB
PHP
Executable file
<?php
|
|
|
|
namespace WenPai\ChinaYes\Service;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
use function WenPai\ChinaYes\get_settings;
|
|
|
|
/**
|
|
* Class Adblock
|
|
* 广告拦截服务
|
|
* @package WenPai\ChinaYes\Service
|
|
*/
|
|
class Adblock {
|
|
|
|
private $settings;
|
|
|
|
public function __construct() {
|
|
$this->settings = get_settings();
|
|
$this->init();
|
|
}
|
|
|
|
/**
|
|
* 初始化广告拦截功能
|
|
*/
|
|
private function init() {
|
|
if (!empty($this->settings['adblock']) && $this->settings['adblock'] == 'on') {
|
|
add_action('admin_head', [$this, 'load_adblock']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 加载广告拦截
|
|
*/
|
|
public function load_adblock() {
|
|
// 处理广告拦截规则
|
|
foreach ((array) $this->settings['adblock_rule'] as $rule) {
|
|
if (empty($rule['enable']) || empty($rule['selector'])) {
|
|
continue;
|
|
}
|
|
echo sprintf('<style>%s{display:none!important;}</style>',
|
|
htmlspecialchars_decode($rule['selector'])
|
|
);
|
|
}
|
|
}
|
|
} |