Skip to content

Commit

Permalink
优化 Wnd\Component\Requests;精简版版本适配;0.9.66
Browse files Browse the repository at this point in the history
  • Loading branch information
swling committed Oct 13, 2023
1 parent bc6788c commit f147a56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 7 additions & 1 deletion accelerator/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*
* wp 内核每次更新都可能引起 wp-settings.php 改变。因此当版本更新后默认移除精简模式,直到核查无误后,更新本文件版本号
*
* @since 0.9.66
* 忽略安全版本更新 ($wp_version / 10)
*
* 版本号规则
* @see https://make.wordpress.org/core/handbook/about/release-cycle/version-numbering/
*
*/

require ABSPATH . 'wp-includes/version.php';
Expand All @@ -13,7 +19,7 @@
// 升级或安装中
$installing = defined('WP_INSTALLING') && WP_INSTALLING;

if ('6.3.1' == $wp_version and !$installing) {
if (6.3 == floatval($wp_version) and !$installing) {
require __DIR__ . '/wp-settings.php';
} else {
require ABSPATH . 'wp-settings.php';
Expand Down
13 changes: 10 additions & 3 deletions includes/component/Requests/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class Requests {
'timeout' => 10,
'filename' => '',
'referer' => '',
'follow' => false,
];

private $args;

private $file;

public function request(string $url, array $args): array{
public function request(string $url, array $args): array {
$this->initRequest($url, $args);
$method = strtoupper($this->args['method']);

Expand Down Expand Up @@ -64,6 +65,12 @@ private function initRequest(string $url, array $args) {
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而不直接输出
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->args['timeout']);

// 重定向跟随
if ($this->args['follow']) {
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
}

if ($this->args['body']) {
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->args['body']);
}
Expand All @@ -78,7 +85,7 @@ private function initRequest(string $url, array $args) {
* 将数组键值对转为 curl headers 数组
*
*/
private static function arrayToHeaders(array $headers): array{
private static function arrayToHeaders(array $headers): array {
$result = [];
foreach ($headers as $key => $value) {
$result[] = $key . ':' . $value;
Expand Down Expand Up @@ -136,7 +143,7 @@ private function head() {
/**
* excute
*/
private function execute_request(): array{
private function execute_request(): array {
// curl_setopt($this->curl, CURLOPT_HEADER, true); // 开启header信息以供调试
// curl_setopt($this->curl, CURLINFO_HEADER_OUT, true);
$body = curl_exec($this->curl);
Expand Down
4 changes: 2 additions & 2 deletions wnd-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Wnd-Frontend
* Plugin URI: https://github.com/swling/wnd-frontend
* Description: Wnd-Frontend 是一套基于 ajax 交互逻辑的 WordPress 前端基础框架。商业用途需购买授权。<a href="https://github.com/swling/wnd-frontend/releases">更新日志</a>
* Version: 0.9.65
* Version: 0.9.66
* Author: swling
* Author URI: https://wndwp.com
* Requires PHP: 8.0
Expand All @@ -26,7 +26,7 @@
use Wnd\Model\Wnd_Init;

// 版本
define('WND_VER', '0.9.65');
define('WND_VER', '0.9.66');

// 定义插件网址路径
define('WND_URL', plugin_dir_url(__FILE__));
Expand Down

0 comments on commit f147a56

Please sign in to comment.