wp-china-yes/Service/Adblock.php
feibisi 64748fe6ff Add new service modules and enhance initialization
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.
2025-07-29 17:58:24 +08:00

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'])
);
}
}
}