Skip to content

Commit

Permalink
fix: cli判断
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Aug 23, 2024
1 parent 73f4d6e commit 7f1b9a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Service/Super.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] )
] );
Expand All @@ -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'
] );
Expand All @@ -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'
] );
Expand All @@ -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'
] );
Expand All @@ -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'
] );
Expand All @@ -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'
] );
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions wp-china-yes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ) );
Expand Down

0 comments on commit 7f1b9a5

Please sign in to comment.