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.
This commit is contained in:
feibisi 2025-07-29 17:58:24 +08:00
parent 70af2db0f5
commit 64748fe6ff
29 changed files with 2617 additions and 645 deletions

169
Service/123-Maintenance.php Executable file
View file

@ -0,0 +1,169 @@
<?php
namespace WenPai\ChinaYes\Service;
defined('ABSPATH') || exit;
use function WenPai\ChinaYes\get_settings;
class Maintenance {
private $settings;
private $allowed_pages = [
'wp-login.php',
'wp-register.php',
'wp-cron.php',
'async-upload.php',
'admin-ajax.php'
];
public function __construct() {
// 使用更早的钩子并设置高优先级
add_action('plugins_loaded', [$this, 'init'], 1);
}
public function init() {
$this->settings = get_settings();
// 仅在调试模式下输出调试信息
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('Maintenance Settings Raw: ' . print_r($this->settings, true));
error_log('Maintenance Mode Value: ' . var_export($this->settings['maintenance_mode'], true));
}
// 如果维护模式启用,挂载相关钩子
if ($this->settings['maintenance_mode']) {
add_action('template_redirect', [$this, 'check_maintenance_mode'], 1);
add_action('admin_bar_menu', [$this, 'add_admin_bar_notice'], 100);
add_action('init', [$this, 'check_ajax_maintenance'], 1);
}
}
public function check_ajax_maintenance() {
if (wp_doing_ajax() && !current_user_can('manage_options')) {
wp_die('维护模式已启用');
}
}
public function check_maintenance_mode() {
// 如果是命令行环境,直接返回
if (php_sapi_name() === 'cli') {
return;
}
// 如果是管理员,直接返回
if (current_user_can('manage_options')) {
return;
}
// 检查是否是允许的页面
global $pagenow;
if (in_array($pagenow, $this->allowed_pages)) {
return;
}
// 检查是否是后台请求
if (is_admin()) {
return;
}
// 检查是否是 REST API 请求
if (defined('REST_REQUEST') && REST_REQUEST) {
return;
}
// 检查是否是 AJAX 请求
if (wp_doing_ajax()) {
return;
}
// 显示维护页面
$this->show_maintenance_page();
}
private function show_maintenance_page() {
$maintenance_settings = $this->settings['maintenance_settings'] ?? [];
$title = $maintenance_settings['maintenance_title'] ?? '网站维护中';
$heading = $maintenance_settings['maintenance_heading'] ?? '网站维护中';
$message = $maintenance_settings['maintenance_message'] ?? '网站正在进行例行维护,请稍后访问。感谢您的理解与支持!';
// 添加基本的样式
$style = '
<style>
body {
background: #f1f1f1;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
.maintenance-wrapper {
text-align: center;
padding: 50px 20px;
max-width: 800px;
margin: 100px auto;
background: white;
border-radius: 5px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.maintenance-wrapper h1 {
color: #333;
font-size: 36px;
margin-bottom: 20px;
}
.maintenance-wrapper h2 {
color: #666;
font-size: 24px;
margin-bottom: 30px;
}
.maintenance-message {
color: #555;
line-height: 1.6;
font-size: 16px;
}
</style>
';
$output = $style . sprintf(
'<div class="maintenance-wrapper">
<h1>%s</h1>
<h2>%s</h2>
<div class="maintenance-message">%s</div>
</div>',
esc_html($heading),
esc_html($title),
wp_kses_post($message)
);
// 设置维护模式响应头
if (!headers_sent()) {
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
header('Content-Type: text/html; charset=utf-8');
}
// 确保输出被清空
if (ob_get_level()) {
ob_end_clean();
}
wp_die($output, $title, [
'response' => 503,
'back_link' => false
]);
}
public function add_admin_bar_notice($wp_admin_bar) {
if (!current_user_can('manage_options')) {
return;
}
// 添加调试信息
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('Admin bar notice added for maintenance mode.');
}
$wp_admin_bar->add_node([
'id' => 'maintenance-mode-notice',
'title' => '<span style="color: #ff0000;">维护模式已启用</span>',
'href' => admin_url('admin.php?page=wp-china-yes#tab=脉云维护')
]);
}
}

256
Service/Acceleration.php Executable file
View file

@ -0,0 +1,256 @@
<?php
namespace WenPai\ChinaYes\Service;
defined('ABSPATH') || exit;
use function WenPai\ChinaYes\get_settings;
class Acceleration {
private $settings;
public function __construct() {
$this->settings = get_settings();
$this->init();
}
/**
* 初始化 admincdn 功能
*/
private function init() {
if (!empty($this->settings['admincdn'])) {
add_action('wp_head', function () {
echo "<!-- 此站点使用的前端静态资源库由萌芽加速adminCDN提供智能加速转接基于文派叶子 WPCY.COM -->\n";
}, 1);
}
$this->load_admincdn();
}
/**
* 加载 admincdn 功能
*/
private function load_admincdn() {
// 确保 $this->settings 中包含必要的键
$this->settings['admincdn_files'] = $this->settings['admincdn_files'] ?? [];
$this->settings['admincdn_public'] = $this->settings['admincdn_public'] ?? [];
$this->settings['admincdn_dev'] = $this->settings['admincdn_dev'] ?? [];
// WordPress 核心静态文件链接替换
if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
if (
in_array('admin', (array) $this->settings['admincdn']) &&
!stristr($GLOBALS['wp_version'], 'alpha') &&
!stristr($GLOBALS['wp_version'], 'beta') &&
!stristr($GLOBALS['wp_version'], 'RC')
) {
// 禁用合并加载,以便于使用公共资源节点
global $concatenate_scripts;
$concatenate_scripts = false;
$this->page_str_replace('init', 'preg_replace', [
'~' . home_url('/') . '(wp-admin|wp-includes)/(css|js)/~',
sprintf('https://wpstatic.admincdn.com/%s/$1/$2/', $GLOBALS['wp_version'])
]);
}
}
// 前台静态加速
if (in_array('frontend', (array) $this->settings['admincdn_files'])) {
$this->page_str_replace('template_redirect', 'preg_replace', [
'#(?<=[(\"\'])(?:' . quotemeta(home_url()) . ')?/(?:((?:wp-content|wp-includes)[^\"\')]+\.(css|js)[^\"\')]+))(?=[\"\')])#',
'https://public.admincdn.com/$0'
]);
}
// Google 字体替换
if (in_array('googlefonts', (array) $this->settings['admincdn_public'])) {
$this->page_str_replace('init', 'str_replace', [
'fonts.googleapis.com',
'googlefonts.admincdn.com'
]);
}
// Google 前端公共库替换
if (in_array('googleajax', (array) $this->settings['admincdn_public'])) {
$this->page_str_replace('init', 'str_replace', [
'ajax.googleapis.com',
'googleajax.admincdn.com'
]);
}
// CDNJS 前端公共库替换
if (in_array('cdnjs', (array) $this->settings['admincdn_public'])) {
$this->page_str_replace('init', 'str_replace', [
'cdnjs.cloudflare.com/ajax/libs',
'cdnjs.admincdn.com'
]);
}
// jsDelivr 前端公共库替换
if (in_array('jsdelivr', (array) $this->settings['admincdn_public'])) {
$this->page_str_replace('init', 'str_replace', [
'cdn.jsdelivr.net',
'jsd.admincdn.com'
]);
}
// BootstrapCDN 前端公共库替换
if (in_array('bootstrapcdn', (array) $this->settings['admincdn_public'])) {
$this->page_str_replace('init', 'str_replace', [
'maxcdn.bootstrapcdn.com',
'jsd.admincdn.com'
]);
}
// Emoji 资源加速 - 使用 Twitter Emoji
if (in_array('emoji', (array) $this->settings['admincdn_files'])) {
$this->replace_emoji();
}
// WordPress.org 预览资源加速
if (in_array('sworg', (array) $this->settings['admincdn_files'])) {
$this->replace_sworg();
}
// React 前端库加速
if (in_array('react', (array) $this->settings['admincdn_dev'])) {
$this->page_str_replace('init', 'str_replace', [
'unpkg.com/react',
'jsd.admincdn.com/npm/react'
]);
}
// jQuery 前端库加速
if (in_array('jquery', (array) $this->settings['admincdn_dev'])) {
$this->page_str_replace('init', 'str_replace', [
'code.jquery.com',
'jsd.admincdn.com/npm/jquery'
]);
}
// Vue.js 前端库加速
if (in_array('vuejs', (array) $this->settings['admincdn_dev'])) {
$this->page_str_replace('init', 'str_replace', [
'unpkg.com/vue',
'jsd.admincdn.com/npm/vue'
]);
}
// DataTables 前端库加速
if (in_array('datatables', (array) $this->settings['admincdn_dev'])) {
$this->page_str_replace('init', 'str_replace', [
'cdn.datatables.net',
'jsd.admincdn.com/npm/datatables.net'
]);
}
// Tailwind CSS 加速
if (in_array('tailwindcss', (array) $this->settings['admincdn_dev'])) {
$this->page_str_replace('init', 'str_replace', [
'unpkg.com/tailwindcss',
'jsd.admincdn.com/npm/tailwindcss'
]);
}
}
/**
* 替换 Emoji 资源
*/
private function replace_emoji() {
// 禁用 WordPress 默认的 emoji 处理
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
// 替换 emoji 图片路径
$this->page_str_replace('init', 'str_replace', [
's.w.org/images/core/emoji',
'jsd.admincdn.com/npm/@twemoji/api/dist'
]);
// 替换 wpemojiSettings 配置
add_action('wp_head', function () {
?>
<script>
window._wpemojiSettings = {
"baseUrl": "https://jsd.admincdn.com/npm/@twemoji/api@15.0.3/dist/72x72/",
"ext": ".png",
"svgUrl": "https://jsd.admincdn.com/npm/@twemoji/api@15.0.3/dist/svg/",
"svgExt": ".svg",
"source": {
"concatemoji": "<?php echo includes_url('js/wp-emoji-release.min.js'); ?>"
}
};
</script>
<?php
}, 1);
}
/**
* 替换 WordPress.org 预览资源
*/
private function replace_sworg() {
$this->page_str_replace('init', 'str_replace', [
'ts.w.org',
'ts.wenpai.net'
]);
// 替换主题预览图片 URL
add_filter('theme_screenshot_url', function ($url) {
if (strpos($url, 'ts.w.org') !== false) {
$url = str_replace('ts.w.org', 'ts.wenpai.net', $url);
}
return $url;
});
// 过滤主题 API 响应
add_filter('themes_api_result', function ($res, $action, $args) {
if (is_object($res) && !empty($res->screenshots)) {
foreach ($res->screenshots as &$screenshot) {
if (isset($screenshot->src)) {
$screenshot->src = str_replace('ts.w.org', 'ts.wenpai.net', $screenshot->src);
}
}
}
return $res;
}, 10, 3);
// 替换页面内容
add_action('admin_init', function () {
ob_start(function ($content) {
return str_replace('ts.w.org', 'ts.wenpai.net', $content);
});
});
// 确保前台内容替换
add_action('template_redirect', function () {
ob_start(function ($content) {
return str_replace('ts.w.org', 'ts.wenpai.net', $content);
});
});
}
/**
* 页面字符串替换
*
* @param string $hook 钩子名称
* @param string $replace_func 替换函数
* @param array $param 替换参数
*/
private function page_str_replace($hook, $replace_func, $param) {
if (php_sapi_name() == 'cli') {
return;
}
add_action($hook, function () use ($replace_func, $param) {
ob_start(function ($buffer) use ($replace_func, $param) {
$param[] = $buffer;
return call_user_func_array($replace_func, $param);
});
}, PHP_INT_MAX);
}
}

46
Service/Adblock.php Executable file
View file

@ -0,0 +1,46 @@
<?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'])
);
}
}
}

98
Service/Avatar.php Executable file
View file

@ -0,0 +1,98 @@
<?php
namespace WenPai\ChinaYes\Service;
defined('ABSPATH') || exit;
use function WenPai\ChinaYes\get_settings;
/**
* Class Avatar
* 初认头像服务
* @package WenPai\ChinaYes\Service
*/
class Avatar {
private $settings;
public function __construct() {
$this->settings = get_settings();
$this->init();
}
/**
* 初始化初认头像功能
*/
private function init() {
if (!empty($this->settings['cravatar'])) {
add_filter('user_profile_picture_description', [$this, 'set_user_profile_picture_for_cravatar'], 1);
add_filter('avatar_defaults', [$this, 'set_defaults_for_cravatar'], 1);
add_filter('um_user_avatar_url_filter', [$this, 'get_cravatar_url'], 1);
add_filter('bp_gravatar_url', [$this, 'get_cravatar_url'], 1);
add_filter('get_avatar_url', [$this, 'get_cravatar_url'], 1);
}
}
/**
* 获取 Cravatar URL
*/
public function get_cravatar_url($url) {
switch ($this->settings['cravatar']) {
case 'cn':
return $this->replace_avatar_url($url, 'cn.cravatar.com');
case 'global':
return $this->replace_avatar_url($url, 'en.cravatar.com');
case 'weavatar':
return $this->replace_avatar_url($url, 'weavatar.com');
default:
return $url;
}
}
/**
* 替换头像 URL
*/
public function replace_avatar_url($url, $domain) {
$sources = array(
'www.gravatar.com',
'0.gravatar.com',
'1.gravatar.com',
'2.gravatar.com',
's.gravatar.com',
'secure.gravatar.com',
'cn.gravatar.com',
'en.gravatar.com',
'gravatar.com',
'sdn.geekzu.org',
'gravatar.duoshuo.com',
'gravatar.loli.net',
'dn-qiniu-avatar.qbox.me'
);
return str_replace($sources, $domain, $url);
}
/**
* 设置 WordPress 讨论设置中的默认 LOGO 名称
*/
public function set_defaults_for_cravatar($avatar_defaults) {
if ($this->settings['cravatar'] == 'weavatar') {
$avatar_defaults['gravatar_default'] = 'WeAvatar';
} else {
$avatar_defaults['gravatar_default'] = '初认头像';
}
return $avatar_defaults;
}
/**
* 设置个人资料卡中的头像上传地址
*/
public function set_user_profile_picture_for_cravatar() {
if ($this->settings['cravatar'] == 'weavatar') {
return '<a href="https://weavatar.com" target="_blank">您可以在 WeAvatar 修改您的资料图片</a>';
} else {
return '<a href="https://cravatar.com" target="_blank">您可以在初认头像修改您的资料图片</a>';
}
}
}

View file

@ -11,18 +11,38 @@ defined( 'ABSPATH' ) || exit;
*/ */
class Base { class Base {
public function __construct() { public function __construct() {
// 加速服务 // 确保所有类文件都存在后再实例化
new Super(); if (class_exists(__NAMESPACE__ . '\Super')) {
// 监控服务 new Super();
new Monitor(); }
// 内存服务
new Memory(); if (class_exists(__NAMESPACE__ . '\Monitor')) {
// 更新服务 new Monitor();
new Update(); }
if ( is_admin() ) {
// 设置服务 if (class_exists(__NAMESPACE__ . '\Memory')) {
new Setting(); new Memory();
} }
}
if (class_exists(__NAMESPACE__ . '\Update')) {
new Update();
}
if (class_exists(__NAMESPACE__ . '\Database')) {
new Database();
}
if (class_exists(__NAMESPACE__ . '\Acceleration')) {
new Acceleration();
}
if (class_exists(__NAMESPACE__ . '\Maintenance')) {
new Maintenance();
}
if ( is_admin() && class_exists(__NAMESPACE__ . '\Setting')) {
new Setting();
}
}
} }

0
Service/Comments.php Executable file
View file

92
Service/Database.php Executable file
View file

@ -0,0 +1,92 @@
<?php
namespace WenPai\ChinaYes\Service;
defined( 'ABSPATH' ) || exit;
use function WenPai\ChinaYes\get_settings;
/**
* Class Database
* 数据库工具服务
* @package WenPai\ChinaYes\Service
*/
class Database {
private $settings;
public function __construct() {
$this->settings = get_settings();
// 如果启用了数据库工具,则允许访问数据库修复工具
if ( ! empty( $this->settings['enable_db_tools'] ) && $this->settings['enable_db_tools'] ) {
define( 'WP_ALLOW_REPAIR', true );
}
// 处理调试常量
$this->handle_debug_constants();
// 安全相关常量
$this->handle_security_constants();
}
/**
* 处理调试模式相关常量
*/
private function handle_debug_constants() {
if ( ! empty( $this->settings['enable_debug'] ) && $this->settings['enable_debug'] ) {
// 只有在常量未定义时才定义
if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}
if ( ! empty( $this->settings['debug_options']['wp_debug_log'] ) && ! defined( 'WP_DEBUG_LOG' ) ) {
define( 'WP_DEBUG_LOG', true );
}
if ( ! empty( $this->settings['debug_options']['wp_debug_display'] ) && ! defined( 'WP_DEBUG_DISPLAY' ) ) {
define( 'WP_DEBUG_DISPLAY', true );
}
if ( ! empty( $this->settings['debug_options']['script_debug'] ) && ! defined( 'SCRIPT_DEBUG' ) ) {
define( 'SCRIPT_DEBUG', true );
}
if ( ! empty( $this->settings['debug_options']['save_queries'] ) && ! defined( 'SAVEQUERIES' ) ) {
define( 'SAVEQUERIES', true );
}
} else {
// 禁用调试模式时的默认值
if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', false );
}
if ( ! defined( 'WP_DEBUG_LOG' ) ) {
define( 'WP_DEBUG_LOG', false );
}
if ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
define( 'WP_DEBUG_DISPLAY', false );
}
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
define( 'SCRIPT_DEBUG', false );
}
if ( ! defined( 'SAVEQUERIES' ) ) {
define( 'SAVEQUERIES', false );
}
}
}
/**
* 处理安全相关常量
*/
private function handle_security_constants() {
if ( ! empty( $this->settings['disallow_file_edit'] ) && ! defined( 'DISALLOW_FILE_EDIT' ) ) {
define( 'DISALLOW_FILE_EDIT', $this->settings['disallow_file_edit'] );
}
if ( ! empty( $this->settings['disallow_file_mods'] ) && ! defined( 'DISALLOW_FILE_MODS' ) ) {
define( 'DISALLOW_FILE_MODS', $this->settings['disallow_file_mods'] );
}
if ( ! empty( $this->settings['force_ssl_admin'] ) && ! defined( 'FORCE_SSL_ADMIN' ) ) {
define( 'FORCE_SSL_ADMIN', $this->settings['force_ssl_admin'] );
}
if ( ! empty( $this->settings['force_ssl_login'] ) && ! defined( 'FORCE_SSL_LOGIN' ) ) {
define( 'FORCE_SSL_LOGIN', $this->settings['force_ssl_login'] );
}
}
}

131
Service/Fonts.php Executable file
View file

@ -0,0 +1,131 @@
<?php
namespace WenPai\ChinaYes\Service;
defined('ABSPATH') || exit;
use function WenPai\ChinaYes\get_settings;
/**
* Class Fonts
* 文风字体服务
* @package WenPai\ChinaYes\Service
*/
class Fonts {
private $settings;
public function __construct() {
$this->settings = get_settings();
$this->init();
}
/**
* 初始化文风字体功能
*/
private function init() {
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] != 'off') {
$this->load_typography();
}
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'optimize') {
add_action('init', function () {
wp_enqueue_style('windfonts-optimize', CHINA_YES_PLUGIN_URL . 'assets/css/fonts.css', [], CHINA_YES_VERSION);
});
}
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'on') {
add_action('wp_head', [$this, 'load_windfonts']);
add_action('admin_head', [$this, 'load_windfonts']);
}
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'frontend') {
add_action('wp_head', [$this, 'load_windfonts']);
}
}
/**
* 加载文风字体
*/
public function load_windfonts() {
echo <<<HTML
<link rel="preconnect" href="//cn.windfonts.com">
<!-- 此中文网页字体由文风字体Windfonts免费提供您可以自由引用请务必保留此授权许可标注 https://wenfeng.org/license -->
HTML;
$loaded = [];
foreach ((array) $this->settings['windfonts_list'] as $font) {
if (empty($font['enable'])) {
continue;
}
if (empty($font['family'])) {
continue;
}
if (in_array($font['css'], $loaded)) {
continue;
}
echo sprintf(<<<HTML
<link rel="stylesheet" type="text/css" href="%s">
<style>
%s {
font-style: %s;
font-weight: %s;
font-family: '%s',sans-serif!important;
}
</style>
HTML
,
$font['css'],
htmlspecialchars_decode($font['selector']),
$font['style'],
$font['weight'],
$font['family']
);
$loaded[] = $font['css'];
}
}
/**
* 加载排印优化
*/
public function load_typography() {
// 支持中文排版段首缩进 2em
if (in_array('indent', (array) $this->settings['windfonts_typography'])) {
add_action('wp_head', function () {
echo '<style>
.entry-content p {
text-indent: 2em;
}
.entry-content .wp-block-group p,
.entry-content .wp-block-columns p,
.entry-content .wp-block-media-text p,
.entry-content .wp-block-quote p {
text-indent: 0;
}
</style>';
});
}
// 支持中文排版两端对齐
if (in_array('align', (array) $this->settings['windfonts_typography'])) {
add_action('wp_head', function () {
if (is_single()) { // 仅在文章页面生效
echo '<style>
.entry-content p {
text-align: justify;
}
.entry-content .wp-block-group p,
.entry-content .wp-block-columns p,
.entry-content .wp-block-media-text p,
.entry-content .wp-block-quote p {
text-align: unset !important;
}
.entry-content .wp-block-columns .has-text-align-center {
text-align: center !important;
}
</style>';
}
});
}
}
}

0
Service/Mail.php Executable file
View file

136
Service/Maintenance.php Executable file
View file

@ -0,0 +1,136 @@
<?php
namespace WenPai\ChinaYes\Service;
defined('ABSPATH') || exit;
use function WenPai\ChinaYes\get_settings;
class Maintenance {
private $settings;
public function __construct() {
$this->settings = get_settings();
// 维护模式检查
if (!empty($this->settings['maintenance_mode'])) {
add_action('template_redirect', [$this, 'check_maintenance_mode']);
add_action('admin_bar_menu', [$this, 'add_admin_bar_notice'], 100);
}
// 仪表盘统计信息
if (!empty($this->settings['disk']) && $this->settings['disk']) {
add_action('dashboard_glance_items', [$this, 'add_dashboard_stats']);
add_action('admin_head', [$this, 'add_admin_css']);
}
// 添加登录记录钩子
add_action('wp_login', [$this, 'record_last_login'], 10, 2);
}
// 添加 CSS 样式
public function add_admin_css() {
$screen = get_current_screen();
if ($screen->id === 'dashboard') {
echo '<style>
#dashboard_right_now .stat-item span.dashicons {
margin: 0 3px 0 -25px;
background: white;
position: relative;
z-index: 1;
}
</style>';
}
}
public function add_dashboard_stats($items) {
if (!is_array($items)) {
$items = array();
}
// 获取显示选项设置
$display_options = $this->settings['disk_display'] ?? [];
// 媒体文件统计
if (in_array('media_num', $display_options)) {
$media_count = wp_count_posts('attachment')->inherit;
$items['media'] = sprintf(
'<a href="%s" class="stat-item"><span class="dashicons dashicons-format-gallery"></span> %s</a>',
admin_url('upload.php'),
sprintf(_n('%d 个媒体', '%d 个媒体', $media_count), $media_count)
);
}
// 管理员统计
if (in_array('admin_num', $display_options)) {
$admin_count = count(get_users(['role' => 'administrator', 'fields' => 'ID']));
$items['admins'] = sprintf(
'<a href="%s" class="stat-item"><span class="dashicons dashicons-shield-alt"></span> %s</a>',
admin_url('users.php?role=administrator'),
sprintf(_n('%d 个管理员', '%d 个管理员', $admin_count), $admin_count)
);
}
// 用户总数统计
if (in_array('user_num', $display_options)) {
$total_users = count(get_users(['fields' => 'ID']));
$items['users'] = sprintf(
'<a href="%s" class="stat-item"><span class="dashicons dashicons-groups"></span> %s</a>',
admin_url('users.php'),
sprintf(_n('%d 个用户', '%d 个用户', $total_users), $total_users)
);
}
// 磁盘使用统计
$disk_info = $this->get_disk_usage_info();
if (in_array('disk_usage', $display_options)) {
$items['disk_usage'] = sprintf(
'<span class="stat-item"><span class="dashicons dashicons-database"></span> 磁盘用量:%s / %s</span>',
size_format($disk_info['used']),
size_format($disk_info['total'])
);
}
if (in_array('disk_limit', $display_options)) {
$items['disk_free'] = sprintf(
'<span class="stat-item"><span class="dashicons dashicons-chart-area"></span> 剩余空间:%s (%s%%)</span>',
size_format($disk_info['free']),
round(($disk_info['free'] / $disk_info['total']) * 100, 2)
);
}
// 上次登录时间
if (in_array('lastlogin', $display_options)) {
$current_user_id = get_current_user_id();
$last_login = get_user_meta($current_user_id, 'last_login', true);
$items['lastlogin'] = sprintf(
'<span class="stat-item"><span class="dashicons dashicons-clock"></span> 上次登录:%s</span>',
$last_login ? date('Y.m.d H:i:s', $last_login) : '从未登录'
);
}
return $items;
}
private function get_disk_usage_info() {
$disk_info = get_transient('disk_usage_info');
if (false === $disk_info) {
$upload_dir = wp_upload_dir();
$disk_total = disk_total_space($upload_dir['basedir']);
$disk_free = disk_free_space($upload_dir['basedir']);
$disk_used = $disk_total - $disk_free;
$disk_info = [
'used' => $disk_used,
'total' => $disk_total,
'free' => $disk_free,
];
set_transient('disk_usage_info', $disk_info, HOUR_IN_SECONDS);
}
return $disk_info;
}
public function record_last_login($user_login, $user) {
update_user_meta($user->ID, 'last_login', time());
}
}

0
Service/Media.php Executable file
View file

View file

@ -45,10 +45,6 @@ class Memory {
// 转换为更直观的名称 // 转换为更直观的名称
switch (strtolower($os)) { switch (strtolower($os)) {
case 'linux': case 'linux':
if (file_exists('/etc/os-release')) {
$content = parse_ini_file('/etc/os-release');
return $content['PRETTY_NAME'] ?? 'Linux';
}
return 'Linux'; return 'Linux';
case 'darwin': case 'darwin':
return 'macOS'; return 'macOS';
@ -152,8 +148,18 @@ class Memory {
*/ */
public function add_footer($content) { public function add_footer($content) {
$settings = get_settings(); $settings = get_settings();
// 确保 memory_display 是数组,如果不是则使用空数组
$display_options = is_array($settings['memory_display'] ?? []) ? $settings['memory_display'] : []; // 设置默认显示选项
$default_options = [
'memory_usage',
'wp_limit',
'server_ip',
];
// 如果设置为空或不是数组,使用默认选项
$display_options = isset($settings['memory_display']) && is_array($settings['memory_display'])
? $settings['memory_display']
: $default_options;
// 如果 memory 设置未启用,直接返回原始内容 // 如果 memory 设置未启用,直接返回原始内容
if (empty($settings['memory'])) { if (empty($settings['memory'])) {
@ -165,6 +171,7 @@ public function add_footer($content) {
$this->os_info = $this->get_os_info(); $this->os_info = $this->get_os_info();
$footer_parts = []; $footer_parts = [];
// 内存使用量 // 内存使用量
if (in_array('memory_usage', $display_options)) { if (in_array('memory_usage', $display_options)) {
@ -251,4 +258,16 @@ public function add_footer($content) {
); );
} }
} }
/**
* 更新设置
*/
private function update_settings() {
if ( is_multisite() ) {
update_site_option( 'wp_china_yes', $this->settings );
} else {
update_option( 'wp_china_yes', $this->settings, true );
}
}
} }

View file

@ -1,171 +1,172 @@
<?php <?php
namespace WenPai\ChinaYes\Service; namespace WenPai\ChinaYes\Service;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use function WenPai\ChinaYes\get_settings; use function WenPai\ChinaYes\get_settings;
/** /**
* Class Monitor * Class Monitor
* 插件监控服务 * 插件监控服务
* @package WenPai\ChinaYes\Service * @package WenPai\ChinaYes\Service
*/ */
class Monitor { class Monitor {
private $settings; private $settings;
public function __construct() { public function __construct() {
$this->settings = get_settings(); $this->settings = get_settings();
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_store' ); // TODO 下个版本移除 wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_store' ); // TODO 下个版本移除
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_cravatar' ); // TODO 下个版本移除 wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_cravatar' ); // TODO 下个版本移除
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_admincdn' ); // TODO 下个版本移除 wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_admincdn' ); // TODO 下个版本移除
if ( $this->settings['monitor'] ) { if ( $this->settings['monitor'] ) {
// 站点网络下只在主站运行 // 站点网络下只在主站运行
if ( is_main_site() ) { if ( is_main_site() ) {
add_action( 'init', [ $this, 'init' ] ); add_action( 'init', [ $this, 'init' ] );
add_action( 'wp_china_yes_monitor', [ add_action( 'wp_china_yes_monitor', [
$this, $this,
'run_monitor' 'run_monitor'
] ); ] );
} }
} else { } else {
wp_clear_scheduled_hook( 'wp_china_yes_monitor' ); wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
} }
} }
/** /**
* 初始化 * 初始化
*/ */
public function init() { public function init() {
if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) { if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) {
wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor' ); wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor' );
} }
} }
/** /**
* 运行监控 * 运行监控
*/ */
public function run_monitor() { public function run_monitor() {
if ( $this->settings['store'] != 'off' ) { if ( $this->settings['store'] != 'off' ) {
$this->maybe_check_store(); $this->maybe_check_store();
} }
if ( $this->settings['cravatar'] != 'off' ) { if ( $this->settings['cravatar'] != 'off' ) {
$this->maybe_check_cravatar(); $this->maybe_check_cravatar();
} }
if ( ! empty( $this->settings['admincdn'] ) ) { if ( ! empty( $this->settings['admincdn'] ) ) {
$this->maybe_check_admincdn(); $this->maybe_check_admincdn();
} }
} }
/** /**
* 检查应用市场可用性 * 检查应用市场可用性
*/ */
public function maybe_check_store() { public function maybe_check_store() {
$test_url = 'https://api.wenpai.net/china-yes/version-check'; $test_url = 'https://api.wenpai.net/china-yes/version-check';
if ( $this->settings['store'] == 'proxy' ) { if ( $this->settings['store'] == 'proxy' ) {
$test_url = 'https://api.wpmirror.com/core/version-check/1.7/'; $test_url = 'https://api.wpmirror.com/core/version-check/1.7/';
} }
$response = wp_remote_get( $test_url ); $response = wp_remote_get( $test_url );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
if ( $this->settings['store'] == 'wenpai' ) { if ( $this->settings['store'] == 'wenpai' ) {
$this->settings['store'] = 'proxy'; $this->settings['store'] = 'proxy';
} elseif ( $this->settings['store'] == 'proxy' ) { } elseif ( $this->settings['store'] == 'proxy' ) {
$this->settings['store'] = 'off'; $this->settings['store'] = 'off';
} }
$this->update_settings(); $this->update_settings();
} }
} }
/** /**
* 检查初认头像可用性 * 检查初认头像可用性
*/ */
public function maybe_check_cravatar() { public function maybe_check_cravatar() {
$test_url = 'https://cn.cravatar.com/avatar/'; $test_url = 'https://cn.cravatar.com/avatar/';
switch ( $this->settings['cravatar'] ) { switch ( $this->settings['cravatar'] ) {
case 'global': case 'global':
$test_url = 'https://en.cravatar.com/avatar/'; $test_url = 'https://en.cravatar.com/avatar/';
break; break;
case 'weavatar': case 'weavatar':
$test_url = 'https://weavatar.com/avatar/'; $test_url = 'https://weavatar.com/avatar/';
break; break;
} }
$response = wp_remote_get( $test_url ); $response = wp_remote_get( $test_url );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
if ( $this->settings['cravatar'] == 'cn' ) { if ( $this->settings['cravatar'] == 'cn' ) {
$this->settings['cravatar'] = 'global'; $this->settings['cravatar'] = 'global';
} elseif ( $this->settings['cravatar'] == 'global' ) { } elseif ( $this->settings['cravatar'] == 'global' ) {
$this->settings['cravatar'] = 'weavatar'; $this->settings['cravatar'] = 'weavatar';
} elseif ( $this->settings['cravatar'] == 'weavatar' ) { } elseif ( $this->settings['cravatar'] == 'weavatar' ) {
$this->settings['cravatar'] = 'cn'; $this->settings['cravatar'] = 'cn';
} }
$this->update_settings(); $this->update_settings();
} }
} }
/** /**
* 检查萌芽加速可用性 * 检查萌芽加速可用性
*/ */
public function maybe_check_admincdn() { public function maybe_check_admincdn() {
// 后台加速 // 后台加速
if ( in_array( 'admin', $this->settings['admincdn'] ) ) { if ( in_array( 'admin', $this->settings['admincdn'] ) ) {
$response = wp_remote_get( 'https://wpstatic.admincdn.com/6.7/wp-includes/js/wp-sanitize.min.js' ); $response = wp_remote_get( 'https://wpstatic.admincdn.com/6.7/wp-includes/js/wp-sanitize.min.js' );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
// 前台加速 // 前台加速
if ( in_array( 'frontend', $this->settings['admincdn'] ) ) { if ( in_array( 'frontend', $this->settings['admincdn'] ) ) {
$url = network_site_url( '/wp-includes/js/wp-sanitize.min.js' ); $url = network_site_url( '/wp-includes/js/wp-sanitize.min.js' );
$response = wp_remote_get( 'https://public.admincdn.com/' . $url ); $response = wp_remote_get( 'https://public.admincdn.com/' . $url );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'frontend' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'frontend' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
// Google 字体 // Google 字体
if ( in_array( 'googlefonts', $this->settings['admincdn'] ) ) { if ( in_array( 'googlefonts', $this->settings['admincdn'] ) ) {
$response = wp_remote_get( 'https://googlefonts.admincdn.com/css?family=Roboto:400,700' ); $response = wp_remote_get( 'https://googlefonts.admincdn.com/css?family=Roboto:400,700' );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googlefonts' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googlefonts' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
// Google 前端公共库 // Google 前端公共库
if ( in_array( 'googleajax', $this->settings['admincdn'] ) ) { if ( in_array( 'googleajax', $this->settings['admincdn'] ) ) {
$response = wp_remote_get( 'https://googleajax.admincdn.com/ajax/libs/jquery/3.7.1/jquery.slim.min.js' ); $response = wp_remote_get( 'https://googleajax.admincdn.com/ajax/libs/jquery/3.7.1/jquery.slim.min.js' );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googleajax' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googleajax' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
// CDNJS 前端公共库 // CDNJS 前端公共库
if ( in_array( 'cdnjs', $this->settings['admincdn'] ) ) { if ( in_array( 'cdnjs', $this->settings['admincdn'] ) ) {
$response = wp_remote_get( 'https://cdnjs.admincdn.com/jquery/3.7.1/jquery.slim.min.js' ); $response = wp_remote_get( 'https://cdnjs.admincdn.com/jquery/3.7.1/jquery.slim.min.js' );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'cdnjs' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'cdnjs' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
// jsDelivr 公共库 // jsDelivr 公共库
if ( in_array( 'jsdelivr', $this->settings['admincdn'] ) ) { if ( in_array( 'jsdelivr', $this->settings['admincdn'] ) ) {
$response = wp_remote_get( 'https://jsd.admincdn.com/npm/jquery@3.7.1/dist/jquery.slim.min.js' ); $response = wp_remote_get( 'https://jsd.admincdn.com/npm/jquery@3.7.1/dist/jquery.slim.min.js' );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'jsdelivr' ] ) ); $this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'jsdelivr' ] ) );
$this->update_settings(); $this->update_settings();
} }
} }
} }
/**
* 更新设置 /**
*/ * 更新设置
private function update_settings() { */
if ( is_multisite() ) { private function update_settings() {
update_site_option( 'wp_china_yes', $this->settings ); if ( is_multisite() ) {
} else { update_site_option( 'wp_china_yes', $this->settings );
update_option( 'wp_china_yes', $this->settings, true ); } else {
} update_option( 'wp_china_yes', $this->settings, true );
} }
} }
}

2
Service/Performance.php Executable file
View file

@ -0,0 +1,2 @@
<?php

File diff suppressed because one or more lines are too long

View file

@ -31,148 +31,152 @@ class Super {
/** /**
* 添加「文派茶馆」小组件 * 添加「文派茶馆」小组件
*/ */
if ( is_admin() ) { if ( is_admin() ) {
add_action( 'wp_dashboard_setup', function () { add_action( 'wp_dashboard_setup', function () {
global $wp_meta_boxes; global $wp_meta_boxes;
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] ); unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', function () { wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', function () {
echo <<<HTML $default_rss_url = 'https://wptea.com/feed/';
<div class="wordpress-news hide-if-no-js"> $custom_rss_url = $this->settings['custom_rss_url'] ?? '';
<div class="rss-widget"> $refresh_interval = $this->settings['custom_rss_refresh'] ?? 3600;
$rss_display_options = $this->settings['rss_display_options'] ?? ['show_date', 'show_summary', 'show_footer'];
if (!is_array($rss_display_options)) {
$rss_display_options = explode(',', $rss_display_options);
}
// 获取默认的 RSS 源内容
$default_rss = fetch_feed($default_rss_url);
$default_items = [];
if (!is_wp_error($default_rss)) {
$default_items = $default_rss->get_items(0, 5);
}
$custom_items = [];
$custom_rss = null;
$custom_rss_latest_date = 0;
if (!empty($custom_rss_url)) {
$transient_key = 'wenpai_tea_custom_rss_' . md5($custom_rss_url);
$cached_custom_items = get_transient($transient_key);
if (false === $cached_custom_items) {
$custom_rss = fetch_feed($custom_rss_url);
if (!is_wp_error($custom_rss)) {
$custom_items = $custom_rss->get_items(0, 2);
if (!empty($custom_items)) {
$custom_rss_latest_date = $custom_items[0]->get_date('U');
}
set_transient($transient_key, $custom_items, $refresh_interval);
}
} else {
$custom_items = $cached_custom_items;
if (!empty($custom_items)) {
$custom_rss_latest_date = $custom_items[0]->get_date('U');
}
}
}
$three_days_ago = time() - (3 * 24 * 60 * 60);
if ($custom_rss_latest_date > $three_days_ago) {
$items = array_merge(array_slice($default_items, 0, 3), $custom_items);
} else {
$items = array_slice($default_items, 0, 5);
}
if (is_wp_error($custom_rss)) {
$items = array_slice($default_items, 0, 5);
}
echo <<<HTML
<div class="wordpress-news hide-if-no-js">
<div class="rss-widget">
HTML; HTML;
wp_widget_rss_output( 'https://wptea.com/feed/', [ foreach ($items as $item) {
'items' => 5, echo '<div class="rss-item">';
'show_summary' => 1, echo '<a href="' . esc_url($item->get_permalink()) . '" target="_blank">' . esc_html($item->get_title()) . '</a>';
] ); if (in_array('show_date', $rss_display_options)) {
echo <<<HTML echo '<span class="rss-date">' . esc_html($item->get_date('Y.m.d')) . '</span>';
</div> }
</div> if (in_array('show_summary', $rss_display_options)) {
<p class="community-events-footer"> echo '<div class="rss-summary">' . esc_html(wp_trim_words($item->get_description(), 45, '...')) . '</div>';
<a href="https://wenpai.org/" target="_blank">文派开源</a> }
| echo '</div>';
<a href="https://wenpai.org/support" target="_blank">支持论坛</a> }
|
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a> echo <<<HTML
| </div>
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a> </div>
</p>
<style>
#wenpai_tea .rss-widget {
font-size:13px;
padding:0 12px
}
#wenpai_tea .rss-widget:last-child {
border-bottom:none;
padding-bottom:8px
}
#wenpai_tea .rss-widget a {
font-weight:400
}
#wenpai_tea .rss-widget span,
#wenpai_tea .rss-widget span.rss-date {
color:#646970
}
#wenpai_tea .rss-widget span.rss-date {
margin-left:12px
}
#wenpai_tea .rss-widget ul li {
padding:4px 0;
margin:0
}
#wenpai_tea .community-events-footer a {
line-height: 2;
padding: 0.5em;
}
</style>
HTML; HTML;
} ); if (in_array('show_footer', $rss_display_options)) {
} ); echo <<<HTML
add_action( 'wp_network_dashboard_setup', function () { <p class="community-events-footer">
global $wp_meta_boxes; <a href="https://wenpai.org/" target="_blank">文派开源</a>
|
unset( $wp_meta_boxes['dashboard-network']['side']['core']['dashboard_primary'] ); <a href="https://wenpai.org/support" target="_blank">支持论坛</a>
wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', function () { |
echo <<<HTML <a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
<div class="wordpress-news hide-if-no-js"> |
<div class="rss-widget"> <a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
</p>
HTML; HTML;
wp_widget_rss_output( 'https://wptea.com/feed/', [ }
'items' => 5, echo <<<HTML
'show_summary' => 1, <style>
] ); #wenpai_tea .rss-widget {
echo <<<HTML padding: 0 12px;
</div> }
</div> #wenpai_tea .rss-widget:last-child {
<p class="community-events-footer"> border-bottom: none;
<a href="https://wenpai.org/" target="_blank">文派开源</a> padding-bottom: 8px;
| }
<a href="https://wenpai.org/support" target="_blank">支持论坛</a> #wenpai_tea .rss-item {
| margin-bottom: 10px;
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a> padding-bottom: 10px;
| border-bottom: 1px solid #eee;
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a> }
</p> #wenpai_tea .rss-item:last-child {
<style> border-bottom: none;
#wenpai_tea .rss-widget { margin-bottom: 0;
font-size:13px; padding-bottom: 0;
padding:0 12px }
} #wenpai_tea .rss-item a {
#wenpai_tea .rss-widget:last-child { text-decoration: none;
border-bottom:none; display: block;
padding-bottom:8px margin-bottom: 5px;
} }
#wenpai_tea .rss-widget a { #wenpai_tea .rss-date {
font-weight:400 color: #666;
} font-size: 12px;
#wenpai_tea .rss-widget span, display: block;
#wenpai_tea .rss-widget span.rss-date { margin-bottom: 8px;
color:#646970 }
} #wenpai_tea .rss-summary {
#wenpai_tea .rss-widget span.rss-date { color: #444;
margin-left:12px font-size: 13px;
} line-height: 1.5;
#wenpai_tea .rss-widget ul li { }
padding:4px 0; #wenpai_tea .community-events-footer {
margin:0 margin-top: 15px;
} padding-top: 15px;
#wenpai_tea .community-events-footer a { padding-bottom: 5px;
line-height: 2; border-top: 1px solid #eee;
padding: 0.5em; text-align: center;
} }
</style> #wenpai_tea .community-events-footer a {
text-decoration: none;
margin: 0 5px;
}
#wenpai_tea .community-events-footer a:hover {
text-decoration: underline;
}
</style>
HTML; HTML;
} ); });
} ); });
} }
/**
* WordPress 核心静态文件链接替换
*/
if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
if (
in_array( 'admin', (array) $this->settings['admincdn'] ) &&
! stristr( $GLOBALS['wp_version'], 'alpha' ) &&
! stristr( $GLOBALS['wp_version'], 'beta' ) &&
! stristr( $GLOBALS['wp_version'], 'RC' )
) {
// 禁用合并加载,以便于使用公共资源节点
global $concatenate_scripts;
$concatenate_scripts = false;
$this->page_str_replace( 'init', 'preg_replace', [
'~' . home_url( '/' ) . '(wp-admin|wp-includes)/(css|js)/~',
sprintf( 'https://wpstatic.admincdn.com/%s/$1/$2/', $GLOBALS['wp_version'] )
] );
}
}
/**
* adminCDN
*/
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
$this->load_admincdn();
}
/** /**
* 初认头像 * 初认头像
@ -214,6 +218,14 @@ HTML;
add_action( 'admin_head', [ $this, 'load_adblock' ] ); add_action( 'admin_head', [ $this, 'load_adblock' ] );
} }
} }
/**
* 通知管理
*/
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
if ( ! empty( $this->settings['notice_block'] ) && $this->settings['notice_block'] == 'on' ) {
add_action( 'admin_head', [ $this, 'load_notice_management' ] );
}
}
/** /**
* 飞行模式 * 飞行模式
@ -223,70 +235,7 @@ HTML;
} }
} }
/**
* 加载 adminCDN
*/
public function load_admincdn() {
/**
* 前台静态加速
*/
if ( in_array( 'frontend', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'template_redirect', 'preg_replace', [
'#(?<=[(\"\'])(?:' . quotemeta( home_url() ) . ')?/(?:((?:wp-content|wp-includes)[^\"\')]+\.(css|js)[^\"\')]+))(?=[\"\')])#',
'https://public.admincdn.com/$0'
] );
}
/**
* Google 字体替换
*/
if ( in_array( 'googlefonts', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'fonts.googleapis.com',
'googlefonts.admincdn.com'
] );
}
/**
* Google 前端公共库替换
*/
if ( in_array( 'googleajax', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'ajax.googleapis.com',
'googleajax.admincdn.com'
] );
}
/**
* CDNJS 前端公共库替换
*/
if ( in_array( 'cdnjs', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'cdnjs.cloudflare.com/ajax/libs',
'cdnjs.admincdn.com'
] );
}
/**
* jsDelivr 前端公共库替换
*/
if ( in_array( 'jsdelivr', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'cdn.jsdelivr.net',
'jsd.admincdn.com'
] );
}
/**
* BootstrapCDN 前端公共库替换
*/
if ( in_array( 'bootstrapcdn', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'maxcdn.bootstrapcdn.com',
'jsd.admincdn.com'
] );
}
}
/** /**
@ -470,6 +419,7 @@ HTML
// 支持中文排版两端对齐 // 支持中文排版两端对齐
if ( in_array( 'align', (array) $this->settings['windfonts_typography'] ) ) { if ( in_array( 'align', (array) $this->settings['windfonts_typography'] ) ) {
add_action( 'wp_head', function () { add_action( 'wp_head', function () {
if ( is_single() ) { // 仅在文章页面生效
echo '<style> echo '<style>
.entry-content p { .entry-content p {
text-align: justify; text-align: justify;
@ -480,38 +430,124 @@ HTML
.entry-content .wp-block-quote p { .entry-content .wp-block-quote p {
text-align: unset !important; text-align: unset !important;
} }
.entry-content .wp-block-columns p.has-text-align-center { .entry-content .wp-block-columns .has-text-align-center {
text-align: center !important; text-align: center !important;
} }
</style>'; </style>';
}
} ); } );
} }
} }
/** /**
* 加载广告拦截 * 加载广告拦截
*/ */
public function load_adblock() { public function load_adblock() {
foreach ( (array) $this->settings['adblock_rule'] as $rule ) { if (empty($this->settings['adblock']) || $this->settings['adblock'] !== 'on') {
if ( empty( $rule['enable'] ) ) { return;
continue; }
}
if ( empty( $rule['selector'] ) ) { // 处理广告拦截规则
continue; foreach ( (array) $this->settings['adblock_rule'] as $rule ) {
} if ( empty( $rule['enable'] ) || empty( $rule['selector'] ) ) {
echo sprintf( <<<HTML continue;
<style> }
%s { echo sprintf( '<style>%s{display:none!important;}</style>',
display: none!important; htmlspecialchars_decode( $rule['selector'] )
} );
</style> }
HTML }
,
htmlspecialchars_decode( $rule['selector'] )
); /**
} * 加载通知管理
} */
public function load_notice_management() {
// 首先检查是否启用通知管理功能
if (empty($this->settings['notice_block']) || $this->settings['notice_block'] !== 'on') {
return;
}
// 检查是否启用全局禁用
if (!empty($this->settings['disable_all_notices'])) {
$this->disable_all_notices();
echo '<style>.notice,.notice-error,.notice-warning,.notice-success,.notice-info,.updated,.error,.update-nag{display:none!important;}</style>';
return;
}
// 处理选择性禁用
$selected_notices = $this->settings['notice_control'] ?? [];
$notice_method = $this->settings['notice_method'] ?? 'hook';
if (!empty($selected_notices)) {
// 处理钩子移除
if (in_array($notice_method, ['hook', 'both'])) {
$this->disable_selected_notices($selected_notices);
}
// 处理 CSS 隐藏
if (in_array($notice_method, ['css', 'both'])) {
$this->apply_notice_css($selected_notices);
}
}
}
/**
* 应用通知 CSS 隐藏
*/
private function apply_notice_css($selected_notices) {
$selectors = [];
foreach ($selected_notices as $type) {
switch ($type) {
case 'error':
$selectors[] = '.notice-error,.error';
break;
case 'warning':
$selectors[] = '.notice-warning';
break;
case 'success':
$selectors[] = '.notice-success,.updated';
break;
case 'info':
$selectors[] = '.notice-info';
break;
case 'core':
$selectors[] = '.update-nag';
break;
}
}
if (!empty($selectors)) {
echo '<style>' . implode(',', $selectors) . '{display:none!important;}</style>';
}
}
/**
* 移除所有管理通知
*/
private function disable_all_notices() {
remove_all_actions('admin_notices');
remove_all_actions('all_admin_notices');
remove_all_actions('user_admin_notices');
remove_all_actions('network_admin_notices');
}
/**
* 禁用选定的通知类型
*/
private function disable_selected_notices($types) {
if (in_array('core', $types)) {
remove_action('admin_notices', 'update_nag', 3);
remove_action('admin_notices', 'maintenance_nag', 10);
add_filter('pre_site_transient_update_core', '__return_null');
add_filter('pre_site_transient_update_plugins', '__return_null');
add_filter('pre_site_transient_update_themes', '__return_null');
}
}
/** /**
* 加载飞行模式 * 加载飞行模式

View file

@ -82,7 +82,7 @@
margin-right: 0px; margin-right: 0px;
} }
.wp_china_yes-field.wp_china_yes-field-radio, .wp_china_yes-field-checkbox, .wp_china_yes-field-group, .wp_china_yes-field-switcher, .wp_china_yes-field-text { .wp_china_yes-field {
padding: 8%; padding: 8%;
background-color: #ffffff; background-color: #ffffff;
margin: 5% 0; margin: 5% 0;
@ -90,10 +90,32 @@
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04); box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
} }
.wp_china_yes-field.wp_china_yes-field-content {
padding: 0;
background-color: rgba(255, 255, 255, 0);
margin: 0;
border-radius: 0;
box-shadow: unset;
}
.wp_china_yes-field-checkbox .wp_china_yes--inline-list li, .wp_china_yes-field-radio .wp_china_yes--inline-list li { .wp_china_yes-field-checkbox .wp_china_yes--inline-list li, .wp_china_yes-field-radio .wp_china_yes--inline-list li {
margin-right: 20px; margin-right: 20px;
} }
.wp_china_yes-copyright p {
font-size: 12px;
color: #999;
}
.wp_china_yes-copyright {
float: left;
margin-top: 25px;
margin-bottom: 35px;
text-align: center;
width: 100%;
font-size: 12px;
zoom: 90%;
}
.wp_china_yes-section { .wp_china_yes-section {
margin: 50px auto; margin: 50px auto;
max-width: 1000px; max-width: 1000px;
@ -108,9 +130,8 @@
.wp_china_yes-field+.wp_china_yes-field { .wp_china_yes-field+.wp_china_yes-field {
border-top: 0px solid #eee; border-top: 0px solid #eee;
} }
.wp_china_yes-field-fieldset .wp_china_yes-fieldset-content {
.wp_china_yes-field.wp_china_yes-field-content { border: 0px solid #ccd0d4;
padding: 0px;
} }
.wp_china_yes-section-title { .wp_china_yes-section-title {

BIN
assets/images/wpcy-logo.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

33
assets/js/script.js Executable file
View file

@ -0,0 +1,33 @@
jQuery(document).ready(function($) {
$("#test-rss-feed").click(function() {
var button = $(this);
var result = $("#rss-test-result");
var feedUrl = $("#custom_rss_url").val();
if (!feedUrl) {
result.html('<span style="color: red;">请先填写 RSS 源地址</span>');
return;
}
button.prop("disabled", true);
result.html("测试中...");
$.post(ajaxurl, {
action: "test_rss_feed",
_ajax_nonce: '<?php echo wp_create_nonce("wp_china_yes_nonce"); ?>',
feed_url: feedUrl
})
.done(function(response) {
result.html(response.success ?
'<span style="color: green;">' + response.data + '</span>' :
'<span style="color: red;">' + response.data + '</span>'
);
})
.fail(function() {
result.html('<span style="color: red;">测试失败</span>');
})
.always(function() {
button.prop("disabled", false);
});
});
});

0
changelog.txt Normal file → Executable file
View file

0
composer.json Normal file → Executable file
View file

0
composer.lock generated Normal file → Executable file
View file

64
copyright.txt Normal file → Executable file
View file

@ -1,28 +1,36 @@
----------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------
**Copyright © 2025 WenPai.cn (Guangzhou) Technology Co., Ltd.** **Copyright © 2025 WenPai.cn (Guangzhou) Technology Co., Ltd.**
----------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------
**Compliance Terms** **Compliance Terms**
Everyone is free to use Wenpai open-source software. However, in China, when using Wenpai software, you must adhere to the GPL open-source license, respect the intellectual property rights of others, and prioritize compliance with Chinese laws in case of any conflicts. Everyone is free to use WenPai open-source software.However, in China, when using WenPai software,
you must adhere to the GPL open-source license, respect the intellectual property rights of others,
**Fork Declaration** and prioritize compliance with Chinese laws in case of any conflicts.
To ensure the long-term availability of various Wenpai (WordPress) infrastructure components, individuals with the necessary capabilities are welcome to establish their own service sources or fork Wenpai Leaf 🍃 (WPCY) to create their own versions.
**Fork Declaration**
**The Only Requirement:** To ensure the long-term availability of various Wenpai (WordPress) infrastructure components,
While strictly adhering to the GPL license, you must respect all lawful rights of Wenpai Technology, including (but not limited to) copyrights, trademarks, patents, intellectual property, goodwill, and more. individuals with the necessary capabilities are welcome to establish their own service sources
or fork WenPai Leaf 🍃 WP-China-Yes (WPCY) to create their own versions.
-----------------------------------------------------------------------------------------
**版权所有 © 2025 年 文派(广州)科技有限公司** **The Only Requirement:**
----------------------------------------------------------------------------------------- While strictly adhering to the GPL license, you must respect all lawful rights of WenPai Technology,
including (but not limited to) copyrights, trademarks, patents, intellectual property, goodwill, and more.
**合规条款**
任何人都可以自由使用文派开源软件,但在中国,当您使用文派软件时,您应在遵守 GPL 开源协议的同时,尊重他人的知识产权,同时有违背中国法律的情况时皆以中国法律为准。 -----------------------------------------------------------------------------------------
**版权所有 © 2025 年 文派(广州)科技有限公司**
**分叉声明** -----------------------------------------------------------------------------------------
为保障各项文派 WordPress 基础设施的长久可用性欢迎有能力的人自建各类服务源以及分叉文派叶子🍃WPCY来制作您自己的版本
**合规条款**
**唯一要求:** 任何人都可以自由使用文派开源软件,但在中国,当您使用文派软件时,您应在遵守 GPL 开源协议的同时,
在严格遵守 GPL 协议的前提下,尊重文派科技的各项合法权益,包括 (不限于) 版权、商标、专利、知识产权、商誉等… 尊重他人的知识产权,同时有违背中国法律的情况时皆以中国法律为准。
**分叉声明**
为保障各项文派 WordPress 基础设施的长久可用性,
欢迎有能力的人自建各类服务源以及分叉文派叶子🍃WPCY来制作您自己的版本
**唯一要求:**
在严格遵守 GPL 协议的前提下,尊重文派科技的各项合法权益,
包括 (不限于) 版权、商标、专利、知识产权、商誉等…

View file

@ -497,9 +497,19 @@ if ( ! class_exists( 'WP_CHINA_YES_Options' ) ) {
echo '<div class="wp_china_yes-header'. esc_attr( $sticky_class ) .'">'; echo '<div class="wp_china_yes-header'. esc_attr( $sticky_class ) .'">';
echo '<div class="wp_china_yes-header-inner">'; echo '<div class="wp_china_yes-header-inner">';
echo '<div class="wp_china_yes-header-left">'; echo '<div class="wp_china_yes-header-left">';
echo '<h1>'. $this->args['framework_title'] .'</h1>'; $hide_elements = !empty($this->options['hide_elements']) ? $this->options['hide_elements'] : [];
echo '</div>'; if (!in_array('hide_logo', $hide_elements)) {
$logo_url = !empty($this->options['header_logo']['url']) ? $this->options['header_logo']['url'] : plugins_url('wp-china-yes/assets/images/wpcy-logo.png');
echo '<img src="' . esc_url($logo_url) . '" alt="WPCY Logo" class="wp-china-yes-logo" style="float: left; height: 26px; vertical-align: middle; margin-right: 10px;" />';
}
if (!in_array('hide_title', $hide_elements)) {
echo '<h1>'. $this->args['framework_title'] .'</h1>';
}
if (!in_array('hide_version', $hide_elements)) {
echo '<small> &nbsp; v' . CHINA_YES_VERSION . '</small>';
}
echo '</div>';
echo '<div class="wp_china_yes-header-right">'; echo '<div class="wp_china_yes-header-right">';
@ -572,6 +582,12 @@ if ( ! class_exists( 'WP_CHINA_YES_Options' ) ) {
echo '</ul>'; echo '</ul>';
echo '<div class="wp_china_yes-copyright">';
echo '<p>Copyright © 2025 · WPCY.COM</p>';
echo '<p>文派叶子·生生不息</p>';
echo '</div>';
echo '</div>'; echo '</div>';
} }
@ -625,8 +641,13 @@ if ( ! class_exists( 'WP_CHINA_YES_Options' ) ) {
echo '</div>'; echo '</div>';
echo '<div class="wp_china_yes-copyright">';
echo '<p>此服务由 文派开源WenPai.org 提供生态接入。</p>';
echo '</div>';
echo '<div class="clear"></div>'; echo '<div class="clear"></div>';
echo '</div>'; echo '</div>';
echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="wp_china_yes-nav-background"></div>' : ''; echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="wp_china_yes-nav-background"></div>' : '';

48
templates/about-section.php Executable file
View file

@ -0,0 +1,48 @@
<?php
// about-section.php
?>
<div class="wpcy-about__section">
<div class="wpcy-about__grid columns-1">
<div class="column wpcy-kit-banner"><span class="wpcy-icon-inner"> <i class="icon icon-archive-1"></i></span>
<h2>项目简介</h2>
<p>文派WordPress中国本土化项目始于 2019 年,由 文派叶子🍃WPCY 插件开启,其前身为 WP-China-Yes。
</p>
<p>2023 4 月,文派科技完成对该项目的收购,并对其进行了全面的品牌重塑。</p>
<p></p>
<div class="wpcy-buttons"><a href="https://wpcy.com/about" target="_blank" rel="noopener" class="components-button button-secondary">关于 WPCY </a><a href="/wp-content/plugins/wp-china-yes/changelog.txt" target="_blank" rel="noopener" class="components-button button-secondary">更新日志 </a></div>
</div>
<div class="column wpcy-kit-banner"><span class="wpcy-icon-inner"> <i class="icon icon-lovely"></i></span>
<h2>赞助支持</h2>
<p>特别感谢以下企业品牌对文派项目提供的资金资源支持。早期伙伴未来有机会共享文派生态资源,期待社会各界参与。</p>
<div class="card-body sponsor-logos">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/feibisi-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/shujue-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/upyun-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/haozi-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/wpsaas-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/lingding-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/weixiaoduo-logo-2020.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/modiqi-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/kekechong-logo.png">
<img src="https://cravatar.cn/wp-content/uploads/2024/09/wenpai-logo@2X.png">
</div>
<div class="wpcy-buttons"><a href="https://wpcy.com/ecosystem" target="_blank" rel="noopener" class="components-button button-secondary">生态共建 </a><a href="https://wpcy.com/about/investor" target="_blank" rel="noopener" class="components-button button-secondary">项目投资 </a></div>
</div>
</div>
<div class="wpcy-about__grid columns-1">
<div class="column wpcy-kit-banner"><span class="wpcy-icon-inner"> <i class="icon icon-user-octagon"></i></span>
<h2>开发 &amp; 贡献者</h2>
<p>100% 开源代码,诚邀您一起参与文派 WordPress 软件国产化进程,打造属于自己的开源自助建站程序。</p>
<div class="card-body contributors-name">
<a href="https://github.com/sunxiyuan" target="_blank">孙锡源</a><a href="https://github.com/devhaozi/" target="_blank">耗子</a><a href="https://github.com/Yulinn233/" target="_blank">Yulinn</a><a href="https://github.com/zhaofeng-shu33/" target="_blank">赵丰</a>
<a
href="https://github.com/djl0415/" target="_blank">jialong Dong</a><a href="https://github.com/k99k5/" target="_blank">TigerKK</a><a href="https://github.com/xianyu125/" target="_blank">xianyu125</a><a href="https://github.com/ElliotHughes/" target="_blank">ElliotHughes</a><a href="https://bbs.weixiaoduo.com/users/feibisi/"
target="_blank">诗语</a><a href="https://www.modiqi.com/" target="_blank">莫蒂奇</a><a href="https://www.weixiaoduo.com/" target="_blank">薇晓朵</a>
<p></p>
</div>
<div class="wpcy-buttons"><a href="https://wpcy.com/about/promoter" target="_blank" rel="noopener" class="components-button button-secondary">推广名单 </a><a href="https://github.com/WenPai-org/wp-china-yes" target="_blank" rel="noopener" class="components-button button-secondary">参与贡献 </a></div>
</div>
</div>
</div>
<div class="clear"></div>

View file

@ -0,0 +1,20 @@
// templates/maintenance-default.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo esc_html($title); ?></title>
<style>
/* 添加你的样式 */
</style>
</head>
<body>
<div class="maintenance-container">
<h1><?php echo esc_html($heading); ?></h1>
<div class="message">
<?php echo wp_kses_post($message); ?>
</div>
</div>
</body>
</html>

21
templates/website-section.php Executable file
View file

@ -0,0 +1,21 @@
<?php
// website-section.php
?>
<div class="wpcy-about__section">
<div class="wpcy-about__grid columns-1">
<div class="column wpcy-kit-banner"><span class="wpcy-icon-inner"> <i class="icon icon-magic-star"></i></span>
<h2>开源建站</h2>
<p>文派寻鹿🦌WP Deer建站套件是由文派科技官方提供的企业建站产品集合代码均为 100% GPL 开源,无任何加密隐藏。</p>
<div class="wpcy-buttons"><a href="https://wpcy.com/website" target="_blank" rel="noopener" class="components-button button-primary">阅读《软件授权协议》 </a></div>
</div>
</div>
<div class="wpcy-about__grid columns-3">
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-flash"></i></span>
<h2>SEO 优化技巧</h2><a href="https://wpxyz.com/" target="_blank" rel="noopener" class="components-button button-link">WPXYZ.com </a></div>
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-box-tick"></i></span>
<h2>网站政策合规</h2><a href="https://wpicp.com" target="_blank" rel="noopener" class="components-button button-link">WPICP.com </a></div>
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-broom"></i></span>
<h2>软件开发工具</h2><a href="https://wpsdk.com/" target="_blank" rel="noopener" class="components-button button-link">WPSDK.com </a></div>
</div>
</div>
<div class="clear"></div>

56
templates/welcome-section.php Executable file
View file

@ -0,0 +1,56 @@
<?php
// welcome-section.php
?>
<div class="wpcy-about__section">
<div class="wpcy-about__grid">
<div class="column wpcy-banner"><span class="wpcy-icon-inner"> <i class="icon icon-mirroring-screen"></i></span>
<h2>原生体验</h2>
<p>文派叶子🍃WP-China-Yes是一款不可多得的 WordPress 系统底层优化和生态基础设施软件。</p>
<div class="wpcy-buttons"><a href="<?php echo $settings_page_url; ?>#tab=%e5%bb%ba%e7%ab%99%e5%a5%97%e4%bb%b6" class="components-button button-primary">获取 WP Deer 建站套件</a><a href="https://wenpai.org/" target="_blank" rel="noopener" class="components-button button-secondary">文派开源WenPai.org</a></div>
<img
src="/wp-content/plugins/wp-china-yes/assets/images/website-banner.jpg" width="358" height="140" alt=""></div>
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-link-21"></i> </span>
<h2>特色功能</h2>
<ul class="wpcy-about__list">
<li><a href="<?php echo $settings_page_url; ?>#tab=%e5%ba%94%e7%94%a8%e5%b8%82%e5%9c%ba" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-folder-open"></i> </span>文派WordPress中国更新源</a></li>
<li><a href="<?php echo $settings_page_url; ?>#tab=%e8%90%8c%e8%8a%bd%e5%8a%a0%e9%80%9f" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-colorfilter"></i> </span>前端公共资源库 CDN 加速</a></li>
<li><a href="<?php echo $settings_page_url; ?>#tab=%e6%96%87%e9%a3%8e%e5%ad%97%e4%bd%93" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-language-square"></i> </span>中文网页字体</a></li>
<li><a href="<?php echo $settings_page_url; ?>#tab=%e5%b9%bf%e5%91%8a%e6%8b%a6%e6%88%aa" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-eye-slash"></i> </span>后台广告拦截</a></li>
<li><a href="<?php echo $settings_page_url; ?>#tab=%e9%a3%9e%e8%a1%8c%e6%a8%a1%e5%bc%8f" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-filter"></i> </span>外部 API 请求屏蔽</a></li>
<li><a href="<?php echo $settings_page_url; ?>#tab=%e5%93%81%e7%89%8c%e7%99%bd%e6%a0%87" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-password-check"></i> </span>品牌 OEM 定制</a></li>
</ul>
<p>* 100% 兼容 WP 程序及分支发行版本,更多优秀插件待您体验。</p>
</div>
</div>
<div class="wpcy-about__grid columns-3">
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-flash"></i></span>
<h2>网站加速</h2>
<p>优化加速插件多如牛毛,为何文派叶子如此与众不同?</p><a href="https://wpcy.com/acceleration" target="_blank" rel="noopener" class="components-button button-link">进一步了解 </a></div>
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-box-tick"></i></span>
<h2>翻译推送</h2>
<p>高质量翻译中文本地化翻译由文派开源官方提供,欢迎参与改进。</p><a href="https://wpcy.com/translate" target="_blank" rel="noopener" class="components-button button-link">本地化改进 </a></div>
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-broom"></i></span>
<h2>广告屏蔽</h2>
<p>呈现清爽整洁的网站后台,清除侵入式后台广告、无用信息。</p><a href="https://wpcy.com/ads" target="_blank" rel="noopener" class="components-button button-link">获取广告规则 </a></div>
</div>
<div class="wpcy-about__grid">
<div class="column"><span class="wpcy-icon-inner"> <i class="icon icon-sms-notification"></i></span>
<h2>加入我们</h2>
<p>关注文派茶馆 WPTEA.com 公众号以及订阅我们的时事通讯即可接收独家内容、提示和更新。</p>
<div class="wpcy-buttons"><a href="https://wptea.com/newsletter" target="_blank" rel="noopener" class="components-button button-secondary">订阅新闻 </a></div> <img src="/wp-content/plugins/wp-china-yes/assets/images/qr-banner.jpg" width="358" height="140" alt=""></div>
<div
class="column"><span class="wpcy-icon-inner"> <i class="icon icon-more-square"></i></span>
<h2>浏览更多</h2>
<ul class="wpcy-about__list">
<li><a href="https://wpcy.com" target="_blank" rel="noopener" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-global"></i> </span>文派叶子 🍃 WPCY.com</a></li>
<li><a href="https://wpcy.com/document" target="_blank" rel="noopener" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-archive-book"></i> </span>快速入门指南</a></li>
<li><a href="https://wpcy.com/support/" target="_blank" rel="noopener noreferrer" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-message-notif"></i> </span>支持论坛</a></li>
<li><a href="https://space.bilibili.com/3546657484442062" target="_blank" rel="noopener noreferrer" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-video-square"></i> </span>Bilibili 官方频道</a></li>
<li><a href="https://wpcy.com/faqs" target="_blank" rel="noopener noreferrer" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-lifebuoy"></i> </span>常见问题</a></li>
<li><a href="https://wpcy.com/document/website-backend-is-messy" target="_blank" rel="noopener noreferrer" class="components-button button-link has-text has-icon"><span class="wpcy-icon-inner-list"> <i class="icon icon-warning-2"></i> </span>疑难故障排查…</a></li>
</li>
</ul>
</div>
</div>
</div>
<div class="clear"></div>

View file

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Plugin Name: WPCY.COM * Plugin Name: WP-China-Yes
* Description: 文派叶子 🍃WP-China-Yes是中国 WordPress 生态基础设施软件,犹如落叶新芽,生生不息。 * Description: 文派叶子 🍃WP-China-Yes是中国 WordPress 生态基础设施软件,犹如落叶新芽,生生不息。
* Author: 文派开源 * Author: 文派开源
* Author URI: https://wpcy.com * Author URI: https://wpcy.com
* Version: 3.8 * Version: 3.8.1
* License: GPLv3 or later * License: GPLv3 or later
* Text Domain: wp-china-yes * Text Domain: wp-china-yes
* Domain Path: /languages * Domain Path: /languages
@ -24,11 +24,32 @@ define( 'CHINA_YES_PLUGIN_FILE', __FILE__ );
define( 'CHINA_YES_PLUGIN_URL', plugin_dir_url( CHINA_YES_PLUGIN_FILE ) ); define( 'CHINA_YES_PLUGIN_URL', plugin_dir_url( CHINA_YES_PLUGIN_FILE ) );
define( 'CHINA_YES_PLUGIN_PATH', plugin_dir_path( CHINA_YES_PLUGIN_FILE ) ); define( 'CHINA_YES_PLUGIN_PATH', plugin_dir_path( CHINA_YES_PLUGIN_FILE ) );
require_once( plugin_dir_path( CHINA_YES_PLUGIN_FILE ) . 'vendor/autoload.php' ); if (file_exists(CHINA_YES_PLUGIN_PATH . 'vendor/autoload.php')) {
// 尽早初始化性能设置
$settings = get_option('wenpai_china_yes'); // 替换成您实际的设置选项名
if (!empty($settings)) {
if (!defined('WP_MEMORY_LIMIT') && !empty($settings['wp_memory_limit'])) {
define('WP_MEMORY_LIMIT', $settings['wp_memory_limit']);
@ini_set('memory_limit', $settings['wp_memory_limit']);
}
if (!defined('WP_MAX_MEMORY_LIMIT') && !empty($settings['wp_max_memory_limit'])) {
define('WP_MAX_MEMORY_LIMIT', $settings['wp_max_memory_limit']);
}
if (!defined('WP_POST_REVISIONS') && isset($settings['wp_post_revisions'])) {
define('WP_POST_REVISIONS', intval($settings['wp_post_revisions']));
}
if (!defined('AUTOSAVE_INTERVAL') && !empty($settings['autosave_interval'])) {
define('AUTOSAVE_INTERVAL', intval($settings['autosave_interval']));
}
}
require_once(CHINA_YES_PLUGIN_PATH . 'vendor/autoload.php');
}
// 注册插件激活钩子 // 注册插件激活钩子
register_activation_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'activate' ] ); register_activation_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'activate' ] );
// 注册插件删除钩子 // 注册插件删除钩子
register_uninstall_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'uninstall' ] ); register_uninstall_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'uninstall' ] );
new Plugin(); new Plugin();