diff --git a/Plugin.php b/Plugin.php index 3d74313..4723162 100644 --- a/Plugin.php +++ b/Plugin.php @@ -5,7 +5,6 @@ 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 @@ public static function uninstall() { 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[] = '参与翻译'; + $links[] = '去广告'; + + return $links; + }, 10, 2 ); } /** @@ -47,9 +56,9 @@ public function plugins_loaded() { */ 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[] = '

' . sprintf( __( 'WP-China-Yes 插件需要 PHP 5.6.0 或更高版本,当前版本为 %s,插件已自动禁用。', + $notices[] = '

' . sprintf( __( 'WP-China-Yes 插件需要 PHP 7.0.0 或更高版本,当前版本为 %s,插件已自动禁用。', 'wp-china-yes' ), PHP_VERSION ) . '

'; } @@ -70,7 +79,6 @@ public static function check() { $notices[] = '

' . __( '检测到不兼容的插件 Kill 429,已自动禁用!', 'wp-china-yes' ) . '

'; - } // 代理服务器检测 if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) ) { diff --git a/Service/Base.php b/Service/Base.php index 238172e..5938a15 100644 --- a/Service/Base.php +++ b/Service/Base.php @@ -12,21 +12,15 @@ class Base { public function __construct() { - /** - * 插件列表页中所有插件增加「参与翻译」链接 - */ - add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) { - $links[] = '参与翻译'; - $links[] = '去广告'; - - return $links; - }, 10, 2 ); - // 加速服务 new Super(); // 监控服务 new Monitor(); // 更新服务 new Update(); + if ( is_admin() ) { + // 设置服务 + new Setting(); + } } } diff --git a/Service/Monitor.php b/Service/Monitor.php index e59aab6..73fb085 100644 --- a/Service/Monitor.php +++ b/Service/Monitor.php @@ -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' ); + } + } + + /** + * 运行监控 + */ + public function run_monitor() { + if ( $this->settings['store'] != 'off' ) { + $this->maybe_check_store(); } - // 检查初认头像可用性 - 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' ); + if ( $this->settings['cravatar'] != 'off' ) { + $this->maybe_check_cravatar(); } - // 检查萌芽加速可用性 - 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 ( ! empty( $this->settings['admincdn'] ) ) { + $this->maybe_check_admincdn(); } } @@ -105,7 +109,7 @@ public function maybe_check_cravatar() { 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 @@ private function update_settings() { 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 ); } } } diff --git a/Service/Super.php b/Service/Super.php index 73c5832..c0e10d0 100644 --- a/Service/Super.php +++ b/Service/Super.php @@ -54,10 +54,10 @@ public function __construct() { 支持论坛 | 翻译平台 - | - 文章投稿 | - 自选新闻源 + 文章投稿 + | + 自选新闻源

HTML; diff --git a/composer.lock b/composer.lock index 6066563..55fa2ae 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [], diff --git a/framework/classes/admin-options.class.php b/framework/classes/admin-options.class.php index 9c250aa..3a9cb9d 100644 --- a/framework/classes/admin-options.class.php +++ b/framework/classes/admin-options.class.php @@ -346,7 +346,7 @@ public function save_options( $data ) { } 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 ); diff --git a/framework/functions/actions.php b/framework/functions/actions.php index b18ed96..f22a70e 100644 --- a/framework/functions/actions.php +++ b/framework/functions/actions.php @@ -115,7 +115,7 @@ function wp_china_yes_import_ajax() { } // Success - update_option( $unique, $data ); + update_option( $unique, $data, true ); wp_send_json_success(); diff --git a/wp-china-yes.php b/wp-china-yes.php index 278cb81..7db8452 100644 --- a/wp-china-yes.php +++ b/wp-china-yes.php @@ -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