diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..1d278bc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..c117656 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -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) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..5e9619d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -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 diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..07e3c7d --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5657f6e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9d8a8f3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +All notable changes to `WP-China-Yes` will be documented in this file. + diff --git a/Plugin.php b/Plugin.php new file mode 100644 index 0000000..1d3f726 --- /dev/null +++ b/Plugin.php @@ -0,0 +1,98 @@ +

' . sprintf( __( 'WP-China-Yes 插件需要 PHP 5.6.0 或更高版本,当前版本为 %s,插件已自动禁用。', + 'wp-china-yes' ), + PHP_VERSION ) . '

'; + } + if ( is_plugin_active( 'wp-china-no/wp-china-no.php' ) ) { + deactivate_plugins( 'wp-china-no/wp-china-no.php' ); + $notices[] = '
+

' . __( '检测到旧版插件 WP-China-No,已自动禁用!', 'wp-china-yes' ) . '

+
'; + } + if ( is_plugin_active( 'wp-china-plus/wp-china-plus.php' ) ) { + deactivate_plugins( 'wp-china-plus/wp-china-plus.php' ); + $notices[] = '
+

' . __( '检测到不兼容的插件 WP-China-Plus,已自动禁用!', 'wp-china-yes' ) . '

+
'; + } + if ( is_plugin_active( 'kill-429/kill-429.php' ) ) { + deactivate_plugins( 'kill-429/kill-429.php' ); + $notices[] = '
+

' . __( '检测到不兼容的插件 Kill 429,已自动禁用!', 'wp-china-yes' ) . '

+
'; + + } + // 代理服务器检测 + if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) ) { + $notices[] = '
+

' . __( '检测到已在 WordPress 配置文件中设置代理服务器,这可能会导致插件无法正常工作!', + 'wp-china-yes' ) . '

+
'; + } + + 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' ); + } + } +} diff --git a/Service/Base.php b/Service/Base.php new file mode 100644 index 0000000..03bbf19 --- /dev/null +++ b/Service/Base.php @@ -0,0 +1,29 @@ +参与翻译'; + + return $links; + }, 10, 2 ); + + // 加速服务 + new Super(); + // 更新服务 + new Update(); + } +} diff --git a/Service/Setting.php b/Service/Setting.php new file mode 100644 index 0000000..7b13d7f --- /dev/null +++ b/Service/Setting.php @@ -0,0 +1,267 @@ +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' => __( '官方加速源(WPMirror):直接从 .org 反代至大陆分发;文派存储库:中国境内自建托管仓库,同时集成文派集市产品更新。', + 'wp-china-yes' ), + 'type' => 'radio', + 'default' => 'wenpai', + 'options' => [ + 'proxy' => '官方镜像', + 'wenpai' => '文派中国', + 'off' => '不启用' + ] + ], + [ + 'name' => 'admincdn', + 'label' => __( '萌芽加速', 'wp-china-yes' ), + 'desc' => __( '萌芽加速(adminCDN):将 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' => __( '初认头像(Cravatar):是 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' => __( '文风字体(Windfonts):即将为您的网页渲染中文字体并对主题、插件内的 Google 字体进行加速。', + 'wp-china-yes' ), + 'type' => 'radio', + 'default' => 'off', + 'options' => [ + 'off' => '即将上线', + ] + ], + [ + 'name' => 'adblock', + 'label' => __( '广告拦截', 'wp-china-yes' ), + 'desc' => __( '文派叶子🍃(WP-China-Yes):独家特色功能,让您拥有清爽整洁的 WordPress 后台,清除各类常用插件侵入式后台广告、通知及无用信息;启用后若存在异常拦截,请切换为手动模式,查看可优化插件列表。', + '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 = '' . esc_html__( '设置', + 'wp-china-yes' ) . ''; + array_unshift( $links, $settings_link ); + + return $links; + }, 10, 2 ); + } + + /** + * 设置页面模版 + */ + public function setting_page() { + echo '

WP-China-Yes

'; + echo '

将您的 WordPress 接入本土生态体系,这将为您提供一个更贴近中国人使用习惯的 WordPress。

100% 开源代码,一起参与文派(WordPress)软件国产化进程,打造属于您自己的开源自助建站程序。

'; + echo << + .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%; + } + } + +
+
+HTML; + $this->setting_api->show_navigation(); + $this->setting_api->show_forms(); + + echo << +
+
+

项目简介

+
+ 文派叶子 🍃(WP-China-Yes)是一款不可多得的 WordPress 系统底层优化和生态基础设施软件。项目起源于 2019 年,专为解决困扰了中国互联网数十年的特色问题而存在。此为文派开源(WenPai.org)的一部分。 +
+ +
+ + +
+

赞助商

+ + +
+ + + +
+
+

提示:此处选项设置并不与任何文派插件及独立功能扩展冲突,可放心安装启用。

+

帮助:您可以随时在此处调整个性化设置以便适应不同的业务场景,萌新请保持默认即可。此项目的发展离不开您的支持和建议,查看联系方式

+HTML; + + } +} diff --git a/Service/Super.php b/Service/Super.php new file mode 100644 index 0000000..b2962b7 --- /dev/null +++ b/Service/Super.php @@ -0,0 +1,324 @@ + '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; + wp_widget_rss_output( 'https://wptea.com/feed/', [ + 'items' => 5, + 'show_summary' => 1, + ] ); + echo << +
+ + + 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; + wp_widget_rss_output( 'https://wptea.com/feed/', [ + 'items' => 5, + 'show_summary' => 1, + ] ); + echo << +
+ + + 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 '您可以在初认头像修改您的资料图片'; + } + + /** + * 页面替换 + * + * @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 ); + } +} diff --git a/Service/Update.php b/Service/Update.php new file mode 100644 index 0000000..c8a5951 --- /dev/null +++ b/Service/Update.php @@ -0,0 +1,24 @@ +=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" +} diff --git a/license b/license index 3c67163..f288702 100644 --- a/license +++ b/license @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2020 LitePress社区 + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/readme.md b/readme.md index 4052949..0cd9af6 100644 --- a/readme.md +++ b/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 页面下载最新版本的插件**(不要直接下载源码!!!),在后台插件管理页面上传并启用即可。 -## 插件截图 -![图片无法加载](https://litepress.cn/wp-content/uploads/2020/10/QQ图片20201007131531.png) - -## 主要特性 - - 对来自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) ## 赞助商 -### 服务器及管理软件 - - - - -[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 + + + + + + + + + diff --git a/wp-china-yes.php b/wp-china-yes.php index bb73864..3752e6d 100644 --- a/wp-china-yes.php +++ b/wp-china-yes.php @@ -1,407 +1,33 @@ 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( '%s', $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[] = '参与翻译'; - - 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 '您可以在 Cravatar 修改您的资料图片'; - } - - 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' ); - ?> - - - -

- 官方应用市场加速镜像:直接从官方反代并在大陆分发,除了增加对 WP-China-Yes 插件的更新支持外未做任何更改 -

-

- LitePress 应用市场:该接口处于开发阶段,目前提供了与 LitePress - 翻译平台 的整合(注意,你可能在使用此接口时遇到未知 BUG,希望能帮忙 反馈 -

- field_cb( 'super_admin', '将WordPress核心所依赖的静态文件切换为公共资源,此选项极大的加快管理后台访问速度', true ); - } - - public function field_super_gravatar_cb() { - $this->field_cb( 'super_gravatar', 'Cravatar 是 Gravatar 在中国的完美替代方案,你可以在 https://cravatar.cn 更新你的头像。(任何开发者均可在自己的产品中集成该服务)' ); - } - - 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 '

设置已保存

'; - } - - if ( ! current_user_can( 'manage_options' ) ) { - return; - } - - settings_errors( 'wpcy_messages' ); - ?> -
-

-
- -
-
-

- LitePress社区的使命是帮助WordPress在中国建立起良好的本土生态环境,以求推进行业整体发展,做大市场蛋糕。
- 特别感谢知更鸟薇晓朵团队AppNode在项目萌芽期给予的帮助。
- 项目所需服务器资源由硅云又拍云提供。 -

- - - - - - -

- -

- init(); -} +new Plugin();