mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-08 06:56:08 +08:00
修复:未考虑AJAX加载时执行不必要代码的问题
This commit is contained in:
parent
ef7e75513f
commit
788d5fba6d
1 changed files with 47 additions and 43 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue