fix: 市场加速导致 Beta 测试插件失效的问题

This commit is contained in:
耗子 2024-03-09 01:40:34 +08:00
parent 597c0943d5
commit 2223b022b7
6 changed files with 200 additions and 170 deletions

View file

@ -38,7 +38,7 @@ class Plugin {
* 插件加载时执行
*/
public function plugins_loaded() {
load_plugin_textdomain( 'wp-china-yes', false, plugin_dir_path( PLUGIN_FILE ) . 'languages' );
load_plugin_textdomain( 'wp-china-yes', false, CHINA_YES_PLUGIN_PATH . 'languages' );
add_action( 'admin_notices', [ $this, 'admin_notices' ] );
}

View file

@ -17,6 +17,7 @@ class Setting {
public function __construct() {
$this->setting_api = new API();
add_action( 'admin_init', [ $this, 'admin_init' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'admin_menu' ] );
}
@ -108,6 +109,16 @@ class Setting {
$this->setting_api->admin_init();
}
/**
* 加载后台资源
*/
public function enqueue_admin_assets( $hook_suffix ) {
if ( strpos( $hook_suffix, 'wp-china-yes' ) === false ) {
return;
}
wp_enqueue_style( 'wpcy-admin', CHINA_YES_PLUGIN_URL . 'assets/css/setting.css', [], CHINA_YES_VERSION );
}
/**
* 挂载设置页面
*/
@ -139,119 +150,14 @@ class Setting {
* 设置页面模版
*/
public function setting_page() {
echo '<div class="wpcy-settings-header">
<div class="wpcy-settings-title-section"><h1>文派叶子🍃(WP-China-Yes)</h1></div>';
echo '<h3>将您的 WordPress 接入本土生态体系,这将为您提供一个更贴近中国人使用习惯的 WordPress。</h3><h4>100% 开源代码一起参与文派WordPress软件国产化进程打造属于您自己的开源自助建站程序。</h4></div>';
echo <<<HTML
<style>
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-family: "Source Han Sans SC", "Noto Sans CJK SC", "Source Han Sans CN", "Noto Sans SC", "Source Han Sans TC", "Noto Sans CJK TC", sans-serif, -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
}
#wpcontent, #wpfooter {
background-color: #ffffff;
}
.container {
display: flex;
flex-wrap: wrap;
width: 100%;
}
.left-column, .right-column {
width: 100%;
}
.right-column {
padding: 20px;
display: flex;
flex-direction: column;
gap: 20px;
}
.card {
background-color: #fff;
padding: 10%;
border-radius: 10px;
text-transform: none;
border: 0px solid #c3c4c7;
font-size: 14px;
line-height: 2;
box-shadow: 0 0.375rem 1.5rem 0 rgba(141, 153, 165, 0.13);
}
.card h3 {
margin-top: 0;
font-size: 18px;
font-weight: 400;
}
.card a, .left-column a {
text-decoration: none;
}
.card-body, .card-footer {
margin: 10px 0;
}
.card-footer a.button.button-primary {
padding: 1% 5%;
margin-top: 10px;
}
.form-table th {
width: 120px;
padding: 5% 0;
}
.form-table td {
padding: 5% 0;
}
.wpcy-settings-header {
padding-top: 20px;
max-width: 1280px;
margin: 0 auto;
line-height: 1.5;
}
.wpcy-settings-title-section {
padding: 1% 0;
}
.wpcy-settings-title-section h3 {
font-size: large;
}
.wpcy-settings-title-section h4 {
font-size: large;
font-weight: 400;
}
.wpcy-settings-footer p {
font-size: x-small;
line-height: 2;
}
.sponsor-logos {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.sponsor-logos img {
width: 26%;
margin-bottom: 30px;
display: block;
margin-left: auto;
margin-right: auto;
height: fit-content;
}
@media screen and (max-width: 782px){
.auto-fold #wpcontent {
padding: 10px;
}
}
@media (min-width: 768px) {
.container {
flex-wrap: nowrap;
max-width: 1280px;
margin: 0 auto;
}
.left-column {
width: 70%;
}
.right-column {
width: 30%;
}
}
</style>
<div class="settings-header">
<div class="settings-title-section">
<h1>文派叶子🍃(WP-China-Yes)</h1>
</div>
<h3>将您的 WordPress 接入本土生态体系,这将为您提供一个更贴近中国人使用习惯的 WordPress。</h3>
<h4>100% 开源代码一起参与文派WordPress软件国产化进程打造属于您自己的开源自助建站程序。</h4>
</div>
<div class="container">
<div class="left-column">
HTML;
@ -259,7 +165,7 @@ HTML;
$this->setting_api->show_forms();
echo <<<HTML
<div class="wpcy-settings-footer">
<div class="settings-footer">
<p><strong>提示:</strong>插件会定期检查节点可用性,并在节点不可用时自动切换至可用节点,以保证您的网站正常访问。如您发现设置项被自动切换,可在此页面重新设置。</p>
<p><strong>帮助:</strong>您可以随时在此处调整个性化设置以便适应不同的业务场景,萌新请保持默认即可。此项目的发展离不开您的支持和建议,<a href="https://wp-china-yes.com/contact" target="_blank">查看联系方式</a></p>
</div>

View file

@ -217,8 +217,10 @@ class Super {
* WordPress.Org 替换
*/
public function filter_wordpress_org( $preempt, $args, $url ) {
if ( ( ! strpos( $url, 'api.wordpress.org' ) && ! strpos( $url,
'downloads.wordpress.org' ) ) ) {
if ( $preempt || isset( $args['_wp_china_yes'] ) ) {
return $preempt;
}
if ( ( ! strpos( $url, 'api.wordpress.org' ) && ! strpos( $url, 'downloads.wordpress.org' ) ) ) {
return $preempt;
}
@ -240,6 +242,8 @@ class Super {
$url = str_replace( 'https://', 'http://', $url );
}
$args['_wp_china_yes'] = true;
return wp_remote_request( $url, $args );
}

View file

@ -5,7 +5,6 @@ namespace WenPai\ChinaYes\Service;
defined( 'ABSPATH' ) || exit;
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
use const WenPai\ChinaYes\PLUGIN_FILE;
/**
* Class Update
@ -17,7 +16,7 @@ class Update {
public function __construct() {
PucFactory::buildUpdateChecker(
'https://api.wenpai.org/china-yes/version-check',
PLUGIN_FILE,
CHINA_YES_PLUGIN_FILE,
'wp-china-yes'
);
}

120
assets/css/setting.css Normal file
View file

@ -0,0 +1,120 @@
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-family: "Source Han Sans SC", "Noto Sans CJK SC", "Source Han Sans CN", "Noto Sans SC", "Source Han Sans TC", "Noto Sans CJK TC", sans-serif, -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
}
#wpcontent, #wpfooter {
background-color: #ffffff;
}
.notice {
background-color: #f5f5f5;
}
.container {
display: flex;
flex-wrap: wrap;
width: 100%;
}
.left-column, .right-column {
width: 100%;
}
.right-column {
padding: 20px;
display: flex;
flex-direction: column;
gap: 20px;
}
.card {
background-color: #fff;
padding: 10%;
border-radius: 10px;
text-transform: none;
border: 0px solid #c3c4c7;
font-size: 14px;
line-height: 2;
box-shadow: 0 0.375rem 1.5rem 0 rgba(141, 153, 165, 0.13);
}
.card h3 {
margin-top: 0;
font-size: 18px;
font-weight: 400;
}
.card a, .left-column a {
text-decoration: none;
}
.card-body, .card-footer {
margin: 10px 0;
}
.card-footer a.button.button-primary {
padding: 1% 5%;
margin-top: 10px;
}
.form-table th {
width: 120px;
padding: 5% 0;
}
.form-table td {
padding: 5% 0;
}
.settings-header {
padding-top: 20px;
max-width: 1280px;
margin: 0 auto;
line-height: 1.5;
}
.settings-title-section {
padding: 1% 0;
}
.settings-footer p {
font-size: 12px;
line-height: 2;
}
.sponsor-logos {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.sponsor-logos img {
width: 26%;
margin-bottom: 30px;
display: block;
margin-left: auto;
margin-right: auto;
height: fit-content;
}
@media screen and (max-width: 782px) {
.auto-fold #wpcontent {
padding: 10px;
}
}
@media (min-width: 768px) {
.container {
flex-wrap: nowrap;
max-width: 1280px;
margin: 0 auto;
}
.left-column {
width: 70%;
}
.right-column {
width: 30%;
}
}

View file

@ -19,15 +19,16 @@ namespace WenPai\ChinaYes;
defined( 'ABSPATH' ) || exit;
const VERSION = '3.6.1';
const PLUGIN_FILE = __FILE__;
const PLUGIN_DIR = __DIR__;
define( 'CHINA_YES_VERSION', '3.6.1' );
define( 'CHINA_YES_PLUGIN_FILE', __FILE__ );
define( 'CHINA_YES_PLUGIN_URL', plugin_dir_url( CHINA_YES_PLUGIN_FILE ) );
define( 'CHINA_YES_PLUGIN_PATH', plugin_dir_path( CHINA_YES_PLUGIN_FILE ) );
require_once( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' );
require_once( plugin_dir_path( CHINA_YES_PLUGIN_FILE ) . 'vendor/autoload.php' );
// 注册插件激活钩子
register_activation_hook( PLUGIN_FILE, [ Plugin::class, 'activate' ] );
register_activation_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'activate' ] );
// 注册插件删除钩子
register_uninstall_hook( PLUGIN_FILE, [ Plugin::class, 'uninstall' ] );
register_uninstall_hook( CHINA_YES_PLUGIN_FILE, [ Plugin::class, 'uninstall' ] );
new Plugin();