diff --git a/Plugin.php b/Plugin.php index 1e5d455..3d74313 100644 --- a/Plugin.php +++ b/Plugin.php @@ -10,7 +10,7 @@ use WenPai\ChinaYes\Service\Setting; class Plugin { /** - * 创建一个插件实例 + * 创建插件实例 */ public function __construct() { new Base(); diff --git a/Service/Monitor.php b/Service/Monitor.php index c244f9b..1f867f7 100644 --- a/Service/Monitor.php +++ b/Service/Monitor.php @@ -37,6 +37,9 @@ class Monitor { * 初始化 */ public function init() { + if ( $this->settings['monitor'] != 'on' ) { + return; + } // 检查应用市场可用性 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' ); @@ -141,6 +144,14 @@ class Monitor { $this->update_settings(); } } + // jsDelivr 公共库 + if ( ! empty( $this->settings['admincdn']['jsdelivr'] ) ) { + $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 ) { + unset( $this->settings['admincdn']['jsdelivr'] ); + $this->update_settings(); + } + } } /** diff --git a/Service/Setting.php b/Service/Setting.php index aed8de9..c64c782 100644 --- a/Service/Setting.php +++ b/Service/Setting.php @@ -62,7 +62,8 @@ class Setting { 'frontend' => '前台加速', 'googlefonts' => 'Google 字体', 'googleajax' => 'Google 前端公共库', - 'cdnjs' => 'CDNJS 前端公共库' + 'cdnjs' => 'CDNJS 前端公共库', + 'jsdelivr' => 'jsDelivr 公共库', ] ], [ @@ -75,19 +76,20 @@ class Setting { 'options' => [ 'cn' => '默认线路', 'global' => '国际线路', - 'weavatar' => '备用源(WeAvatar)', + 'weavatar' => '备用源(WeAvatar)', 'off' => '不启用' ] ], [ 'name' => 'windfonts', 'label' => __( '文风字体', 'wp-china-yes' ), - 'desc' => __( '文风字体(Windfonts)即将为您的网页渲染中文字体并对主题、插件内的字体进行加速。', + 'desc' => __( '文风字体(Windfonts)为您的网页渲染中文字体并对主题、插件内的字体进行加速;优化模式可优化浏览器字体调用。', 'wp-china-yes' ), 'type' => 'radio', 'default' => 'off', 'options' => [ - 'off' => '即将上线', + 'optimize' => '优化模式', + 'off' => '不启用', ] ], [ @@ -101,6 +103,18 @@ class Setting { 'off' => '即将上线', ] ], + [ + 'name' => 'monitor', + 'label' => __( '自动监控', 'wp-china-yes' ), + 'desc' => __( '文派叶子🍃(WP-China-Yes)支持自动监控各加速节点可用性,当节点不可用时自动切换至可用节点或关闭加速,以保证您的网站正常访问。', + 'wp-china-yes' ), + 'type' => 'radio', + 'default' => 'on', + 'options' => [ + 'on' => '启用', + 'off' => '不启用', + ] + ], ] ]; @@ -166,7 +180,7 @@ HTML; echo << -
提示:插件会定期检查节点可用性,并在节点不可用时自动切换至可用节点,以保证您的网站正常访问。如您发现设置项被自动切换,可在此页面重新设置。
+提示:插件会定期检查节点可用性,并在节点不可用时自动切换至可用节点,以保证您的网站正常访问。如您发现设置项被自动切换,可重新设置或关闭自动监控功能。
帮助:您可以随时在此处调整个性化设置以便适应不同的业务场景,萌新请保持默认即可。此项目的发展离不开您的支持和建议,查看联系方式。
diff --git a/Service/Super.php b/Service/Super.php index d103155..1597550 100644 --- a/Service/Super.php +++ b/Service/Super.php @@ -199,6 +199,16 @@ class Super { 'cdnjs.admincdn.com' ] ); } + + /** + * jsDelivr 前端公共库替换 + */ + if ( ! empty( $this->settings['admincdn']['jsdelivr'] ) ) { + $this->page_str_replace( 'str_replace', [ + 'cdn.jsdelivr.net', + 'jsd.admincdn.com' + ] ); + } } /** @@ -211,6 +221,15 @@ class Super { add_filter( 'bp_gravatar_url', [ $this, 'get_cravatar_url' ], 1 ); add_filter( 'get_avatar_url', [ $this, 'get_cravatar_url' ], 1 ); } + + /** + * 文风字体 + */ + 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 ); + } ); + } } /** diff --git a/assets/css/fonts.css b/assets/css/fonts.css new file mode 100644 index 0000000..5b0941e --- /dev/null +++ b/assets/css/fonts.css @@ -0,0 +1,3 @@ +html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { + font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif; +} \ No newline at end of file diff --git a/assets/css/setting.css b/assets/css/setting.css index 99975fb..bf4544f 100644 --- a/assets/css/setting.css +++ b/assets/css/setting.css @@ -1,5 +1,5 @@ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { - font-family: "Source Han Sans SC", "Noto Sans CJK SC", "Source Han Sans CN", "Noto Sans SC", "Source Han Sans TC", "Noto Sans CJK TC", sans-serif, -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif; + font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif; } #wpcontent, #wpfooter { diff --git a/helpers.php b/helpers.php index e3e545d..c69e791 100644 --- a/helpers.php +++ b/helpers.php @@ -16,5 +16,6 @@ function get_settings() { 'cravatar' => 'cn', 'windfonts' => 'off', 'adblock' => 'off', + 'monitor' => 'on', ] ); } diff --git a/wp-china-yes.php b/wp-china-yes.php index fe0b3e5..51a627d 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.6.2 + * Version: 3.6.3 * License: GPLv3 or later * Text Domain: wp-china-yes * Domain Path: /languages @@ -19,7 +19,7 @@ namespace WenPai\ChinaYes; defined( 'ABSPATH' ) || exit; -define( 'CHINA_YES_VERSION', '3.6.2' ); +define( 'CHINA_YES_VERSION', '3.6.3' ); define( 'CHINA_YES_PLUGIN_FILE', __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 ) );