Merge pull request #58 from wp-china/develop

v3.2.0
This commit is contained in:
孙锡源 2020-10-07 13:43:09 +08:00 committed by GitHub
commit e424840950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 126 additions and 65 deletions

View file

@ -1 +0,0 @@
<?php

View file

@ -1,28 +1,64 @@
# WP-China-Yes
## 简介
一个革命性的插件从此中国人会拥有针对国内环境专门定制的WordPress以及一个由中国人主导的社区生态环境
WP中国本土化社区[WP-China.org][0]出品旨在将你的WordPress一键接入到本土生态体系中
## 安装
如果你期望参与测试可以直接Clone Master分支中的代码此处是功能模块基本完整的测试版本。
若期望用于正式环境请移步[发布列表][1],下载最新稳定版的压缩包后直接访问[http://你的域名/wp-admin/plugin-install.php][2],然后点击页面左上角的“上传插件”,上传安装即可。
## 插件截图
![图片无法加载](https://wp-china.org/wp-content/uploads/2020/10/QQ图片20201007131531.png)
## 主要特性
对WordPress核心所依赖的所有官方服务及谷歌字体提供包含中国大陆节点的全球加速支持
- 对来自wordpress.org的所有外部服务进行加速
- 对来自谷歌公共库的一些服务进行加速
- 对接[本土翻译平台][3]为WordPress本身及官方应用市场中的所有应用推送基于AI翻译+人工辅助校准的全量汉化包
- 使WordPress内置应用市场支持中文作品信息展示及中文语义化搜索开发中
- 使WordPress内置应用市场中支持选购国内开发者所推出的优秀作品并享受集成式的安装及更新推送服务开发中
为官方仓库的所有插件/主题追加基于机器翻译+人工辅助校准的全量汉化包插件端支持直接对翻译词条校准并实时生效校准内容同时也会被上传到wp-china.org用来改善翻译质量
## 问题反馈
需要着重说明一下:**任何问题都会在第一时间得到积极的处理**,所以,有问题尽管提。
为官方仓库的所有插件/主题追加中文作品信息显示支持,并支持中文语义化搜索及智能推荐(仍在开发中)
你可以选择以下三种方式反馈问题:
支持直接选购国内WordPress服务商的优秀作品及服务享受和官方原版仓库一致的安装/升级体验(仍在开发中)
1. 提交一个[Issue][4]
2. 在本土化社区的[论坛][5]中提交一个帖子
3. 加项目交流QQ群1046115671
无论选择何种方式提交问题,都希望你可以详细描述问题的表现及触发条件,这样对减少交流成本及快速定位问题有很大好处。
## 参与项目发展
对于普通用户来讲,最好的参与项目发展的方式就是帮助项目宣传推广及参与[翻译贡献][3]
如果你有好的Idea或是对参与项目开发有兴趣可以加项目交流QQ群1046115671
我想,对于在校大学生来讲,参与一个开源项目无疑是积累开发经验的最好方式。同时,工作并不是完全无偿的,项目赞助商会视情况为每位开发者提供周期性资金支持。
## 赞助商
### 金牌赞助
<img src="https://a0.wp-china-yes.net/wp-content/uploads/2020/08/weixiaoduo-logo-2020-300x134.png" width="127" height="57" alt="" class="wp-image-968 alignnone size-medium">
### 服务器及管理软件
<img src="https://a0.wp-china-yes.net/wp-content/uploads/2020/08/logo.png" width="127" height="79" alt="" class="wp-image-763 alignnone size-full">
<img src="https://a0.wp-china-yes.net/wp-content/uploads/2020/08/又拍云_logo5-300x153.png" width="137" height="70" alt="" class="wp-image-764 alignnone size-medium" srcset="https://a0.wp-china-yes.net/wp-content/uploads/2020/08/又拍云_logo5-300x153.png 300w, https://a0.wp-china-yes.net/wp-content/uploads/2020/08/又拍云_logo5-480x244.png 480w, https://a0.wp-china-yes.net/wp-content/uploads/2020/08/又拍云_logo5.png 594w" sizes="(max-width: 137px) 100vw, 137px">
<img src="https://a0.wp-china-yes.net/wp-content/uploads/2020/08/logo-s.gif" width="175" height="44" alt="" class="wp-image-762 alignnone size-full">
## 关于繁体中文支持
目前该项目主要由我一个人开发推进,精力实在有限,暂时不能为繁体中文提供支持,但是未来会尽量覆盖。
再次声明:现阶段不支持繁体中文无关任何立场问题,单纯就是精力不足,为了项目发展,只能先顾及多数,请一定不要过分解读!
[0]: https://wp-china.org
[1]: https://github.com/wp-china/wp-china-yes/releases
[2]: http://你的域名/wp-admin/plugin-install.php
[3]: https://translate.wp-china.org
[4]: https://github.com/wp-china/wp-china-yes/issues
[5]: https://wp-china.org/forums

View file

@ -4,7 +4,7 @@
* Description: 将你的WordPress接入本土生态体系中这将为你提供一个更贴近中国人使用习惯的WordPress
* Author: WP中国本土化社区
* Author URI:https://wp-china.org/
* Version: 3.1.3
* Version: 3.2.0
* Network: True
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
@ -35,12 +35,11 @@ class WP_CHINA_YES {
/**
* 初始化设置项
*/
if (empty(get_option('wpapi')) || empty(get_option('super_admin')) || empty(get_option('super_gravatar')) || empty(get_option('super_googlefonts'))) {
update_option("wpapi", get_option('wpapi') ?: '2');
update_option("super_admin", get_option('super_admin') ?: '1');
update_option("super_gravatar", get_option('super_gravatar') ?: '1');
update_option("super_googlefonts", get_option('super_googlefonts') ?: '2');
}
update_option("wpapi", get_option('wpapi') ?: '2');
update_option("super_admin", get_option('super_admin') ?: '1');
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');
/**
@ -51,6 +50,7 @@ class WP_CHINA_YES {
delete_option("super_admin");
delete_option("super_gravatar");
delete_option("super_googlefonts");
delete_option("super_googleajax");
});
@ -72,12 +72,11 @@ class WP_CHINA_YES {
/**
* 将WordPress核心所依赖的静态文件访问链接替换为公共资源节点
*/
if (get_option('super_admin') == 1) {
add_action('init', function () {
ob_start(function ($buffer) {
return preg_replace('~' . home_url('/') . '(wp-admin|wp-includes)/(css|js)/~', sprintf('https://a2.wp-china-yes.net/WordPress@%s/$1/$2/', $GLOBALS['wp_version']), $buffer);
});
});
if (get_option('super_admin') != 2) {
$this->page_str_replace('preg_replace', [
'~' . home_url('/') . '(wp-admin|wp-includes)/(css|js)/~',
sprintf('https://a2.wp-china-yes.net/WordPress@%s/$1/$2/', $GLOBALS['wp_version'])
], get_option('super_admin'));
}
}
@ -121,7 +120,7 @@ class WP_CHINA_YES {
add_settings_field(
'wpcy_field_select_super_admin',
'管理后台加速',
'加速管理后台',
[$this, 'field_super_admin_cb'],
'wpcy',
'wpcy_section_main'
@ -142,6 +141,14 @@ class WP_CHINA_YES {
'wpcy',
'wpcy_section_main'
);
add_settings_field(
'wpcy_field_select_super_googleajax',
'加速谷歌前端公共库',
[$this, 'field_super_googleajax_cb'],
'wpcy',
'wpcy_section_main'
);
});
/**
@ -186,12 +193,15 @@ class WP_CHINA_YES {
/**
* 替换谷歌字体为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 (get_option('super_googlefonts') != 2) {
$this->page_str_replace('str_replace', ['fonts.googleapis.com', 'googlefonts.wp-china-yes.net'], get_option('super_googlefonts'));
}
/**
* 替换谷歌前端公共库为WP-China.org维护的大陆加速节点
*/
if (get_option('super_googleajax') != 2) {
$this->page_str_replace('str_replace', ['ajax.googleapis.com', 'googleajax.wp-china-yes.net'], get_option('super_googleajax'));
}
}
}
@ -218,48 +228,19 @@ class WP_CHINA_YES {
}
public function 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核心所依赖的静态文件切换为公共资源此选项极大的加快管理后台访问速度
</p>
<?php
$this->field_cb('super_admin' , '将WordPress核心所依赖的静态文件切换为公共资源此选项极大的加快管理后台访问速度', true);
}
public function field_super_gravatar_cb() {
$super_gravatar = get_option('super_gravatar');
?>
<label>
<input type="radio" value="1" name="super_gravatar" <?php checked($super_gravatar, '1'); ?>>启用
</label>
<label>
<input type="radio" value="2" name="super_gravatar" <?php checked($super_gravatar, '2'); ?>>禁用
</label>
<p class="description">
为Gravatar头像加速推荐所有用户启用该选项
</p>
<?php
$this->field_cb('super_gravatar' , '为Gravatar头像加速推荐所有用户启用该选项');
}
public function field_super_googlefonts_cb() {
$super_googlefonts = get_option('super_googlefonts');
?>
<label>
<input type="radio" value="1" name="super_googlefonts" <?php checked($super_googlefonts, '1'); ?>>启用
</label>
<label>
<input type="radio" value="2" name="super_googlefonts" <?php checked($super_googlefonts, '2'); ?>>禁用
</label>
<p class="description">
请只在主题包含谷歌字体的情况下才启用该选项,以免造成不必要的性能损失
</p>
<?php
$this->field_cb('super_googlefonts' , '请只在包含谷歌字体的情况下才启用该选项,以免造成不必要的性能损失');
}
public function field_super_googleajax_cb() {
$this->field_cb('super_googleajax' , '请只在包含谷歌前端公共库的情况下才启用该选项,以免造成不必要的性能损失');
}
public function options_page_html() {
@ -268,6 +249,7 @@ class WP_CHINA_YES {
update_option("super_admin", sanitize_text_field($_POST['super_admin']));
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']));
echo '<div class="notice notice-success settings-error is-dismissible"><p><strong>设置已保存</strong></p></div>';
}
@ -294,4 +276,48 @@ class WP_CHINA_YES {
</p>
<?php
}
private function field_cb($option_name, $description, $is_global = false) {
$option_value = get_option($option_name);
if (!$is_global):
?>
<label>
<input type="radio" value="3" name="<?php echo $option_name; ?>" <?php checked($option_value, '3'); ?>>前台启用
</label>
<label>
<input type="radio" value="4" name="<?php echo $option_name; ?>" <?php checked($option_value, '4'); ?>>后台启用
</label>
<?php endif; ?>
<label>
<input type="radio" value="1" name="<?php echo $option_name; ?>" <?php checked($option_value, '1'); ?>><?php echo $is_global ? '启用' : '全局启用' ?>
</label>
<label>
<input type="radio" value="2" name="<?php echo $option_name; ?>" <?php checked($option_value, '2'); ?>>禁用
</label>
<p class="description">
<?php echo $description; ?>
</p>
<?php
}
/**
* @param $replace_func string 要调用的字符串关键字替换函数
* @param $param array 传递给字符串替换函数的参数
* @param $level int 替换级别1.全局替换 3.前台替换 4.后台替换
*/
private function page_str_replace($replace_func, $param, $level) {
if ($level == 3 && is_admin()) {
return;
} elseif ($level == 4 && !is_admin()) {
return;
}
add_action('init', function () use ($replace_func, $param) {
ob_start(function ($buffer) use ($replace_func, $param) {
$param[] = $buffer;
return call_user_func_array($replace_func, $param);
});
});
}
}