From 291f64a7a31a7dceccd352c0de930b99fb47a379 Mon Sep 17 00:00:00 2001 From: sunxiyuan Date: Fri, 27 Mar 2020 15:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=85=8D=E7=BD=AE=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=8A=BD=E5=8F=96=E5=87=BA=E6=9D=A5=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index 35441e2..14a1a20 100644 --- a/index.php +++ b/index.php @@ -61,13 +61,7 @@ class WP_CHINA_YES { } public static function wp_china_yes_activate() { - $options = array(); - $options['community'] = '0'; - $options['custom_api_server'] = ''; - $options['custom_download_server'] = ''; - $options['api_server'] = 'api.w.org.ibadboy.net'; - $options['download_server'] = 'd.w.org.ibadboy.net'; - add_option('wp_china_yes_options', $options); + self::set_wp_option(); } public static function wp_china_yes_deactivate() { @@ -155,14 +149,15 @@ EOT; self::error('参数错误', - 1); } - $options = array(); - $options['community'] = sanitize_text_field(trim($_POST['community'])); - $options['custom_api_server'] = sanitize_text_field(trim($_POST['custom_api_server'])); - $options['custom_download_server'] = sanitize_text_field(trim($_POST['custom_download_server'])); - $options["api_server"] = sanitize_text_field(trim($_POST['api_server'])); - $options["download_server"] = sanitize_text_field(trim($_POST['download_server'])); - update_option("wp_china_yes_options", $options); - self::success('', $options); + self::set_wp_option( + sanitize_text_field(trim($_POST['community'])), + sanitize_text_field(trim($_POST['custom_api_server'])), + sanitize_text_field(trim($_POST['custom_download_server'])), + sanitize_text_field(trim($_POST['api_server'])), + sanitize_text_field(trim($_POST['download_server'])) + ); + + self::success(); } private static function success($message = '', $data = []) { @@ -186,4 +181,20 @@ EOT; ], JSON_UNESCAPED_UNICODE); exit; } + + private static function set_wp_option( + $community = 0, + $custom_api_server = '', + $custom_download_server = '', + $api_server = 'api.w.org.ibadboy.net', + $download_server = 'd.w.org.ibadboy.net' + ) { + $options = array(); + $options['community'] = (int) $community; + $options['custom_api_server'] = $custom_api_server; + $options['custom_download_server'] = $custom_download_server; + $options['api_server'] = $api_server; + $options['download_server'] = $download_server; + update_option("wp_china_yes_options", $options); + } } \ No newline at end of file