特性:CDNJS前端公共库加速

This commit is contained in:
耗子 2022-04-13 12:24:06 +08:00 committed by GitHub
parent 391e3db4c3
commit ee63f3abae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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提供的国区定制API2 只是经代理加速的api.wordpress.org原版API
* wpapi用以标记用户所选的仓库api数值说明1 使用LitePress的API2 只是经代理加速的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>';
}