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' ) . '
+' . __( '检测到不兼容的插件 WP-China-Plus,已自动禁用!', 'wp-china-yes' ) . '
+' . __( '检测到不兼容的插件 Kill 429,已自动禁用!', 'wp-china-yes' ) . '
+' . __( '检测到已在 WordPress 配置文件中设置代理服务器,这可能会导致插件无法正常工作!', + 'wp-china-yes' ) . '
+提示:此处选项设置并不与任何文派插件及独立功能扩展冲突,可放心安装启用。
+帮助:您可以随时在此处调整个性化设置以便适应不同的业务场景,萌新请保持默认即可。此项目的发展离不开您的支持和建议,查看联系方式。
+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; + } ); + } ); + 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; + } ); + } ); + } + + /** + * 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社区- 官方应用市场加速镜像:直接从官方反代并在大陆分发,除了增加对 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 '设置已保存
- LitePress社区的使命是帮助WordPress在中国建立起良好的本土生态环境,以求推进行业整体发展,做大市场蛋糕。
- 特别感谢知更鸟、薇晓朵团队、AppNode在项目萌芽期给予的帮助。
- 项目所需服务器资源由硅云和又拍云提供。
-
- -
- init(); -} +new Plugin();