升级至 3.8 版本
2
Plugin.php
Normal file → Executable file
|
@ -45,7 +45,7 @@ class Plugin {
|
|||
*/
|
||||
add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) {
|
||||
$links[] = '<a target="_blank" href="https://translate.wenpai.org/projects/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">参与翻译</a>';
|
||||
$links[] = '<a target="_blank" href="https://wp-china-yes.com/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">去广告</a>';
|
||||
$links[] = '<a target="_blank" href="https://wpcy.com/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">去广告</a>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
|
|
6
Service/Base.php
Normal file → Executable file
|
@ -16,11 +16,13 @@ class Base {
|
|||
new Super();
|
||||
// 监控服务
|
||||
new Monitor();
|
||||
// 内存服务
|
||||
new Memory();
|
||||
// 更新服务
|
||||
new Update();
|
||||
if ( is_admin() ) {
|
||||
// 设置服务
|
||||
new Setting();
|
||||
// 设置服务
|
||||
new Setting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
254
Service/Memory.php
Executable file
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
|
||||
/**
|
||||
* Class Memory
|
||||
* 显示服务器 IP 和内存使用情况
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Memory {
|
||||
private $memory = [];
|
||||
private $server_ip_address = '';
|
||||
private $os_info = '';
|
||||
private $debug_status = '';
|
||||
private $cpu_usage = null;
|
||||
private $mysql_version = '';
|
||||
|
||||
public function __construct() {
|
||||
$settings = get_settings();
|
||||
if (!empty($settings['memory'])) {
|
||||
add_action('plugins_loaded', [$this, 'initialize']);
|
||||
}
|
||||
register_activation_hook(CHINA_YES_PLUGIN_FILE, [$this, 'check_php_version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化插件
|
||||
*/
|
||||
public function initialize() {
|
||||
add_action('init', [$this, 'check_memory_limit']);
|
||||
add_filter('admin_footer_text', [$this, 'add_footer']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统信息
|
||||
*/
|
||||
private function get_os_info() {
|
||||
$os = php_uname('s');
|
||||
|
||||
// 转换为更直观的名称
|
||||
switch (strtolower($os)) {
|
||||
case 'linux':
|
||||
if (file_exists('/etc/os-release')) {
|
||||
$content = parse_ini_file('/etc/os-release');
|
||||
return $content['PRETTY_NAME'] ?? 'Linux';
|
||||
}
|
||||
return 'Linux';
|
||||
case 'darwin':
|
||||
return 'macOS';
|
||||
case 'windows nt':
|
||||
return 'Windows';
|
||||
default:
|
||||
return $os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取调试状态
|
||||
*/
|
||||
private function get_debug_status() {
|
||||
if (defined('WP_DEBUG') && true === WP_DEBUG) {
|
||||
return '<strong><font color="#F60">' . __('WP_DEBUG', 'wp-china-yes') . '</font></strong>';
|
||||
}
|
||||
return '<span style="text-decoration: line-through;">' . __('WP_DEBUG', 'wp-china-yes') . '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CPU 使用率
|
||||
*/
|
||||
private function get_cpu_usage() {
|
||||
if (function_exists('sys_getloadavg') && is_callable('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
return round($load[0] * 100 / 4, 2); // 假设是4核CPU
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MySQL 版本
|
||||
*/
|
||||
private function get_mysql_version() {
|
||||
global $wpdb;
|
||||
return $wpdb->get_var("SELECT VERSION()");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 PHP 内存限制
|
||||
*/
|
||||
public function check_memory_limit() {
|
||||
$this->memory['limit'] = (int) ini_get('memory_limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查内存使用情况
|
||||
*/
|
||||
private function check_memory_usage() {
|
||||
$this->memory['usage'] = function_exists('memory_get_peak_usage')
|
||||
? round(memory_get_peak_usage(true) / 1024 / 1024, 2)
|
||||
: 0;
|
||||
|
||||
if (!empty($this->memory['usage']) && !empty($this->memory['limit'])) {
|
||||
$this->memory['percent'] = round($this->memory['usage'] / $this->memory['limit'] * 100, 0);
|
||||
$this->memory['color'] = $this->get_memory_color($this->memory['percent']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用率的颜色
|
||||
*/
|
||||
private function get_memory_color($percent) {
|
||||
if ($percent > 90) {
|
||||
return 'font-weight:bold;color:red';
|
||||
} elseif ($percent > 75) {
|
||||
return 'font-weight:bold;color:#E66F00';
|
||||
}
|
||||
return 'font-weight:normal;';
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 WordPress 内存限制
|
||||
*/
|
||||
private function format_wp_limit($size) {
|
||||
$unit = strtoupper(substr($size, -1));
|
||||
$value = (int) substr($size, 0, -1);
|
||||
|
||||
switch ($unit) {
|
||||
case 'P': $value *= 1024;
|
||||
case 'T': $value *= 1024;
|
||||
case 'G': $value *= 1024;
|
||||
case 'M': $value *= 1024;
|
||||
case 'K': $value *= 1024;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 WordPress 内存限制
|
||||
*/
|
||||
private function check_wp_limit() {
|
||||
$memory = $this->format_wp_limit(WP_MEMORY_LIMIT);
|
||||
return $memory ? size_format($memory) : __('N/A', 'wp-china-yes');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加信息到管理界面页脚
|
||||
*/
|
||||
public function add_footer($content) {
|
||||
$settings = get_settings();
|
||||
// 确保 memory_display 是数组,如果不是则使用空数组
|
||||
$display_options = is_array($settings['memory_display'] ?? []) ? $settings['memory_display'] : [];
|
||||
|
||||
// 如果 memory 设置未启用,直接返回原始内容
|
||||
if (empty($settings['memory'])) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$this->check_memory_usage();
|
||||
$this->server_ip_address = $_SERVER['SERVER_ADDR'] ?? ($_SERVER['LOCAL_ADDR'] ?? '');
|
||||
$this->os_info = $this->get_os_info();
|
||||
|
||||
$footer_parts = [];
|
||||
|
||||
// 内存使用量
|
||||
if (in_array('memory_usage', $display_options)) {
|
||||
$footer_parts[] = sprintf('%s: %s %s %s MB (<span style="%s">%s%%</span>)',
|
||||
__('Memory', 'wp-china-yes'),
|
||||
$this->memory['usage'],
|
||||
__('of', 'wp-china-yes'),
|
||||
$this->memory['limit'],
|
||||
$this->memory['color'],
|
||||
$this->memory['percent']
|
||||
);
|
||||
}
|
||||
|
||||
// WP内存限制
|
||||
if (in_array('wp_limit', $display_options)) {
|
||||
$footer_parts[] = sprintf('%s: %s',
|
||||
__('WP LIMIT', 'wp-china-yes'),
|
||||
$this->check_wp_limit()
|
||||
);
|
||||
}
|
||||
|
||||
// 服务器IP和主机名
|
||||
if (in_array('server_ip', $display_options)) {
|
||||
$hostname_part = in_array('hostname', $display_options) ? " (" . gethostname() . ")" : "";
|
||||
$footer_parts[] = sprintf('IP: %s%s',
|
||||
$this->server_ip_address,
|
||||
$hostname_part
|
||||
);
|
||||
}
|
||||
|
||||
// 操作系统信息
|
||||
if (in_array('os_info', $display_options)) {
|
||||
$footer_parts[] = sprintf('OS: %s', $this->os_info);
|
||||
}
|
||||
|
||||
// PHP信息
|
||||
if (in_array('php_info', $display_options)) {
|
||||
$footer_parts[] = sprintf('PHP: %s @%sBitOS',
|
||||
PHP_VERSION,
|
||||
PHP_INT_SIZE * 8
|
||||
);
|
||||
}
|
||||
|
||||
// Debug状态
|
||||
if (in_array('debug_status', $display_options)) {
|
||||
$footer_parts[] = $this->get_debug_status();
|
||||
}
|
||||
|
||||
// CPU使用率
|
||||
if (in_array('cpu_usage', $display_options)) {
|
||||
$cpu_usage = $this->get_cpu_usage();
|
||||
if ($cpu_usage !== false) {
|
||||
$footer_parts[] = sprintf('CPU: %s%%', $cpu_usage);
|
||||
}
|
||||
}
|
||||
|
||||
// MySQL版本
|
||||
if (in_array('mysql_version', $display_options)) {
|
||||
$footer_parts[] = sprintf('MySQL: %s', $this->get_mysql_version());
|
||||
}
|
||||
|
||||
if (!empty($footer_parts)) {
|
||||
$content .= ' | WPCY - ' . implode(' | ', $footer_parts);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查 PHP 版本
|
||||
*/
|
||||
public function check_php_version() {
|
||||
if (version_compare(PHP_VERSION, '7.0', '<')) {
|
||||
deactivate_plugins(plugin_basename(CHINA_YES_PLUGIN_FILE));
|
||||
wp_die(
|
||||
sprintf(
|
||||
'<h1>%s</h1><p>%s</p>',
|
||||
__('插件无法激活:PHP 版本过低', 'wp-china-yes'),
|
||||
__('请升级 PHP 至 7.0 或更高版本。', 'wp-china-yes')
|
||||
),
|
||||
__('PHP 版本错误', 'wp-china-yes'),
|
||||
['back_link' => true]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
344
Service/Monitor.php
Normal file → Executable file
|
@ -1,173 +1,171 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Monitor
|
||||
* 插件监控服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Monitor {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
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_admincdn' ); // TODO 下个版本移除
|
||||
if ( $this->settings['monitor'] ) {
|
||||
// 站点网络下只在主站运行
|
||||
if ( is_main_site() ) {
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'wp_china_yes_monitor', [
|
||||
$this,
|
||||
'run_monitor'
|
||||
] );
|
||||
}
|
||||
} else {
|
||||
if ( wp_get_scheduled_event( 'wp_china_yes_monitor' ) ) {
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function init() {
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行监控
|
||||
*/
|
||||
public function run_monitor() {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
$this->maybe_check_store();
|
||||
}
|
||||
if ( $this->settings['cravatar'] != 'off' ) {
|
||||
$this->maybe_check_cravatar();
|
||||
}
|
||||
if ( ! empty( $this->settings['admincdn'] ) ) {
|
||||
$this->maybe_check_admincdn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查应用市场可用性
|
||||
*/
|
||||
public function maybe_check_store() {
|
||||
$test_url = 'https://api.wenpai.net/china-yes/version-check';
|
||||
if ( $this->settings['store'] == 'proxy' ) {
|
||||
$test_url = 'https://api.wpmirror.com/core/version-check/1.7/';
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['store'] == 'wenpai' ) {
|
||||
$this->settings['store'] = 'proxy';
|
||||
} elseif ( $this->settings['store'] == 'proxy' ) {
|
||||
$this->settings['store'] = 'off';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查初认头像可用性
|
||||
*/
|
||||
public function maybe_check_cravatar() {
|
||||
$test_url = 'https://cn.cravatar.com/avatar/';
|
||||
switch ( $this->settings['cravatar'] ) {
|
||||
case 'global':
|
||||
$test_url = 'https://en.cravatar.com/avatar/';
|
||||
break;
|
||||
case 'weavatar':
|
||||
$test_url = 'https://weavatar.com/avatar/';
|
||||
break;
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['cravatar'] == 'cn' ) {
|
||||
$this->settings['cravatar'] = 'global';
|
||||
} elseif ( $this->settings['cravatar'] == 'global' ) {
|
||||
$this->settings['cravatar'] = 'weavatar';
|
||||
} elseif ( $this->settings['cravatar'] == 'weavatar' ) {
|
||||
$this->settings['cravatar'] = 'cn';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查萌芽加速可用性
|
||||
*/
|
||||
public function maybe_check_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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// 前台加速
|
||||
if ( in_array( 'frontend', $this->settings['admincdn'] ) ) {
|
||||
$url = network_site_url( '/wp-includes/js/wp-sanitize.min.js' );
|
||||
$response = wp_remote_get( 'https://public.admincdn.com/' . $url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'frontend' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 字体
|
||||
if ( in_array( 'googlefonts', $this->settings['admincdn'] ) ) {
|
||||
$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 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googlefonts' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 前端公共库
|
||||
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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googleajax' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// CDNJS 前端公共库
|
||||
if ( in_array( 'cdnjs', $this->settings['admincdn'] ) ) {
|
||||
$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 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'cdnjs' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// jsDelivr 公共库
|
||||
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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'jsdelivr' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设置
|
||||
*/
|
||||
private function update_settings() {
|
||||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_china_yes', $this->settings );
|
||||
} else {
|
||||
update_option( 'wp_china_yes', $this->settings, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Monitor
|
||||
* 插件监控服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Monitor {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
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_admincdn' ); // TODO 下个版本移除
|
||||
if ( $this->settings['monitor'] ) {
|
||||
// 站点网络下只在主站运行
|
||||
if ( is_main_site() ) {
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'wp_china_yes_monitor', [
|
||||
$this,
|
||||
'run_monitor'
|
||||
] );
|
||||
}
|
||||
} else {
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function init() {
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行监控
|
||||
*/
|
||||
public function run_monitor() {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
$this->maybe_check_store();
|
||||
}
|
||||
if ( $this->settings['cravatar'] != 'off' ) {
|
||||
$this->maybe_check_cravatar();
|
||||
}
|
||||
if ( ! empty( $this->settings['admincdn'] ) ) {
|
||||
$this->maybe_check_admincdn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查应用市场可用性
|
||||
*/
|
||||
public function maybe_check_store() {
|
||||
$test_url = 'https://api.wenpai.net/china-yes/version-check';
|
||||
if ( $this->settings['store'] == 'proxy' ) {
|
||||
$test_url = 'https://api.wpmirror.com/core/version-check/1.7/';
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['store'] == 'wenpai' ) {
|
||||
$this->settings['store'] = 'proxy';
|
||||
} elseif ( $this->settings['store'] == 'proxy' ) {
|
||||
$this->settings['store'] = 'off';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查初认头像可用性
|
||||
*/
|
||||
public function maybe_check_cravatar() {
|
||||
$test_url = 'https://cn.cravatar.com/avatar/';
|
||||
switch ( $this->settings['cravatar'] ) {
|
||||
case 'global':
|
||||
$test_url = 'https://en.cravatar.com/avatar/';
|
||||
break;
|
||||
case 'weavatar':
|
||||
$test_url = 'https://weavatar.com/avatar/';
|
||||
break;
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['cravatar'] == 'cn' ) {
|
||||
$this->settings['cravatar'] = 'global';
|
||||
} elseif ( $this->settings['cravatar'] == 'global' ) {
|
||||
$this->settings['cravatar'] = 'weavatar';
|
||||
} elseif ( $this->settings['cravatar'] == 'weavatar' ) {
|
||||
$this->settings['cravatar'] = 'cn';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查萌芽加速可用性
|
||||
*/
|
||||
public function maybe_check_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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// 前台加速
|
||||
if ( in_array( 'frontend', $this->settings['admincdn'] ) ) {
|
||||
$url = network_site_url( '/wp-includes/js/wp-sanitize.min.js' );
|
||||
$response = wp_remote_get( 'https://public.admincdn.com/' . $url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'frontend' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 字体
|
||||
if ( in_array( 'googlefonts', $this->settings['admincdn'] ) ) {
|
||||
$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 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googlefonts' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 前端公共库
|
||||
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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googleajax' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// CDNJS 前端公共库
|
||||
if ( in_array( 'cdnjs', $this->settings['admincdn'] ) ) {
|
||||
$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 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'cdnjs' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// jsDelivr 公共库
|
||||
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' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'jsdelivr' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设置
|
||||
*/
|
||||
private function update_settings() {
|
||||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_china_yes', $this->settings );
|
||||
} else {
|
||||
update_option( 'wp_china_yes', $this->settings, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
59
Service/Super.php
Normal file → Executable file
|
@ -55,9 +55,7 @@ HTML;
|
|||
|
|
||||
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
||||
|
|
||||
<a href="https://wptea.com/instructions-for-submission/" target="_blank">文章投稿</a>
|
||||
|
|
||||
<a href="https://wp-china-yes.com/document/news-source" target="_blank">自选新闻源</a>
|
||||
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
|
||||
</p>
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
|
@ -113,9 +111,7 @@ HTML;
|
|||
|
|
||||
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
||||
|
|
||||
<a href="https://wptea.com/instructions-for-submission/" target="_blank">文章投稿</a>
|
||||
|
|
||||
<a href="https://wptea.com/document/news-source/" target="_blank">自选新闻源</a>
|
||||
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
|
||||
</p>
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
|
@ -276,12 +272,23 @@ HTML;
|
|||
*/
|
||||
if ( in_array( 'jsdelivr', (array) $this->settings['admincdn'] ) ) {
|
||||
$this->page_str_replace( 'init', 'str_replace', [
|
||||
'jsd.admincdn.com',
|
||||
'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'
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载文风字体
|
||||
*/
|
||||
|
@ -442,6 +449,44 @@ HTML
|
|||
remove_filter( $qmr_work_tag, 'wptexturize' );
|
||||
}
|
||||
}
|
||||
|
||||
// 支持中文排版段首缩进 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 () {
|
||||
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 p.has-text-align-center {
|
||||
text-align: center !important;
|
||||
}
|
||||
</style>';
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
0
Service/Update.php
Normal file → Executable file
|
@ -90,6 +90,9 @@
|
|||
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.wp_china_yes-section {
|
||||
margin: 50px auto;
|
||||
|
|
BIN
assets/images/qr-banner.jpg
Executable file
After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 47 KiB |
0
framework/assets/css/style-rtl.min.css
vendored
Normal file → Executable file
0
framework/assets/css/style.min.css
vendored
Normal file → Executable file
0
framework/assets/images/checkerboard.png
Normal file → Executable file
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
0
framework/assets/images/wp-logo.svg
Normal file → Executable file
Before Width: | Height: | Size: 940 B After Width: | Height: | Size: 940 B |
0
framework/assets/images/wp-plugin-logo.svg
Normal file → Executable file
Before Width: | Height: | Size: 482 B After Width: | Height: | Size: 482 B |
0
framework/assets/js/main.min.js
vendored
Normal file → Executable file
0
framework/assets/js/plugins.min.js
vendored
Normal file → Executable file
0
framework/classes/abstract.class.php
Normal file → Executable file
0
framework/classes/admin-options.class.php
Normal file → Executable file
0
framework/classes/fields.class.php
Normal file → Executable file
0
framework/fields/accordion/accordion.php
Normal file → Executable file
0
framework/fields/background/background.php
Normal file → Executable file
0
framework/fields/backup/backup.php
Normal file → Executable file
0
framework/fields/border/border.php
Normal file → Executable file
0
framework/fields/button_set/button_set.php
Normal file → Executable file
0
framework/fields/callback/callback.php
Normal file → Executable file
0
framework/fields/checkbox/checkbox.php
Normal file → Executable file
0
framework/fields/code_editor/code_editor.php
Normal file → Executable file
0
framework/fields/color/color.php
Normal file → Executable file
0
framework/fields/color_group/color_group.php
Normal file → Executable file
0
framework/fields/content/content.php
Normal file → Executable file
0
framework/fields/date/date.php
Normal file → Executable file
0
framework/fields/datetime/datetime.php
Normal file → Executable file
0
framework/fields/dimensions/dimensions.php
Normal file → Executable file
0
framework/fields/fieldset/fieldset.php
Normal file → Executable file
0
framework/fields/gallery/gallery.php
Normal file → Executable file
0
framework/fields/group/group.php
Normal file → Executable file
0
framework/fields/heading/heading.php
Normal file → Executable file
0
framework/fields/icon/fa4-icons.php
Normal file → Executable file
0
framework/fields/icon/fa5-icons.php
Normal file → Executable file
0
framework/fields/icon/icon.php
Normal file → Executable file
0
framework/fields/image_select/image_select.php
Normal file → Executable file
0
framework/fields/index.php
Normal file → Executable file
0
framework/fields/link/link.php
Normal file → Executable file
0
framework/fields/link_color/link_color.php
Normal file → Executable file
0
framework/fields/map/map.php
Normal file → Executable file
0
framework/fields/media/media.php
Normal file → Executable file
0
framework/fields/notice/notice.php
Normal file → Executable file
0
framework/fields/number/number.php
Normal file → Executable file
0
framework/fields/palette/palette.php
Normal file → Executable file
0
framework/fields/radio/radio.php
Normal file → Executable file
0
framework/fields/repeater/repeater.php
Normal file → Executable file
0
framework/fields/select/select.php
Normal file → Executable file
0
framework/fields/slider/slider.php
Normal file → Executable file
0
framework/fields/sortable/sortable.php
Normal file → Executable file
0
framework/fields/sorter/sorter.php
Normal file → Executable file
0
framework/fields/spacing/spacing.php
Normal file → Executable file
0
framework/fields/spinner/spinner.php
Normal file → Executable file
0
framework/fields/subheading/subheading.php
Normal file → Executable file
0
framework/fields/submessage/submessage.php
Normal file → Executable file
0
framework/fields/switcher/switcher.php
Normal file → Executable file
0
framework/fields/tabbed/tabbed.php
Normal file → Executable file
0
framework/fields/text/text.php
Normal file → Executable file
0
framework/fields/textarea/textarea.php
Normal file → Executable file
0
framework/fields/typography/google-fonts.php
Normal file → Executable file
0
framework/fields/typography/typography.php
Normal file → Executable file
0
framework/fields/upload/upload.php
Normal file → Executable file
0
framework/fields/wp_editor/wp_editor.php
Normal file → Executable file
0
framework/functions/actions.php
Normal file → Executable file
0
framework/functions/customize.php
Normal file → Executable file
0
framework/functions/helpers.php
Normal file → Executable file
0
framework/functions/sanitize.php
Normal file → Executable file
0
framework/functions/validate.php
Normal file → Executable file
0
framework/functions/walker.php
Normal file → Executable file
0
framework/index.php
Normal file → Executable file
0
framework/languages/zh_CN.mo
Normal file → Executable file
1344
framework/languages/zh_CN.po
Normal file → Executable file
1
helpers.php
Normal file → Executable file
|
@ -20,6 +20,7 @@ function get_settings() {
|
|||
'plane' => 'off',
|
||||
'plane_rule' => [],
|
||||
'monitor' => true,
|
||||
'memory' => true,
|
||||
'hide' => false,
|
||||
'custom_name' => 'WP-China-Yes',
|
||||
] );
|
||||
|
|