From c231f262db7e5cab6ed9cd992c1ebd6bcb94ecde Mon Sep 17 00:00:00 2001 From: sunxiyuan Date: Wed, 25 Mar 2020 09:48:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=8F=E6=88=91=E7=88=B1=E6=B0=B4=E7=85=AE?= =?UTF-8?q?=E9=B1=BC(http://blog.wpjam.com)=E6=8F=90=E9=86=92=EF=BC=8C?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=A0=B8=E5=BF=83=E4=BB=A3=E7=A0=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=B2=BE=E7=AE=80=E6=8E=89100=E4=BD=99=E8=A1=8C?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 129 +++--------------------------------------------------- 1 file changed, 5 insertions(+), 124 deletions(-) diff --git a/index.php b/index.php index 2eda3f5..35441e2 100644 --- a/index.php +++ b/index.php @@ -85,130 +85,11 @@ class WP_CHINA_YES { $url = str_replace('api.wordpress.org', $api_server, $url); $url = str_replace('downloads.wordpress.org', $download_server, $url); - if (function_exists('wp_kses_bad_protocol')) { - if ($r['reject_unsafe_urls']) { - $url = wp_http_validate_url($url); - } - if ($url) { - $url = wp_kses_bad_protocol($url, array( - 'http', - 'https', - 'ssl' - )); - } - } - - $arrURL = @parse_url($url); - - if (empty($url) || empty($arrURL['scheme'])) { - return new WP_Error('http_request_failed', __('A valid URL was not provided.')); - } - - if ($r['stream']) { - if (empty($r['filename'])) { - $r['filename'] = get_temp_dir() . basename($url); - } - - $r['blocking'] = true; - if ( ! wp_is_writable(dirname($r['filename']))) { - return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.')); - } - } - - if (is_null($r['headers'])) { - $r['headers'] = array(); - } - - if ( ! is_array($r['headers'])) { - $processedHeaders = WP_Http::processHeaders($r['headers']); - $r['headers'] = $processedHeaders['headers']; - } - - $headers = $r['headers']; - $data = $r['body']; - $type = $r['method']; - $options = array( - 'timeout' => $r['timeout'], - 'useragent' => $r['user-agent'], - 'blocking' => $r['blocking'], - 'hooks' => new WP_HTTP_Requests_Hooks($url, $r), - ); - - if ($r['stream']) { - $options['filename'] = $r['filename']; - } - if (empty($r['redirection'])) { - $options['follow_redirects'] = false; - } else { - $options['redirects'] = $r['redirection']; - } - - if (isset($r['limit_response_size'])) { - $options['max_bytes'] = $r['limit_response_size']; - } - - if ( ! empty($r['cookies'])) { - $options['cookies'] = WP_Http::normalize_cookies($r['cookies']); - } - - if ( ! $r['sslverify']) { - $options['verify'] = false; - $options['verifyname'] = false; - } else { - $options['verify'] = $r['sslcertificates']; - } - - if ('HEAD' !== $type && 'GET' !== $type) { - $options['data_format'] = 'body'; - } - - $options['verify'] = apply_filters('https_ssl_verify', $options['verify'], $url); - - $proxy = new WP_HTTP_Proxy(); - if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) { - $options['proxy'] = new Requests_Proxy_HTTP($proxy->host() . ':' . $proxy->port()); - - if ($proxy->use_authentication()) { - $options['proxy']->use_authentication = true; - $options['proxy']->user = $proxy->username(); - $options['proxy']->pass = $proxy->password(); - } - } - - mbstring_binary_safe_encoding(); - - try { - $requests_response = Requests::request($url, $headers, $data, $type, $options); - - $http_response = new WP_HTTP_Requests_Response($requests_response, $r['filename']); - $response = $http_response->to_array(); - - $response['http_response'] = $http_response; - } catch (Requests_Exception $e) { - $response = new WP_Error('http_request_failed', $e->getMessage()); - } - - reset_mbstring_encoding(); - - do_action('http_api_debug', $response, 'response', 'Requests', $r, $url); - if (is_wp_error($response)) { - return $response; - } - - if ( ! $r['blocking']) { - return array( - 'headers' => array(), - 'body' => '', - 'response' => array( - 'code' => false, - 'message' => false, - ), - 'cookies' => array(), - 'http_response' => null, - ); - } - - return apply_filters('http_response', $response, $r, $url); + /** + * 此处原本是复制了官方对外部请求处理的原始代码 + * 后经我爱水煮鱼(http://blog.wpjam.com/)提醒,可以直接调用wp_remote_request达成相同目的,由此精简掉100余行代码。 + */ + return wp_remote_request($url , $r); } public static function plugin_row_meta($links, $file) {