mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-03 11:11:30 +08:00
特性:CDNJS前端公共库加速
This commit is contained in:
parent
391e3db4c3
commit
ee63f3abae
1 changed files with 31 additions and 1 deletions
|
@ -53,6 +53,7 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
update_option( "super_gravatar", get_option( 'super_gravatar' ) ?: '1' );
|
||||
update_option( "super_googlefonts", get_option( 'super_googlefonts' ) ?: '2' );
|
||||
update_option( "super_googleajax", get_option( 'super_googleajax' ) ?: '2' );
|
||||
update_option( "super_cdnjs", get_option( 'super_cdnjs' ) ?: '2' );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -64,6 +65,7 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
delete_option( "super_gravatar" );
|
||||
delete_option( "super_googlefonts" );
|
||||
delete_option( "super_googleajax" );
|
||||
delete_option( "super_cdnjs" );
|
||||
} );
|
||||
|
||||
|
||||
|
@ -103,7 +105,7 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
if ( is_admin() || wp_doing_cron() ) {
|
||||
add_action( 'admin_init', function () {
|
||||
/**
|
||||
* wpapi用以标记用户所选的仓库api,数值说明:1 使用由WP-China.org提供的国区定制API,2 只是经代理加速的api.wordpress.org原版API
|
||||
* wpapi用以标记用户所选的仓库api,数值说明:1 使用LitePress的API,2 只是经代理加速的api.wordpress.org原版API
|
||||
*/
|
||||
register_setting( 'wpcy', 'wpapi' );
|
||||
|
||||
|
@ -121,6 +123,11 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
* super_googlefonts用以标记用户是否启用谷歌字体加速功能
|
||||
*/
|
||||
register_setting( 'wpcy', 'super_googlefonts' );
|
||||
|
||||
/**
|
||||
* super_cdnjs用以标记用户是否启用CDNJS加速功能
|
||||
*/
|
||||
register_setting( 'wpcy', 'super_cdnjs' );
|
||||
|
||||
add_settings_section(
|
||||
'wpcy_section_main',
|
||||
|
@ -168,6 +175,14 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_cdnjs',
|
||||
'加速CDNJS前端公共库',
|
||||
[ $this, 'field_super_cdnjs_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
} );
|
||||
|
||||
/**
|
||||
|
@ -224,6 +239,16 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
'gajax.cdn.wepublish.cn'
|
||||
], get_option( 'super_googleajax' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换CDNJS前端公共库为WePublish维护的加速节点
|
||||
*/
|
||||
if ( get_option( 'super_cdnjs' ) != 2 ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'cdnjs.cloudflare.com/ajax/libs',
|
||||
'cdnjs.cdn.wepublish.cn'
|
||||
], get_option( 'super_cdnjs' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -312,6 +337,10 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
public function field_super_googleajax_cb() {
|
||||
$this->field_cb( 'super_googleajax', '请只在包含谷歌前端公共库的情况下才启用该选项,以免造成不必要的性能损失' );
|
||||
}
|
||||
|
||||
public function field_super_googleajax_cb() {
|
||||
$this->field_cb( 'super_cdnjs', '请只在包含CDNJS前端公共库的情况下才启用该选项,以免造成不必要的性能损失' );
|
||||
}
|
||||
|
||||
public function options_page_html() {
|
||||
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
|
||||
|
@ -320,6 +349,7 @@ if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
|||
update_option( "super_gravatar", sanitize_text_field( $_POST['super_gravatar'] ) );
|
||||
update_option( "super_googlefonts", sanitize_text_field( $_POST['super_googlefonts'] ) );
|
||||
update_option( "super_googleajax", sanitize_text_field( $_POST['super_googleajax'] ) );
|
||||
update_option( "super_cdnjs", sanitize_text_field( $_POST['super_cdnjs'] ) );
|
||||
|
||||
echo '<div class="notice notice-success settings-error is-dismissible"><p><strong>设置已保存</strong></p></div>';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue