From 788d5fba6dd3ec276496b8b81dc9d346067eb0db Mon Sep 17 00:00:00 2001 From: sunxiyuan Date: Wed, 26 Aug 2020 17:46:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9C=AA=E8=80=83?= =?UTF-8?q?=E8=99=91AJAX=E5=8A=A0=E8=BD=BD=E6=97=B6=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E8=A6=81=E4=BB=A3=E7=A0=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wp-china-yes.php | 90 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/wp-china-yes.php b/wp-china-yes.php index 3104b27..22ac640 100644 --- a/wp-china-yes.php +++ b/wp-china-yes.php @@ -9,7 +9,7 @@ * License URI: http://www.gnu.org/licenses/gpl-3.0.html */ -if (is_admin()) { +if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) { /** * 引入设置页 */ @@ -66,26 +66,6 @@ if (is_admin()) { }); - /** - * 替换api.wordpress.org和downloads.wordpress.org为WP-China.org维护的大陆加速节点 - * URL替换代码来自于我爱水煮鱼(http://blog.wpjam.com/)开发的WPJAM Basic插件 - */ - add_filter('pre_http_request', function ($preempt, $r, $url) { - if ( ! stristr($url, 'api.wordpress.org') && ! stristr($url, 'downloads.wordpress.org')) { - return false; - } - if (get_option('wpapi') == 1) { - $url = str_replace('api.wordpress.org', 'api.wp-china-yes.net', $url); - $url = str_replace('downloads.wordpress.org', 'download.wp-china-yes.net', $url); - } else { - $url = str_replace('api.wordpress.org', 'api.w.org.ibadboy.net', $url); - $url = str_replace('downloads.wordpress.org', 'd.w.org.ibadboy.net', $url); - } - - return wp_remote_request($url, $r); - }, 10, 3); - - /** * 将WordPress核心所依赖的静态文件访问链接替换为jsDelivr提供的CDN节点 */ @@ -100,30 +80,54 @@ if (is_admin()) { } -/** - * 替换G家头像为WP-China.org维护的大陆加速节点 - */ -if (get_option('super_gravatar') == 1) { - add_filter('get_avatar', function ($avatar) { - return str_replace([ - 'www.gravatar.com', - '0.gravatar.com', - '1.gravatar.com', - '2.gravatar.com', - 'secure.gravatar.com', - 'cn.gravatar.com' - ], 'gravatar.wp-china-yes.net', $avatar); - }); +if (is_admin()) { + /** + * 替换api.wordpress.org和downloads.wordpress.org为WP-China.org维护的大陆加速节点 + * URL替换代码来自于我爱水煮鱼(http://blog.wpjam.com/)开发的WPJAM Basic插件 + */ + add_filter('pre_http_request', function ($preempt, $r, $url) { + if (!stristr($url, 'api.wordpress.org') && !stristr($url, 'downloads.wordpress.org')) { + return false; + } + if (get_option('wpapi') == 1) { + $url = str_replace('api.wordpress.org', 'api.wp-china-yes.net', $url); + $url = str_replace('downloads.wordpress.org', 'download.wp-china-yes.net', $url); + } else { + $url = str_replace('api.wordpress.org', 'api.w.org.ibadboy.net', $url); + $url = str_replace('downloads.wordpress.org', 'd.w.org.ibadboy.net', $url); + } + + return wp_remote_request($url, $r); + }, 10, 3); } -/** - * 替换谷歌字体为WP-China.org维护的大陆加速节点 - */ -if (get_option('super_googlefonts') == 1) { - add_action('init', function () { - ob_start(function ($buffer) { - return str_replace('fonts.googleapis.com', 'googlefonts.wp-china-yes.net', $buffer); +if (!(defined('DOING_AJAX') && DOING_AJAX)) { + /** + * 替换G家头像为WP-China.org维护的大陆加速节点 + */ + if (get_option('super_gravatar') == 1) { + add_filter('get_avatar', function ($avatar) { + return str_replace([ + 'www.gravatar.com', + '0.gravatar.com', + '1.gravatar.com', + '2.gravatar.com', + 'secure.gravatar.com', + 'cn.gravatar.com' + ], 'gravatar.wp-china-yes.net', $avatar); }); - }); + } + + + /** + * 替换谷歌字体为WP-China.org维护的大陆加速节点 + */ + if (get_option('super_googlefonts') == 1) { + add_action('init', function () { + ob_start(function ($buffer) { + return str_replace('fonts.googleapis.com', 'googlefonts.wp-china-yes.net', $buffer); + }); + }); + } }