From 7f1b9a5672c4c0ca0093359aee7f777e8928d4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Fri, 23 Aug 2024 15:34:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cli=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Super.php | 18 +++++++++--------- wp-china-yes.php | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Service/Super.php b/Service/Super.php index 38518cf..5506a35 100644 --- a/Service/Super.php +++ b/Service/Super.php @@ -147,7 +147,7 @@ public function __construct() { global $concatenate_scripts; $concatenate_scripts = false; - $this->page_str_replace( 'preg_replace', [ + $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'] ) ] ); @@ -159,7 +159,7 @@ public function __construct() { * 前台静态加速 */ if ( ! empty( $this->settings['admincdn']['frontend'] ) ) { - $this->page_str_replace( 'preg_replace', [ + $this->page_str_replace( 'template_redirect', 'preg_replace', [ '#(?<=[(\"\'])(?:' . quotemeta( home_url() ) . ')?/(?:((?:wp-content|wp-includes)[^\"\')]+\.(css|js)[^\"\')]+))(?=[\"\')])#', 'https://public.admincdn.com/$0' ] ); @@ -169,7 +169,7 @@ public function __construct() { * Google 字体替换 */ if ( ! empty( $this->settings['admincdn']['googlefonts'] ) ) { - $this->page_str_replace( 'str_replace', [ + $this->page_str_replace( 'init', 'str_replace', [ 'fonts.googleapis.com', 'googlefonts.admincdn.com' ] ); @@ -179,7 +179,7 @@ public function __construct() { * Google 前端公共库替换 */ if ( ! empty( $this->settings['admincdn']['googleajax'] ) ) { - $this->page_str_replace( 'str_replace', [ + $this->page_str_replace( 'init', 'str_replace', [ 'ajax.googleapis.com', 'googleajax.admincdn.com' ] ); @@ -189,7 +189,7 @@ public function __construct() { * CDNJS 前端公共库替换 */ if ( ! empty( $this->settings['admincdn']['cdnjs'] ) ) { - $this->page_str_replace( 'str_replace', [ + $this->page_str_replace( 'init', 'str_replace', [ 'cdnjs.cloudflare.com/ajax/libs', 'cdnjs.admincdn.com' ] ); @@ -199,7 +199,7 @@ public function __construct() { * jsDelivr 前端公共库替换 */ if ( ! empty( $this->settings['admincdn']['jsdelivr'] ) ) { - $this->page_str_replace( 'str_replace', [ + $this->page_str_replace( 'init', 'str_replace', [ 'cdn.jsdelivr.net', 'jsd.admincdn.com' ] ); @@ -330,12 +330,12 @@ public function set_user_profile_picture_for_cravatar() { * @param $replace_func string 要调用的字符串关键字替换函数 * @param $param array 传递给字符串替换函数的参数 */ - private function page_str_replace( $replace_func, $param ) { + private function page_str_replace( $hook, $replace_func, $param ) { // CLI 下返回,防止影响缓冲区 - if ( class_exists( 'WP_CLI' ) ) { + if ( php_sapi_name() == 'cli' ) { return; } - add_action( 'template_redirect', function () use ( $replace_func, $param ) { + add_action( $hook, function () use ( $replace_func, $param ) { ob_start( function ( $buffer ) use ( $replace_func, $param ) { $param[] = $buffer; diff --git a/wp-china-yes.php b/wp-china-yes.php index be3c2fe..1fe9762 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.4 + * Version: 3.6.5 * License: GPLv3 or later * Text Domain: wp-china-yes * Domain Path: /languages @@ -19,7 +19,7 @@ defined( 'ABSPATH' ) || exit; -define( 'CHINA_YES_VERSION', '3.6.4' ); +define( 'CHINA_YES_VERSION', '3.6.5' ); 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 ) );