mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-04 20:19:53 +08:00
特性:增加管理后台加速功能——将WordPress核心静态文件的访问链接替换为jsDelivr提供的GitHub加速CDN
This commit is contained in:
parent
46563f3a02
commit
ef7e75513f
2 changed files with 44 additions and 1 deletions
28
setting.php
28
setting.php
|
@ -6,6 +6,11 @@ function wpcy_settings_init() {
|
|||
*/
|
||||
register_setting('wpcy', 'wpapi');
|
||||
|
||||
/**
|
||||
* super_admin用以标记用户是否启用管理后台加速功能
|
||||
*/
|
||||
register_setting('wpcy', 'super_admin');
|
||||
|
||||
/**
|
||||
* super_gravatar用以标记用户是否启用G家头像加速功能
|
||||
*/
|
||||
|
@ -31,6 +36,14 @@ function wpcy_settings_init() {
|
|||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_admin',
|
||||
'管理后台加速',
|
||||
'wpcy_field_super_admin_cb',
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_gravatar',
|
||||
'加速G家头像',
|
||||
|
@ -68,6 +81,21 @@ function wpcy_field_wpapi_cb() {
|
|||
<?php
|
||||
}
|
||||
|
||||
function wpcy_field_super_admin_cb() {
|
||||
$super_admin = get_option('super_admin');
|
||||
?>
|
||||
<label>
|
||||
<input type="radio" value="1" name="super_admin" <?php checked($super_admin, '1'); ?>>启用
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" value="2" name="super_admin" <?php checked($super_admin, '2'); ?>>禁用
|
||||
</label>
|
||||
<p class="description">
|
||||
将WordPress核心所依赖的静态资源切换到jsDelivr上加载,此选项极大的加快管理后台访问速度
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
function wpcy_field_super_gravatar_cb() {
|
||||
$super_gravatar = get_option('super_gravatar');
|
||||
?>
|
||||
|
|
|
@ -33,8 +33,9 @@ if (is_admin()) {
|
|||
/**
|
||||
* 初始化设置项
|
||||
*/
|
||||
if (empty(get_option('wpapi')) || empty(get_option('super_gravatar')) || empty(get_option('super_googlefonts'))) {
|
||||
if (empty(get_option('wpapi')) || empty(get_option('super_admin')) || empty(get_option('super_gravatar')) || empty(get_option('super_googlefonts'))) {
|
||||
update_option("wpapi", '2');
|
||||
update_option("super_admin", '1');
|
||||
update_option("super_gravatar", '1');
|
||||
update_option("super_googlefonts", '2');
|
||||
}
|
||||
|
@ -45,6 +46,7 @@ if (is_admin()) {
|
|||
*/
|
||||
register_deactivation_hook(__FILE__, function () {
|
||||
delete_option("wpapi");
|
||||
delete_option("super_admin");
|
||||
delete_option("super_gravatar");
|
||||
delete_option("super_googlefonts");
|
||||
});
|
||||
|
@ -82,6 +84,19 @@ if (is_admin()) {
|
|||
|
||||
return wp_remote_request($url, $r);
|
||||
}, 10, 3);
|
||||
|
||||
|
||||
/**
|
||||
* 将WordPress核心所依赖的静态文件访问链接替换为jsDelivr提供的CDN节点
|
||||
*/
|
||||
if (get_option('super_admin') == 1) {
|
||||
add_action('init', function () {
|
||||
ob_start(function ($buffer) {
|
||||
$buffer = str_replace(esc_url(home_url('/wp-includes/css/')), sprintf('https://cdn.jsdelivr.net/gh/WordPress/WordPress@%s/wp-includes/css/', $GLOBALS['wp_version']), $buffer);
|
||||
return str_replace(esc_url(home_url('/wp-includes/js/')), sprintf('https://cdn.jsdelivr.net/gh/WordPress/WordPress@%s/wp-includes/js/', $GLOBALS['wp_version']), $buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue