mirror of
https://github.com/WenPai-org/wp-china-yes.git
synced 2025-08-03 11:11:30 +08:00
refactor: 全局重构
This commit is contained in:
parent
af8107006b
commit
e1a6083779
16 changed files with 1127 additions and 438 deletions
101
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
101
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
name: 报告问题 (Bug Report)
|
||||
description: 创建一个报告以帮助我们改进 (Create a report to help us improve)
|
||||
title: "[Bug Report]: "
|
||||
labels: ["bug"]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**请仅使用 简体中文 或 英文 进行填写**
|
||||
**Please only use Simplified Chinese or English to fill in**
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 在提问之前 (Before asking)
|
||||
description: |
|
||||
提问之前,先回答几个小问题。
|
||||
Before asking questions, answer a few quick questions.
|
||||
options:
|
||||
- label: 我已经搜索了现有的 Issues 和 Discussions (I've searched the existing Issues and Discussions)
|
||||
required: true
|
||||
- label: 我已经阅读了 README 中除版本记录以外的所有内容 (I've read everything in the README except the version notes)
|
||||
required: true
|
||||
- label: 我在提问题之前至少花费了 5 分钟来思考和准备 (I spend at least 5 minutes thinking and preparing before asking a question)
|
||||
required: true
|
||||
- label: 这个问题出现在最新版的 WP-China-Yes 上 (This question appears on the latest version of WP-China-Yes)
|
||||
required: false
|
||||
- label: 我使用过旧版的 WP-China-Yes 并且没有出现这个问题 (I've used an older version of WP-China-Yes and didn't have this problem)
|
||||
required: false
|
||||
- label: 这个问题出现了至少 3 次 (This question has occurred at least 3 times)
|
||||
required: false
|
||||
- type: textarea
|
||||
id: describe
|
||||
attributes:
|
||||
label: 描述问题 (Describe the problem)
|
||||
description: |
|
||||
简明概要地描述你遇到的问题。
|
||||
Briefly describe the problem you are having.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: 预期行为 (Expected behavior)
|
||||
description: |
|
||||
简明概要地描述你期望发生的事情。
|
||||
Briefly describe what you expect to happen.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduce
|
||||
attributes:
|
||||
label: 如何复现 (How to reproduce)
|
||||
description: |
|
||||
重现该问题的详细步骤。
|
||||
Detailed steps to reproduce the problem.
|
||||
value: |
|
||||
1. 安装 WP-China-Yes
|
||||
2. 设置 '...'
|
||||
3. 点击 '...'
|
||||
4. 出现问题
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: 相关日志 (Related logs)
|
||||
description: |
|
||||
请复制并粘贴任何相关的日志输出。
|
||||
Please copy and paste any relevant log output.
|
||||
可以把文件拖入这个区域以添加日志文件。
|
||||
Files can be dragged into this area to add log files.
|
||||
日志文件可通过开启 WordPress 的调试模式获取。
|
||||
Log files can be accessed by enabling WordPress debug mode.
|
||||
render: Text
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: 截图 (Screenshots)
|
||||
description: |
|
||||
如果有,添加屏幕截图可帮助更快定位你的问题。
|
||||
If so, adding screenshots can help locate your issue faster.
|
||||
可以复制图片后在此区域内粘贴以添加图片。
|
||||
Pictures can be copied and pasted in this area to add pictures.
|
||||
如有必要,使用马赛克遮盖敏感信息。
|
||||
Use a mosaic to obscure sensitive information if necessary.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: others
|
||||
attributes:
|
||||
label: 还有别的吗 (Anything else)
|
||||
description: |
|
||||
运行环境?浏览器?WordPress 版本?相关的配置?链接?参考资料?
|
||||
Environment? Browser? WordPress version? Related configuration? Link? References?
|
||||
任何能让我们对你所遇到的问题有更多了解的东西。
|
||||
Anything that can give us more insight into the problem you're having.
|
||||
validations:
|
||||
required: false
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 讨论、问答和非项目问题 (Discussions, questions, and non-project issues)
|
||||
url: https://jq.qq.com/?_wv=1027&k=I1oJKSTH
|
||||
about: 其他不明之处,请移步我们的QQ群 12370907 (For other unclear things, please move to our qq group 12370907)
|
55
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
55
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
name: 功能请求 (Feature request)
|
||||
description: 为这个项目提出一个想法 (Suggest an idea for this project)
|
||||
title: "[Feature Request]: "
|
||||
labels: ["enhancement"]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**请仅使用 简体中文 或 英文 进行填写**
|
||||
**Please only use Simplified Chinese or English to fill in**
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: 在提问之前 (Before asking)
|
||||
description: |
|
||||
提问之前,先回答几个小问题。
|
||||
Before asking questions, answer a few quick questions.
|
||||
options:
|
||||
- label: 我已经搜索了全部 Issues 和 Commits (I have searched all Issues and Commits)
|
||||
required: true
|
||||
- label: 它们当中没有我将要提交的新功能 (None of them have new feature that I'm going to submit)
|
||||
required: true
|
||||
- type: textarea
|
||||
id: feature
|
||||
attributes:
|
||||
label: 描述功能 (Describe feature)
|
||||
description: |
|
||||
简明概要地描述你的新功能,以及它将解决什么问题。
|
||||
Briefly describe your new feature and what problem it will solve.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: workflow
|
||||
attributes:
|
||||
label: 工作流程 (Workflow)
|
||||
description: |
|
||||
请向我们提供有关该功能的实现流程。
|
||||
Please provide us with the implementation flow for this feature.
|
||||
value: |
|
||||
1. 新建文件 ....
|
||||
2. 添加函数 ....
|
||||
3. ...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: others
|
||||
attributes:
|
||||
label: 还有别的吗 (Anything else)
|
||||
description: |
|
||||
运行环境?浏览器?WordPress 版本?相关的配置?链接?参考资料?
|
||||
Environment? Browser? WordPress version? Related configuration? Link? References?
|
||||
任何能让我们对该功能的实现有更多帮助的东西。
|
||||
Anything that can help us more with the implementation of this feature.
|
||||
validations:
|
||||
required: false
|
31
.github/workflows/update-changelog.yml
vendored
Normal file
31
.github/workflows/update-changelog.yml
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
name: "Update Changelog"
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
|
||||
- name: Update Changelog
|
||||
uses: stefanzweifel/changelog-updater-action@v1
|
||||
with:
|
||||
latest-version: ${{ github.event.release.tag_name }}
|
||||
release-notes: ${{ github.event.release.body }}
|
||||
|
||||
- name: Commit updated CHANGELOG
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
branch: main
|
||||
commit_message: "docs: Update CHANGELOG"
|
||||
file_pattern: CHANGELOG.md
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
vendor
|
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to `WP-China-Yes` will be documented in this file.
|
||||
|
98
Plugin.php
Normal file
98
Plugin.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WenPai\ChinaYes\Service\Base;
|
||||
use WenPai\ChinaYes\Service\Setting;
|
||||
|
||||
class Plugin {
|
||||
|
||||
/**
|
||||
* 创建一个插件实例
|
||||
*/
|
||||
public function __construct() {
|
||||
new Base();
|
||||
new Setting();
|
||||
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件激活时执行
|
||||
*/
|
||||
public static function activate() {
|
||||
// 兼容性检测
|
||||
self::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件删除时执行
|
||||
*/
|
||||
public static function uninstall() {
|
||||
// 清除设置
|
||||
is_multisite() ? delete_site_option( 'wp_china_yes' ) : delete_option( 'wp_china_yes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件加载时执行
|
||||
*/
|
||||
public function plugins_loaded() {
|
||||
load_plugin_textdomain( 'wp-china-yes', false, plugin_dir_path( PLUGIN_FILE ) . 'languages' );
|
||||
add_action( 'admin_notices', [ $this, 'admin_notices' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件兼容性检测函数
|
||||
*/
|
||||
public static function check() {
|
||||
$notices = [];
|
||||
if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
|
||||
deactivate_plugins( 'wp-china-yes/wp-china-yes.php' );
|
||||
$notices[] = '<div class="notice notice-error"><p>' . sprintf( __( 'WP-China-Yes 插件需要 PHP 5.6.0 或更高版本,当前版本为 %s,插件已自动禁用。',
|
||||
'wp-china-yes' ),
|
||||
PHP_VERSION ) . '</p></div>';
|
||||
}
|
||||
if ( is_plugin_active( 'wp-china-no/wp-china-no.php' ) ) {
|
||||
deactivate_plugins( 'wp-china-no/wp-china-no.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>' . __( '检测到旧版插件 WP-China-No,已自动禁用!', 'wp-china-yes' ) . '</strong></p>
|
||||
</div>';
|
||||
}
|
||||
if ( is_plugin_active( 'wp-china-plus/wp-china-plus.php' ) ) {
|
||||
deactivate_plugins( 'wp-china-plus/wp-china-plus.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>' . __( '检测到不兼容的插件 WP-China-Plus,已自动禁用!', 'wp-china-yes' ) . '</strong></p>
|
||||
</div>';
|
||||
}
|
||||
if ( is_plugin_active( 'kill-429/kill-429.php' ) ) {
|
||||
deactivate_plugins( 'kill-429/kill-429.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>' . __( '检测到不兼容的插件 Kill 429,已自动禁用!', 'wp-china-yes' ) . '</strong></p>
|
||||
</div>';
|
||||
|
||||
}
|
||||
// 代理服务器检测
|
||||
if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) ) {
|
||||
$notices[] = '<div class="notice notice-warning is-dismissible">
|
||||
<p><strong>' . __( '检测到已在 WordPress 配置文件中设置代理服务器,这可能会导致插件无法正常工作!',
|
||||
'wp-china-yes' ) . '</strong></p>
|
||||
</div>';
|
||||
}
|
||||
|
||||
set_transient( 'wp-china-yes-admin-notices', $notices, 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出管理后台提示信息
|
||||
*/
|
||||
public function admin_notices() {
|
||||
$notices = get_transient( 'wp-china-yes-admin-notices' );
|
||||
if ( $notices ) {
|
||||
foreach ( $notices as $notice ) {
|
||||
echo $notice;
|
||||
}
|
||||
delete_transient( 'wp-china-yes-admin-notices' );
|
||||
}
|
||||
}
|
||||
}
|
29
Service/Base.php
Normal file
29
Service/Base.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Base
|
||||
* 插件主服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Base {
|
||||
|
||||
public function __construct() {
|
||||
/**
|
||||
* 插件列表页中所有插件增加「参与翻译」链接
|
||||
*/
|
||||
add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) {
|
||||
$links[] = '<a target="_blank" href="https://translate.wenpai.org/projects/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">参与翻译</a>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
|
||||
// 加速服务
|
||||
new Super();
|
||||
// 更新服务
|
||||
new Update();
|
||||
}
|
||||
}
|
267
Service/Setting.php
Normal file
267
Service/Setting.php
Normal file
|
@ -0,0 +1,267 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use TheTNB\Setting\API;
|
||||
|
||||
/**
|
||||
* Class Setting
|
||||
* 插件设置服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Setting {
|
||||
private $setting_api;
|
||||
|
||||
public function __construct() {
|
||||
$this->setting_api = new API();
|
||||
add_action( 'admin_init', [ $this, 'admin_init' ] );
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'admin_menu' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载设置项
|
||||
*/
|
||||
public function admin_init() {
|
||||
|
||||
$sections = [
|
||||
[
|
||||
'id' => 'wp_china_yes',
|
||||
'title' => __( '设置', 'wp-china-yes' )
|
||||
]
|
||||
];
|
||||
|
||||
$fields = [
|
||||
'wp_china_yes' => [
|
||||
[
|
||||
'name' => 'store',
|
||||
'label' => __( '应用市场', 'wp-china-yes' ),
|
||||
'desc' => __( '<a href="https://wpmirror.com/" target="_blank">官方加速源(WPMirror)</a>:直接从 .org 反代至大陆分发;文派存储库:中国境内自建托管仓库,同时集成文派集市产品更新。',
|
||||
'wp-china-yes' ),
|
||||
'type' => 'radio',
|
||||
'default' => 'wenpai',
|
||||
'options' => [
|
||||
'proxy' => '官方镜像',
|
||||
'wenpai' => '文派中国',
|
||||
'off' => '不启用'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'admincdn',
|
||||
'label' => __( '萌芽加速', 'wp-china-yes' ),
|
||||
'desc' => __( '<a href="https://admincdn.com/" target="_blank">萌芽加速(adminCDN)</a>:将 WordPress 依赖的静态文件切换为公共资源,加快网站访问速度。您可按需启用需要加速的项目,更多细节控制和功能,请关注 adminCDN 项目。',
|
||||
'wp-china-yes' ),
|
||||
'type' => 'multicheck',
|
||||
'default' => [
|
||||
'admin' => 'admin',
|
||||
],
|
||||
'options' => [
|
||||
'admin' => '后台加速',
|
||||
'frontend' => '前台加速',
|
||||
'googlefonts' => 'Google 字体',
|
||||
'googleajax' => 'Google 前端公共库',
|
||||
'cdnjs' => 'CDNJS 前端公共库'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'cravatar',
|
||||
'label' => __( '初认头像', 'wp-china-yes' ),
|
||||
'desc' => __( '<a href="https://cravatar.com/" target="_blank">初认头像(Cravatar)</a>:是 Gravatar 在中国的完美替代方案,您可以在 https://cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。(任何开发者均可在自己的产品中集成该服务,不局限于 WordPress)',
|
||||
'wp-china-yes' ),
|
||||
'type' => 'radio',
|
||||
'default' => 'cn',
|
||||
'options' => [
|
||||
'cn' => '全局启用',
|
||||
'global' => '国际线路',
|
||||
'weavatar' => '备用源',
|
||||
'off' => '不启用'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'windfonts',
|
||||
'label' => __( '文风字体', 'wp-china-yes' ),
|
||||
'desc' => __( '<a href="https://windfonts.com/" target="_blank">文风字体(Windfonts)</a>:即将为您的网页渲染中文字体并对主题、插件内的 Google 字体进行加速。',
|
||||
'wp-china-yes' ),
|
||||
'type' => 'radio',
|
||||
'default' => 'off',
|
||||
'options' => [
|
||||
'off' => '即将上线',
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'adblock',
|
||||
'label' => __( '广告拦截', 'wp-china-yes' ),
|
||||
'desc' => __( '<a href="https://wp-china-yes.com/ads" target="_blank">文派叶子🍃(WP-China-Yes)</a>:独家特色功能,让您拥有清爽整洁的 WordPress 后台,清除各类常用插件侵入式后台广告、通知及无用信息;启用后若存在异常拦截,请切换为手动模式,查看<a href="https://wp-china-yes.com/" target="_blank">可优化插件列表</a>。',
|
||||
'wp-china-yes' ),
|
||||
'type' => 'radio',
|
||||
'default' => 'off',
|
||||
'options' => [
|
||||
'off' => '即将上线',
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->setting_api->set_sections( $sections );
|
||||
$this->setting_api->set_fields( $fields );
|
||||
$this->setting_api->admin_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载设置页面
|
||||
*/
|
||||
public function admin_menu() {
|
||||
// 后台设置
|
||||
add_submenu_page(
|
||||
is_multisite() ? 'settings.php' : 'options-general.php',
|
||||
esc_html__( 'WP-China-Yes', 'wp-china-yes' ),
|
||||
esc_html__( 'WP-China-Yes', 'wp-china-yes' ),
|
||||
is_multisite() ? 'manage_network_options' : 'manage_options',
|
||||
'wp-china-yes',
|
||||
[ $this, 'setting_page' ]
|
||||
);
|
||||
// 插件页设置
|
||||
add_filter( 'plugin_action_links', function ( $links, $file ) {
|
||||
if ( 'wp-china-yes/wp-china-yes.php' !== $file ) {
|
||||
return $links;
|
||||
}
|
||||
$settings_link = '<a href="' . add_query_arg( array( 'page' => 'wp-china-yes' ),
|
||||
is_multisite() ? 'settings.php' : 'options-general.php' ) . '">' . esc_html__( '设置',
|
||||
'wp-china-yes' ) . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置页面模版
|
||||
*/
|
||||
public function setting_page() {
|
||||
echo '<h1>WP-China-Yes</h1>';
|
||||
echo '<h3>将您的 WordPress 接入本土生态体系,这将为您提供一个更贴近中国人使用习惯的 WordPress。</h3><h4>100% 开源代码,一起参与文派(WordPress)软件国产化进程,打造属于您自己的开源自助建站程序。</h4>';
|
||||
echo <<<HTML
|
||||
<style>
|
||||
.container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
}
|
||||
.left-column, .right-column {
|
||||
width: 100%;
|
||||
}
|
||||
.left-column {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.right-column {
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
.card {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.13);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.card h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
.card a {
|
||||
text-decoration: none;
|
||||
}
|
||||
.card-body, .card-footer {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.sponsor-logos {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sponsor-logos img {
|
||||
width: 30%;
|
||||
margin-bottom: 12px;
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.container {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
.left-column {
|
||||
width: 70%;
|
||||
}
|
||||
.right-column {
|
||||
width: 30%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="container">
|
||||
<div class="left-column">
|
||||
HTML;
|
||||
$this->setting_api->show_navigation();
|
||||
$this->setting_api->show_forms();
|
||||
|
||||
echo <<<HTML
|
||||
</div>
|
||||
<div class="right-column">
|
||||
<div class="card">
|
||||
<h3>项目简介</h3>
|
||||
<div class="card-body">
|
||||
文派叶子 🍃(WP-China-Yes)是一款不可多得的 WordPress 系统底层优化和生态基础设施软件。项目起源于 2019 年,专为解决困扰了中国互联网数十年的特色问题而存在。此为文派开源(WenPai.org)的一部分。
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a class="button button-primary" href="https://wp-china-yes.com/" target="_blank">了解更多</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二个卡片 -->
|
||||
<div class="card">
|
||||
<h3>赞助商</h3>
|
||||
<div class="card-body sponsor-logos">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/feibisi-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/shujue-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/upyun-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/wenpai-logo@2X.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/wpsaas-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/lingding-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/weixiaoduo-logo-2020.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/modiqi-logo.png">
|
||||
<img src="https://wp-china-yes.com/wp-content/uploads/2023/08/kekechong-logo-1.png">
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a class="button button-primary" href="https://wp-china-yes.com/about/sponsor" target="_blank">成为赞助商</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第三个卡片 -->
|
||||
<div class="card">
|
||||
<h3>建站套件</h3>
|
||||
<div class="card-body">
|
||||
<ul>
|
||||
<li><a href="https://wenpai.org/plugins/wpicp-license" target="_blank">WPICP License 备案号管理器</a></li>
|
||||
<li><a href="https://wenpai.org/plugins/wpavatar/" target="_blank">WPAvatar 文派头像</a></li>
|
||||
<li><a href="https://wenpai.org/plugins/wpsite-shortcode/" target="_blank">WPSite Shortcode 网站简码</a></li>
|
||||
<li><a href="https://wenpai.org/plugins/wpfanyi-import/" target="_blank">WPfanyi Import 翻译导入器</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a class="button button-primary" href="https://wp-china-yes.com/products" target="_blank">一键安装</a>
|
||||
<a class="button button-primary" href="https://wp-china-yes.com" target="_blank">功能请求</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>提示:此处选项设置并不与任何文派插件及独立功能扩展冲突,可放心安装启用。</p>
|
||||
<p>帮助:您可以随时在此处调整个性化设置以便适应不同的业务场景,萌新请保持默认即可。此项目的发展离不开您的支持和建议,<a href="https://wp-china-yes.com/contact" target="_blank">查看联系方式</a>。</p>
|
||||
HTML;
|
||||
|
||||
}
|
||||
}
|
324
Service/Super.php
Normal file
324
Service/Super.php
Normal file
|
@ -0,0 +1,324 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Super
|
||||
* 插件加速服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Super {
|
||||
|
||||
private $settings;
|
||||
private $default = [
|
||||
'store' => 'wenpai',
|
||||
'admincdn' => [
|
||||
'admin' => 'admin',
|
||||
],
|
||||
'cravatar' => 'cn',
|
||||
'windfonts' => 'off',
|
||||
'adblock' => 'off',
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = is_multisite() ? get_site_option( 'wp_china_yes' ) : get_option( 'wp_china_yes' );
|
||||
$this->settings = wp_parse_args( $this->settings, $this->default );
|
||||
|
||||
/**
|
||||
* WordPress.Org API 替换
|
||||
*/
|
||||
if ( is_admin() || wp_doing_cron() ) {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
add_filter( 'pre_http_request', [ $this, 'filter_wordpress_org' ], 100, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加「文派茶馆」小组件
|
||||
*/
|
||||
if ( is_admin() ) {
|
||||
add_action( 'wp_dashboard_setup', function () {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
|
||||
wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', function () {
|
||||
echo <<<HTML
|
||||
<div class="wordpress-news hide-if-no-js">
|
||||
<div class="rss-widget">
|
||||
HTML;
|
||||
wp_widget_rss_output( 'https://wptea.com/feed/', [
|
||||
'items' => 5,
|
||||
'show_summary' => 1,
|
||||
] );
|
||||
echo <<<HTML
|
||||
</div>
|
||||
</div>
|
||||
<p class="community-events-footer">
|
||||
<a href="https://wenpai.org/" target="_blank">文派开源</a>
|
||||
|
|
||||
<a href="https://wenpai.org/support" target="_blank">支持论坛</a>
|
||||
|
|
||||
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
||||
</p>
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
font-size:13px;
|
||||
padding:0 12px
|
||||
}
|
||||
#wenpai_tea .rss-widget:last-child {
|
||||
border-bottom:none;
|
||||
padding-bottom:8px
|
||||
}
|
||||
#wenpai_tea .rss-widget a {
|
||||
font-weight:400
|
||||
}
|
||||
#wenpai_tea .rss-widget span,
|
||||
#wenpai_tea .rss-widget span.rss-date {
|
||||
color:#646970
|
||||
}
|
||||
#wenpai_tea .rss-widget span.rss-date {
|
||||
margin-left:12px
|
||||
}
|
||||
#wenpai_tea .rss-widget ul li {
|
||||
padding:4px 0;
|
||||
margin:0
|
||||
}
|
||||
</style>
|
||||
HTML;
|
||||
} );
|
||||
} );
|
||||
add_action( 'wp_network_dashboard_setup', function () {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
unset( $wp_meta_boxes['dashboard-network']['side']['core']['dashboard_primary'] );
|
||||
wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', function () {
|
||||
echo <<<HTML
|
||||
<div class="wordpress-news hide-if-no-js">
|
||||
<div class="rss-widget">
|
||||
HTML;
|
||||
wp_widget_rss_output( 'https://wptea.com/feed/', [
|
||||
'items' => 5,
|
||||
'show_summary' => 1,
|
||||
] );
|
||||
echo <<<HTML
|
||||
</div>
|
||||
</div>
|
||||
<p class="community-events-footer">
|
||||
<a href="https://wenpai.org/" target="_blank">文派开源</a>
|
||||
|
|
||||
<a href="https://wenpai.org/support" target="_blank">支持论坛</a>
|
||||
|
|
||||
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
||||
</p>
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
font-size:13px;
|
||||
padding:0 12px
|
||||
}
|
||||
#wenpai_tea .rss-widget:last-child {
|
||||
border-bottom:none;
|
||||
padding-bottom:8px
|
||||
}
|
||||
#wenpai_tea .rss-widget a {
|
||||
font-weight:400
|
||||
}
|
||||
#wenpai_tea .rss-widget span,
|
||||
#wenpai_tea .rss-widget span.rss-date {
|
||||
color:#646970
|
||||
}
|
||||
#wenpai_tea .rss-widget span.rss-date {
|
||||
margin-left:12px
|
||||
}
|
||||
#wenpai_tea .rss-widget ul li {
|
||||
padding:4px 0;
|
||||
margin:0
|
||||
}
|
||||
</style>
|
||||
HTML;
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress 核心静态文件链接替换
|
||||
*/
|
||||
if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
if (
|
||||
! empty( $this->settings['admincdn']['admin'] ) &&
|
||||
! stristr( $GLOBALS['wp_version'], 'alpha' ) &&
|
||||
! stristr( $GLOBALS['wp_version'], 'beta' ) &&
|
||||
! stristr( $GLOBALS['wp_version'], 'RC' )
|
||||
) {
|
||||
// 禁用合并加载,以便于使用公共资源节点
|
||||
global $concatenate_scripts;
|
||||
$concatenate_scripts = false;
|
||||
|
||||
$this->page_str_replace( 'preg_replace', [
|
||||
'~' . home_url( '/' ) . '(wp-admin|wp-includes)/(css|js)/~',
|
||||
sprintf( 'https://wpstatic.admincdn.com/%s/$1/$2/', $GLOBALS['wp_version'] )
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
/**
|
||||
* 前台静态加速
|
||||
*/
|
||||
if ( ! empty( $this->settings['admincdn']['frontend'] ) ) {
|
||||
add_action( 'template_redirect', function () {
|
||||
ob_start( function ( $content ) {
|
||||
$regex = '#(?<=[(\"\'])(?:' . quotemeta( home_url() ) . ')?/(?:((?:wp-content|wp-includes)[^\"\')]+\.(css|js)[^\"\')]+))(?=[\"\')])#';
|
||||
|
||||
return preg_replace_callback( $regex, function ( $asset ) {
|
||||
return 'https://public.admincdn.com/' . $asset[0];
|
||||
}, $content );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Google 字体替换
|
||||
*/
|
||||
if ( ! empty( $this->settings['admincdn']['googlefonts'] ) ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'fonts.googleapis.com',
|
||||
'googlefonts.admincdn.com'
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Google 前端公共库替换
|
||||
*/
|
||||
if ( ! empty( $this->settings['admincdn']['googleajax'] ) ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'ajax.googleapis.com',
|
||||
'googleajax.admincdn.com'
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* CDNJS 前端公共库替换
|
||||
*/
|
||||
if ( ! empty( $this->settings['admincdn']['cdnjs'] ) ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'cdnjs.cloudflare.com/ajax/libs',
|
||||
'cdnjs.admincdn.com'
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初认头像
|
||||
*/
|
||||
if ( ! empty( $this->settings['cravatar'] ) ) {
|
||||
add_filter( 'user_profile_picture_description', [ $this, 'set_user_profile_picture_for_cravatar' ], 1 );
|
||||
add_filter( 'avatar_defaults', [ $this, 'set_defaults_for_cravatar' ], 1 );
|
||||
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_cravatar_url' ], 1 );
|
||||
add_filter( 'bp_gravatar_url', [ $this, 'get_cravatar_url' ], 1 );
|
||||
add_filter( 'get_avatar_url', [ $this, 'get_cravatar_url' ], 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress.Org 替换
|
||||
*/
|
||||
public function filter_wordpress_org( $preempt, $args, $url ) {
|
||||
if ( ( ! strpos( $url, 'api.wordpress.org' ) && ! strpos( $url,
|
||||
'downloads.wordpress.org' ) ) ) {
|
||||
return $preempt;
|
||||
}
|
||||
|
||||
if ( $this->settings['store'] == 'wenpai' ) {
|
||||
$url = str_replace( 'api.wordpress.org', 'api.wenpai.org', $url );
|
||||
} else {
|
||||
$url = str_replace( 'api.wordpress.org', 'wpa.cdn.haozi.net', $url );
|
||||
}
|
||||
$url = str_replace( 'downloads.wordpress.org', 'wpd.cdn.haozi.net', $url );
|
||||
|
||||
$curl_version = '1.0.0';
|
||||
if ( function_exists( 'curl_version' ) ) {
|
||||
$curl_version_array = curl_version();
|
||||
if ( is_array( $curl_version_array ) && key_exists( 'version', $curl_version_array ) ) {
|
||||
$curl_version = $curl_version_array['version'];
|
||||
}
|
||||
}
|
||||
if ( version_compare( $curl_version, '7.15.0', '<' ) ) {
|
||||
$url = str_replace( 'https://', 'http://', $url );
|
||||
}
|
||||
|
||||
return wp_remote_request( $url, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* 初认头像替换
|
||||
*/
|
||||
public function get_cravatar_url( $url ) {
|
||||
switch ( $this->settings['cravatar'] ) {
|
||||
case 'cn':
|
||||
return $this->replace_avatar_url( $url, 'cn.cravatar.com' );
|
||||
case 'global':
|
||||
return $this->replace_avatar_url( $url, 'en.cravatar.com' );
|
||||
case 'weavatar':
|
||||
return $this->replace_avatar_url( $url, 'weavatar.com' );
|
||||
default:
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像 URL 替换
|
||||
*/
|
||||
public function replace_avatar_url( $url, $domain ) {
|
||||
$sources = array(
|
||||
'www.gravatar.com',
|
||||
'0.gravatar.com',
|
||||
'1.gravatar.com',
|
||||
'2.gravatar.com',
|
||||
's.gravatar.com',
|
||||
'secure.gravatar.com',
|
||||
'cn.gravatar.com',
|
||||
'en.gravatar.com',
|
||||
'gravatar.com',
|
||||
'sdn.geekzu.org',
|
||||
'gravatar.duoshuo.com',
|
||||
'gravatar.loli.net',
|
||||
'dn-qiniu-avatar.qbox.me'
|
||||
);
|
||||
|
||||
return str_replace( $sources, $domain, $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress 讨论设置中的默认 LOGO 名称替换
|
||||
*/
|
||||
public function set_defaults_for_cravatar( $avatar_defaults ) {
|
||||
$avatar_defaults['gravatar_default'] = '初认头像';
|
||||
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人资料卡中的头像上传地址替换
|
||||
*/
|
||||
public function set_user_profile_picture_for_cravatar() {
|
||||
return '<a href="https://cravatar.com" target="_blank">您可以在初认头像修改您的资料图片</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面替换
|
||||
*
|
||||
* @param $replace_func string 要调用的字符串关键字替换函数
|
||||
* @param $param array 传递给字符串替换函数的参数
|
||||
*/
|
||||
private function page_str_replace( $replace_func, $param ) {
|
||||
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 );
|
||||
} );
|
||||
}, 999999 );
|
||||
}
|
||||
}
|
24
Service/Update.php
Normal file
24
Service/Update.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
use const WenPai\ChinaYes\PLUGIN_FILE;
|
||||
|
||||
/**
|
||||
* Class Update
|
||||
* 插件更新服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Update {
|
||||
|
||||
public function __construct() {
|
||||
PucFactory::buildUpdateChecker(
|
||||
'https://api.wenpai.org/china-yes/version-check',
|
||||
PLUGIN_FILE,
|
||||
'wp-china-yes'
|
||||
);
|
||||
}
|
||||
}
|
24
composer.json
Normal file
24
composer.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "wenpai-org/wp-china-yes",
|
||||
"description": "WordPress Optimized Plugin for Mainland China",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"thetnb/wp-setting-api": "^2.0",
|
||||
"yahnis-elsts/plugin-update-checker": "^5.2"
|
||||
},
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WenPai\\ChinaYes\\": "./"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "耗子",
|
||||
"email": "i@haozi.net"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"optimize-autoloader": true
|
||||
}
|
||||
}
|
113
composer.lock
generated
Normal file
113
composer.lock
generated
Normal file
|
@ -0,0 +1,113 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "19512e097932a150b6ccc5f8044c62ed",
|
||||
"packages": [
|
||||
{
|
||||
"name": "thetnb/wp-setting-api",
|
||||
"version": "2.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/TheTNB/wp-setting-api.git",
|
||||
"reference": "0e34224dfe0832fd3bf29e2e3c054a2aad603f84"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/TheTNB/wp-setting-api/zipball/0e34224dfe0832fd3bf29e2e3c054a2aad603f84",
|
||||
"reference": "0e34224dfe0832fd3bf29e2e3c054a2aad603f84",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"TheTNB\\Setting\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "耗子",
|
||||
"email": "i@haozi.net"
|
||||
}
|
||||
],
|
||||
"description": "WordPress Setting API for developers",
|
||||
"homepage": "https://github.com/thetnb/wp-setting-api",
|
||||
"keywords": [
|
||||
"wordpress"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/TheTNB/wp-setting-api/issues",
|
||||
"source": "https://github.com/TheTNB/wp-setting-api/tree/2.0.2"
|
||||
},
|
||||
"time": "2024-03-08T07:11:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "yahnis-elsts/plugin-update-checker",
|
||||
"version": "v5.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/YahnisElsts/plugin-update-checker.git",
|
||||
"reference": "e8e53e6d98e37fa7c895c93417f52e3775494715"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/e8e53e6d98e37fa7c895c93417f52e3775494715",
|
||||
"reference": "e8e53e6d98e37fa7c895c93417f52e3775494715",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.6.20"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"load-v5p4.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Yahnis Elsts",
|
||||
"email": "whiteshadow@w-shadow.com",
|
||||
"homepage": "https://w-shadow.com/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
|
||||
"homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
|
||||
"keywords": [
|
||||
"automatic updates",
|
||||
"plugin updates",
|
||||
"theme updates",
|
||||
"wordpress"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/YahnisElsts/plugin-update-checker/issues",
|
||||
"source": "https://github.com/YahnisElsts/plugin-update-checker/tree/v5.4"
|
||||
},
|
||||
"time": "2024-02-24T09:56:49+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
2
license
2
license
|
@ -1,7 +1,7 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2020 LitePress社区 <litepress.cn>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
|
71
readme.md
71
readme.md
|
@ -1,57 +1,44 @@
|
|||
# WP-China-Yes
|
||||
|
||||
文派叶子 🍃(WP-China-Yes)是中国 WordPress 生态基础设施软件,犹如落叶新芽,生生不息。
|
||||
|
||||
## 简介
|
||||
LitePress社区([litepress.cn][0])出品,旨在将你的WordPress一键接入到本土生态体系中
|
||||
|
||||
文派叶子 🍃(WP-China-Yes)是一款不可多得的 WordPress 系统底层优化和生态基础设施软件。项目起源于 2019 年,专为解决困扰了中国互联网数十年的特色问题而存在。此为文派开源(WenPai.org)的一部分。
|
||||
|
||||
## 功能
|
||||
|
||||
- [x] 优化 WordPress 相关服务在中国大陆的访问速度
|
||||
- [x] 优化 WordPress 后台加载速度
|
||||
- [x] 优化 WordPress 前台加载速度
|
||||
- [x] 移除后台无用请求与组件
|
||||
- [x] 替换 Gravatar 头像为[初认头像](https://cravatar.com/)
|
||||
- [x] 优化 谷歌字体 加载速度
|
||||
- [x] 优化 谷歌前端库 加载速度
|
||||
- [x] 优化 CDNJS 加载速度
|
||||
|
||||
## 安装
|
||||
如果你期望参与测试,可以直接Clone Master分支中的代码,此处是功能模块基本完整的测试版本。
|
||||
|
||||
若期望用于正式环境请移步[发布列表][1],下载最新稳定版的压缩包后直接访问[http://你的域名/wp-admin/plugin-install.php][2],然后点击页面左上角的“上传插件”,上传安装即可。
|
||||
同其他 WordPress 插件一样,**从 Release 页面下载最新版本的插件**(不要直接下载源码!!!),在后台插件管理页面上传并启用即可。
|
||||
|
||||
## 插件截图
|
||||

|
||||
|
||||
## 主要特性
|
||||
- 对来自wordpress.org的所有外部服务进行加速
|
||||
- 对来自谷歌公共库的一些服务进行加速
|
||||
- 对接[LitePress翻译平台][3],为WordPress本身及官方应用市场中的所有应用推送基于AI翻译+人工辅助校准的全量汉化包
|
||||
- 使WordPress内置应用市场支持中文作品信息展示及中文语义化搜索(开发中)
|
||||
- 使WordPress内置应用市场中支持选购国内开发者所推出的优秀作品并享受集成式的安装及更新推送服务(开发中)
|
||||
当然,你也可以选择将插件手动上传到`wp-content/plugins`目录下,然后在后台启用。
|
||||
|
||||
## 问题反馈
|
||||
需要着重说明一下:**任何问题都会在第一时间得到积极的处理**,所以,有问题尽管提。
|
||||
|
||||
你可以选择以下三种方式反馈问题:
|
||||
对于 WordPress 相关的问题,可在 [文派支持论坛](https://wenpai.org/support) 提问寻求帮助。
|
||||
|
||||
1. 提交一个[Issue][4]
|
||||
2. 在LitePress社区的[论坛][5]中提交一个帖子
|
||||
3. 加项目交流QQ群:1046115671
|
||||
对于此插件自身问题,可在`Issues`页面提交问题反馈,注意[提问的智慧](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md)。
|
||||
|
||||
无论选择何种方式提交问题,都希望你可以详细描述问题的表现及触发条件,这样对减少交流成本及快速定位问题有很大好处。
|
||||
|
||||
## 参与项目发展
|
||||
|
||||
对于普通用户来讲,最好的参与项目发展的方式就是帮助项目宣传推广及参与[翻译贡献][3]
|
||||
|
||||
如果你有好的Idea,或是对参与项目开发有兴趣可以加项目交流QQ群:1046115671
|
||||
|
||||
我想,对于在校大学生来讲,参与一个开源项目无疑是积累开发经验的最好方式。同时,工作并不是完全无偿的,项目赞助商会视情况为每位开发者提供周期性资金支持。
|
||||
交流QQ群:[1046115671](https://qm.qq.com/q/BATf8KsCje)
|
||||
|
||||
## 赞助商
|
||||
|
||||
### 服务器及管理软件
|
||||
|
||||
<img src="https://litepress.cn/wp-content/uploads/2020/08/又拍云_logo5-300x153.png" width="137" height="70" alt="" class="wp-image-764 alignnone size-medium" srcset="https://litepress.cn/wp-content/uploads/2020/08/又拍云_logo5-300x153.png 300w, https://litepress.cn/wp-content/uploads/2020/08/又拍云_logo5-300x153.png 480w, https://litepress.cn/wp-content/uploads/2020/08/又拍云_logo5-300x153.png 594w" sizes="(max-width: 137px) 100vw, 137px">
|
||||
|
||||
|
||||
[0]: https://litepress.cn
|
||||
|
||||
[1]: https://github.com/litepress/wp-china-yes/releases
|
||||
|
||||
[2]: http://你的域名/wp-admin/plugin-install.php
|
||||
|
||||
[3]: https://litepress.cn/translate/
|
||||
|
||||
[4]: https://github.com/litepress/wp-china-yes/issues
|
||||
|
||||
[5]: https://litepress.cn/forums
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/feibisi-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/shujue-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/upyun-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/wenpai-logo@2X.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/wpsaas-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/lingding-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/weixiaoduo-logo-2020.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/modiqi-logo.png"></a>
|
||||
<a href="#"><img height="80" src="https://wp-china-yes.com/wp-content/uploads/2023/08/kekechong-logo-1.png"></a>
|
||||
|
|
416
wp-china-yes.php
416
wp-china-yes.php
|
@ -1,407 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: WP-China-Yes
|
||||
* Description: 将你的WordPress接入本土生态体系中,这将为你提供一个更贴近中国人使用习惯的WordPress
|
||||
* Author: LitePress社区
|
||||
* Author URI:https://litepress.cn/
|
||||
* Version: 3.5.5
|
||||
* Network: True
|
||||
* Description: 文派叶子 🍃(WP-China-Yes)是中国 WordPress 生态基础设施软件,犹如落叶新芽,生生不息。
|
||||
* Author: 文派开源
|
||||
* Author URI: https://wp-china-yes.com
|
||||
* Version: 3.6.1
|
||||
* License: GPLv3 or later
|
||||
* Text Domain: wp-china-yes
|
||||
* Domain Path: /languages
|
||||
* Network: True
|
||||
* Requires at least: 4.9
|
||||
* Tested up to: 9.9.9
|
||||
* Requires PHP: 5.6.0
|
||||
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
namespace WenPai\ChinaYes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
||||
class WP_CHINA_YES {
|
||||
private $page_url;
|
||||
const VERSION = '3.6.1';
|
||||
const PLUGIN_FILE = __FILE__;
|
||||
const PLUGIN_DIR = __DIR__;
|
||||
|
||||
public function __construct() {
|
||||
$this->page_url = network_admin_url( is_multisite() ? 'settings.php?page=wp-china-yes' : 'options-general.php?page=wp-china-yes' );
|
||||
}
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' );
|
||||
|
||||
public function init() {
|
||||
if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
/**
|
||||
* 插件列表项目中增加设置项
|
||||
*/
|
||||
add_filter( sprintf( '%splugin_action_links_%s', is_multisite() ? 'network_admin_' : '', plugin_basename( __FILE__ ) ), function ( $links ) {
|
||||
return array_merge(
|
||||
[ sprintf( '<a href="%s">%s</a>', $this->page_url, '设置' ) ],
|
||||
$links
|
||||
);
|
||||
} );
|
||||
// 注册插件激活钩子
|
||||
register_activation_hook( PLUGIN_FILE, [ Plugin::class, 'activate' ] );
|
||||
// 注册插件删除钩子
|
||||
register_uninstall_hook( PLUGIN_FILE, [ Plugin::class, 'uninstall' ] );
|
||||
|
||||
|
||||
/**
|
||||
* 插件列表页中所有插件增加“翻译校准”链接
|
||||
*/
|
||||
// if (get_option('wpapi') == 1) {
|
||||
add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) {
|
||||
$links[] = '<a target="_blank" href="https://litepress.cn/translate/projects/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">参与翻译</a>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化设置项
|
||||
*/
|
||||
update_option( "wpapi", get_option( 'wpapi' ) ?: '2' );
|
||||
update_option( "super_admin", get_option( 'super_admin' ) ?: '2' );
|
||||
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' );
|
||||
|
||||
|
||||
/**
|
||||
* 禁用插件时删除配置
|
||||
*/
|
||||
register_deactivation_hook( __FILE__, function () {
|
||||
delete_option( "wpapi" );
|
||||
delete_option( "super_admin" );
|
||||
delete_option( "super_gravatar" );
|
||||
delete_option( "super_googlefonts" );
|
||||
delete_option( "super_googleajax" );
|
||||
} );
|
||||
|
||||
|
||||
/**
|
||||
* 菜单注册
|
||||
*/
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', function () {
|
||||
add_submenu_page(
|
||||
is_multisite() ? 'settings.php' : 'options-general.php',
|
||||
'WP-China-Yes',
|
||||
'WP-China-Yes',
|
||||
is_multisite() ? 'manage_network_options' : 'manage_options',
|
||||
'wp-china-yes',
|
||||
[ $this, 'options_page_html' ]
|
||||
);
|
||||
} );
|
||||
|
||||
|
||||
/**
|
||||
* 将WordPress核心所依赖的静态文件访问链接替换为公共资源节点
|
||||
*/
|
||||
if (
|
||||
get_option( 'super_admin' ) != 2 &&
|
||||
! stristr( $GLOBALS['wp_version'], 'alpha' ) &&
|
||||
! stristr( $GLOBALS['wp_version'], 'beta' ) &&
|
||||
! stristr( $GLOBALS['wp_version'], 'RC' ) &&
|
||||
! isset( $GLOBALS['lp_version'] )
|
||||
) {
|
||||
$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' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( is_admin() || wp_doing_cron() ) {
|
||||
add_action( 'admin_init', function () {
|
||||
/**
|
||||
* wpapi用以标记用户所选的仓库api,数值说明:1 使用LitePress的API,2 只是经代理加速的api.wordpress.org原版API
|
||||
*/
|
||||
register_setting( 'wpcy', 'wpapi' );
|
||||
|
||||
/**
|
||||
* super_admin用以标记用户是否启用管理后台加速功能
|
||||
*/
|
||||
register_setting( 'wpcy', 'super_admin' );
|
||||
|
||||
/**
|
||||
* super_gravatar用以标记用户是否启用Cravatar头像功能
|
||||
*/
|
||||
register_setting( 'wpcy', 'super_gravatar' );
|
||||
|
||||
/**
|
||||
* super_googlefonts用以标记用户是否启用谷歌字体加速功能
|
||||
*/
|
||||
register_setting( 'wpcy', 'super_googlefonts' );
|
||||
|
||||
add_settings_section(
|
||||
'wpcy_section_main',
|
||||
'将你的WordPress接入本土生态体系中,这将为你提供一个更贴近中国人使用习惯的WordPress',
|
||||
'',
|
||||
'wpcy'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_wpapi',
|
||||
'选择应用市场',
|
||||
[ $this, 'field_wpapi_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_admin',
|
||||
'加速管理后台',
|
||||
[ $this, 'field_super_admin_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_gravatar',
|
||||
'使用 Cravatar 头像',
|
||||
[ $this, 'field_super_gravatar_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_googlefonts',
|
||||
'加速谷歌字体',
|
||||
[ $this, 'field_super_googlefonts_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpcy_field_select_super_googleajax',
|
||||
'加速谷歌前端公共库',
|
||||
[ $this, 'field_super_googleajax_cb' ],
|
||||
'wpcy',
|
||||
'wpcy_section_main'
|
||||
);
|
||||
|
||||
} );
|
||||
|
||||
/**
|
||||
* 替换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' ) ) || get_option( 'wpapi' ) == 3 ) {
|
||||
return $preempt;
|
||||
}
|
||||
if ( get_option( 'wpapi' ) == 1 ) {
|
||||
$url = str_replace( 'api.wordpress.org', 'api.litepress.cn', $url );
|
||||
$url = str_replace( 'downloads.wordpress.org', 'd.w.org.ibadboy.net', $url );
|
||||
} else {
|
||||
$url = str_replace( 'api.wordpress.org', 'api.w.org.ibadboy.net', $url );
|
||||
$url = str_replace( 'downloads.wordpress.org', 'd.w.org.ibadboy.net', $url );
|
||||
}
|
||||
|
||||
$curl_version = '1.0.0';
|
||||
if ( function_exists( 'curl_version' ) ) {
|
||||
$curl_version_array = curl_version();
|
||||
if ( is_array( $curl_version_array ) && key_exists( 'version', $curl_version_array ) ) {
|
||||
$curl_version = $curl_version_array['version'];
|
||||
}
|
||||
}
|
||||
|
||||
// 如果CURL版本小于7.15.0,说明不支持SNI,无法通过HTTPS访问又拍云的节点,故而改用HTTP
|
||||
if ( version_compare( $curl_version, '7.15.0', '<' ) ) {
|
||||
$url = str_replace( 'https://', 'http://', $url );
|
||||
}
|
||||
|
||||
return wp_remote_request( $url, $r );
|
||||
}, 999999, 3 );
|
||||
}
|
||||
|
||||
|
||||
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
/**
|
||||
* 替换谷歌字体为 LitePress 维护的加速节点
|
||||
*/
|
||||
if ( get_option( 'super_googlefonts' ) != 2 ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'fonts.googleapis.com',
|
||||
'googlefonts.wp-china-yes.net'
|
||||
], get_option( 'super_googlefonts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换谷歌前端公共库为 LitePress 维护的加速节点
|
||||
*/
|
||||
if ( get_option( 'super_googleajax' ) != 2 ) {
|
||||
$this->page_str_replace( 'str_replace', [
|
||||
'ajax.googleapis.com',
|
||||
'googleajax.wp-china-yes.net'
|
||||
], get_option( 'super_googleajax' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换Gravatar头像为Cravatar头像
|
||||
*/
|
||||
if ( get_option( 'super_gravatar' ) == 1 ) {
|
||||
if ( ! function_exists( 'get_cravatar_url' ) ) {
|
||||
/**
|
||||
* 替换Gravatar头像为Cravatar头像
|
||||
*
|
||||
* Cravatar是Gravatar在中国的完美替代方案,你可以在https://cravatar.cn更新你的头像
|
||||
*/
|
||||
function get_cravatar_url( $url ) {
|
||||
$sources = array(
|
||||
'www.gravatar.com',
|
||||
'0.gravatar.com',
|
||||
'1.gravatar.com',
|
||||
'2.gravatar.com',
|
||||
'secure.gravatar.com',
|
||||
'cn.gravatar.com',
|
||||
'gravatar.com',
|
||||
);
|
||||
|
||||
return str_replace( $sources, 'cravatar.cn', $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换WordPress讨论设置中的默认LOGO名称
|
||||
*/
|
||||
function set_defaults_for_cravatar( $avatar_defaults ) {
|
||||
$avatar_defaults['gravatar_default'] = 'Cravatar 标志';
|
||||
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换个人资料卡中的头像上传地址
|
||||
*/
|
||||
function set_user_profile_picture_for_cravatar() {
|
||||
return '<a href="https://cravatar.cn" target="_blank">您可以在 Cravatar 修改您的资料图片</a>';
|
||||
}
|
||||
|
||||
add_filter( 'user_profile_picture_description', 'set_user_profile_picture_for_cravatar' );
|
||||
add_filter( 'avatar_defaults', 'set_defaults_for_cravatar', 1 );
|
||||
add_filter( 'um_user_avatar_url_filter', 'get_cravatar_url', 1 );
|
||||
add_filter( 'bp_gravatar_url', 'get_cravatar_url', 1 );
|
||||
add_filter( 'get_avatar_url', 'get_cravatar_url', 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function field_wpapi_cb() {
|
||||
$wpapi = get_option( 'wpapi' );
|
||||
?>
|
||||
<label>
|
||||
<input type="radio" value="2" name="wpapi" <?php checked( $wpapi, '2' ); ?>>官方应用市场加速镜像
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" value="1" name="wpapi" <?php checked( $wpapi, '1' ); ?>>LitePress 应用市场(技术试验)
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" value="3" name="wpapi" <?php checked( $wpapi, '3' ); ?>>不接管应用市场
|
||||
</label>
|
||||
<p class="description">
|
||||
<b>官方应用市场加速镜像</b>:直接从官方反代并在大陆分发,除了增加对 WP-China-Yes 插件的更新支持外未做任何更改
|
||||
</p>
|
||||
<p class="description">
|
||||
<b>LitePress 应用市场</b>:该接口处于开发阶段,目前提供了与 <a href="https://litepress.cn/translate" target="_blank">LitePress
|
||||
翻译平台</a> 的整合<b>(注意,你可能在使用此接口时遇到未知 BUG,希望能帮忙 <a href="https://litepress.cn/" target="_blank">反馈</a>)</b>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function field_super_admin_cb() {
|
||||
$this->field_cb( 'super_admin', '将WordPress核心所依赖的静态文件切换为公共资源,此选项极大的加快管理后台访问速度', true );
|
||||
}
|
||||
|
||||
public function field_super_gravatar_cb() {
|
||||
$this->field_cb( 'super_gravatar', 'Cravatar 是 Gravatar 在中国的完美替代方案,你可以在 <a href="https://cravatar.cn" target="_blank">https://cravatar.cn</a> 更新你的头像。(任何开发者均可在自己的产品中集成该服务)' );
|
||||
}
|
||||
|
||||
public function field_super_googlefonts_cb() {
|
||||
$this->field_cb( 'super_googlefonts', '请只在包含谷歌字体的情况下才启用该选项,以免造成不必要的性能损失' );
|
||||
}
|
||||
|
||||
public function field_super_googleajax_cb() {
|
||||
$this->field_cb( 'super_googleajax', '请只在包含谷歌前端公共库的情况下才启用该选项,以免造成不必要的性能损失' );
|
||||
}
|
||||
|
||||
public function options_page_html() {
|
||||
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
|
||||
update_option( "wpapi", sanitize_text_field( $_POST['wpapi'] ) );
|
||||
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>';
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings_errors( 'wpcy_messages' );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
||||
<form action="<?php echo $this->page_url; ?>" method="post">
|
||||
<?php
|
||||
settings_fields( 'wpcy' );
|
||||
do_settings_sections( 'wpcy' );
|
||||
submit_button( '保存配置' );
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<p>
|
||||
<a href="https://litepress.cn" target="_blank">LitePress社区</a>的使命是帮助WordPress在中国建立起良好的本土生态环境,以求推进行业整体发展,做大市场蛋糕。<br/>
|
||||
特别感谢<a href="https://zmingcx.com/" target="_blank">知更鸟</a>、<a href="https://www.weixiaoduo.com/"
|
||||
target="_blank">薇晓朵团队</a>、<a
|
||||
href="https://www.appnode.com/" target="_blank">AppNode</a>在项目萌芽期给予的帮助。<br/>
|
||||
项目所需服务器资源由<a href="https://www.vpsor.cn/" target="_blank">硅云</a>和<a href="https://www.upyun.com/"
|
||||
target="_blank">又拍云</a>提供。
|
||||
</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 );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
( new WP_CHINA_YES )->init();
|
||||
}
|
||||
new Plugin();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue