mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-03 02:48:45 +08:00
feat: 性能优化
This commit is contained in:
parent
789c920032
commit
7121b4b7ef
8 changed files with 63 additions and 57 deletions
20
Plugin.php
20
Plugin.php
|
@ -5,7 +5,6 @@ namespace WenPai\ChinaYes;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WenPai\ChinaYes\Service\Base;
|
||||
use WenPai\ChinaYes\Service\Setting;
|
||||
|
||||
class Plugin {
|
||||
|
||||
|
@ -14,8 +13,9 @@ class Plugin {
|
|||
*/
|
||||
public function __construct() {
|
||||
new Base();
|
||||
new Setting();
|
||||
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
|
||||
if ( is_admin() ) {
|
||||
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,15 @@ class Plugin {
|
|||
public function plugins_loaded() {
|
||||
load_plugin_textdomain( 'wp-china-yes', false, CHINA_YES_PLUGIN_PATH . 'languages' );
|
||||
add_action( 'admin_notices', [ $this, 'admin_notices' ] );
|
||||
/**
|
||||
* 插件列表页中所有插件增加「参与翻译」链接
|
||||
*/
|
||||
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>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,9 +56,9 @@ class Plugin {
|
|||
*/
|
||||
public static function check() {
|
||||
$notices = [];
|
||||
if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
|
||||
if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) {
|
||||
deactivate_plugins( 'wp-china-yes/wp-china-yes.php' );
|
||||
$notices[] = '<div class="notice notice-error"><p>' . sprintf( __( 'WP-China-Yes 插件需要 PHP 5.6.0 或更高版本,当前版本为 %s,插件已自动禁用。',
|
||||
$notices[] = '<div class="notice notice-error"><p>' . sprintf( __( 'WP-China-Yes 插件需要 PHP 7.0.0 或更高版本,当前版本为 %s,插件已自动禁用。',
|
||||
'wp-china-yes' ),
|
||||
PHP_VERSION ) . '</p></div>';
|
||||
}
|
||||
|
@ -70,7 +79,6 @@ class Plugin {
|
|||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>' . __( '检测到不兼容的插件 Kill 429,已自动禁用!', 'wp-china-yes' ) . '</strong></p>
|
||||
</div>';
|
||||
|
||||
}
|
||||
// 代理服务器检测
|
||||
if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) ) {
|
||||
|
|
|
@ -12,21 +12,15 @@ defined( 'ABSPATH' ) || exit;
|
|||
class Base {
|
||||
|
||||
public function __construct() {
|
||||
/**
|
||||
* 插件列表页中所有插件增加「参与翻译」链接
|
||||
*/
|
||||
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>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
|
||||
// 加速服务
|
||||
new Super();
|
||||
// 监控服务
|
||||
new Monitor();
|
||||
// 更新服务
|
||||
new Update();
|
||||
if ( is_admin() ) {
|
||||
// 设置服务
|
||||
new Setting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,40 +17,44 @@ class Monitor {
|
|||
|
||||
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'] ) {
|
||||
return;
|
||||
// 站点网络下只在主站运行
|
||||
if ( is_main_site() ) {
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'wp_china_yes_monitor_hook', [
|
||||
$this,
|
||||
'run_monitor'
|
||||
] );
|
||||
}
|
||||
} else {
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
|
||||
}
|
||||
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'wp_china_yes_maybe_check_store', [
|
||||
$this,
|
||||
'maybe_check_store'
|
||||
] );
|
||||
add_action( 'wp_china_yes_maybe_check_cravatar', [
|
||||
$this,
|
||||
'maybe_check_cravatar'
|
||||
] );
|
||||
add_action( 'wp_china_yes_maybe_check_admincdn', [
|
||||
$this,
|
||||
'maybe_check_admincdn'
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function init() {
|
||||
// 检查应用市场可用性
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_maybe_check_store' ) && $this->settings['store'] != 'off' ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_maybe_check_store' );
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor_hook' );
|
||||
}
|
||||
// 检查初认头像可用性
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_maybe_check_cravatar' ) && $this->settings['cravatar'] != 'off' ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_maybe_check_cravatar' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行监控
|
||||
*/
|
||||
public function run_monitor() {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
$this->maybe_check_store();
|
||||
}
|
||||
// 检查萌芽加速可用性
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_maybe_check_admincdn' ) && ! empty( $this->settings['admincdn'] ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_maybe_check_admincdn' );
|
||||
if ( $this->settings['cravatar'] != 'off' ) {
|
||||
$this->maybe_check_cravatar();
|
||||
}
|
||||
if ( ! empty( $this->settings['admincdn'] ) ) {
|
||||
$this->maybe_check_admincdn();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +109,7 @@ class Monitor {
|
|||
public function maybe_check_admincdn() {
|
||||
// 后台加速
|
||||
if ( in_array( 'admin', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://wpstatic.admincdn.com/6.4.3/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 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) );
|
||||
$this->update_settings();
|
||||
|
@ -161,7 +165,7 @@ class Monitor {
|
|||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_china_yes', $this->settings );
|
||||
} else {
|
||||
update_option( 'wp_china_yes', $this->settings );
|
||||
update_option( 'wp_china_yes', $this->settings, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,10 +54,10 @@ HTML;
|
|||
<a href="https://wenpai.org/support" target="_blank">支持论坛</a>
|
||||
|
|
||||
<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/instructions-for-submission/" target="_blank">文章投稿</a>
|
||||
|
|
||||
<a href="https://wp-china-yes.com/document/news-source" target="_blank">自选新闻源</a>
|
||||
</p>
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
|
@ -83,8 +83,8 @@ HTML;
|
|||
margin:0
|
||||
}
|
||||
#wenpai_tea .community-events-footer a {
|
||||
line-height: 2;
|
||||
padding: 0.5em;
|
||||
line-height: 2;
|
||||
padding: 0.5em;
|
||||
}
|
||||
</style>
|
||||
HTML;
|
||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -8,16 +8,16 @@
|
|||
"packages": [
|
||||
{
|
||||
"name": "yahnis-elsts/plugin-update-checker",
|
||||
"version": "v5.4",
|
||||
"version": "v5.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/YahnisElsts/plugin-update-checker.git",
|
||||
"reference": "e8e53e6d98e37fa7c895c93417f52e3775494715"
|
||||
"reference": "845d65da93bcff31649ede00d9d73b1beadbb7f0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/e8e53e6d98e37fa7c895c93417f52e3775494715",
|
||||
"reference": "e8e53e6d98e37fa7c895c93417f52e3775494715",
|
||||
"url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/845d65da93bcff31649ede00d9d73b1beadbb7f0",
|
||||
"reference": "845d65da93bcff31649ede00d9d73b1beadbb7f0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -27,7 +27,7 @@
|
|||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"load-v5p4.php"
|
||||
"load-v5p5.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
@ -52,9 +52,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/YahnisElsts/plugin-update-checker/issues",
|
||||
"source": "https://github.com/YahnisElsts/plugin-update-checker/tree/v5.4"
|
||||
"source": "https://github.com/YahnisElsts/plugin-update-checker/tree/v5.5"
|
||||
},
|
||||
"time": "2024-02-24T09:56:49+00:00"
|
||||
"time": "2024-10-16T14:25:00+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
|
|
@ -346,7 +346,7 @@ if ( ! class_exists( 'WP_CHINA_YES_Options' ) ) {
|
|||
} else if ( $this->args['database'] === 'network' ) {
|
||||
update_site_option( $this->unique, $data );
|
||||
} else {
|
||||
update_option( $this->unique, $data );
|
||||
update_option( $this->unique, $data, true );
|
||||
}
|
||||
|
||||
do_action( "wp_china_yes_{$this->unique}_saved", $data, $this );
|
||||
|
|
|
@ -115,7 +115,7 @@ if ( ! function_exists( 'wp_china_yes_import_ajax' ) ) {
|
|||
}
|
||||
|
||||
// Success
|
||||
update_option( $unique, $data );
|
||||
update_option( $unique, $data, true );
|
||||
|
||||
wp_send_json_success();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Description: 文派叶子 🍃(WP-China-Yes)是中国 WordPress 生态基础设施软件,犹如落叶新芽,生生不息。
|
||||
* Author: 文派开源
|
||||
* Author URI: https://wp-china-yes.com
|
||||
* Version: 3.7.0
|
||||
* Version: 3.7.1
|
||||
* License: GPLv3 or later
|
||||
* Text Domain: wp-china-yes
|
||||
* Domain Path: /languages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue