feat:更新设置界面为WP默认UI,增加谷歌字体、G家头像加速、去除自定义源功能

This commit is contained in:
sunxiyuan 2020-07-16 09:17:47 +08:00
parent f4ccf1ff1d
commit a86c806880
2 changed files with 213 additions and 4 deletions

View file

@ -24,6 +24,11 @@ if (is_admin()) {
require __DIR__ . '/vendor/loco-translate/loco.php';
}
/**
* 引入设置页
*/
require __DIR__ . '/setting.php';
/**
* 菜单注册
@ -38,13 +43,11 @@ if (is_admin()) {
add_submenu_page(
'wpcy',
'系统本土化',
'China Yes!!!',
'系统本土化',
'manage_options',
'wpcy-setting',
function () {
echo 'a';
},
'wpcy_options_page_html',
0
);
@ -60,4 +63,51 @@ if (is_admin()) {
3
);
});
/**
* 替换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('super_gravatar') == 1) {
$url = str_replace('api.wordpress.org', 'api.wp-china-yes.net', $url);
} else {
$url = str_replace('api.wordpress.org', 'api-original.wp-china-yes.net', $url);
}
$url = str_replace('downloads.wordpress.org', 'd.w.org.ibadboy.net', $url);
return wp_remote_request($url, $r);
}, 10, 3);
}
/**
* 替换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'
], '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);
});
});
}