version 4.13.0

This commit is contained in:
2021-12-07 11:08:05 +00:00
commit cb26d2c0c4
1285 changed files with 254735 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
if ( ! class_exists( 'Endurance_Page_Cache' ) ) {
return;
}
// https://github.com/bluehost/endurance-page-cache
class ET_Core_LIB_BluehostCache extends Endurance_Page_Cache {
private static $_instance;
public function __construct() {
$this->purged = array();
$this->trigger = null;
$this->cache_level = get_option( 'endurance_cache_level', 2 );
$this->cache_dir = WP_CONTENT_DIR . '/endurance-page-cache';
$this->cache_exempt = array( 'wp-admin', '.', 'checkout', 'cart', 'wp-json', '%', '=', '@', '&', ':', ';', );
}
public static function get_instance() {
if ( null === self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
public function clear( $post_id = '' ) {
if ( '' !== $post_id && method_exists( $this, 'purge_single' ) ) {
$this->purge_single( get_the_permalink( $post_id ) );
} else if ( '' === $post_id && method_exists( $this, 'purge_all' ) ) {
$this->purge_all();
}
}
}

View File

@ -0,0 +1,503 @@
<?php
/**
* ET Core OAuth Library
*
* Copyright © 2016-2017 Elegant Themes, Inc.
*
* Based on code from the TwitterOAuth Library:
* - Copyright © 2009-2016 Abraham Williams
* - Copyright © 2007-2009 Andy Smith
*
* @license
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
class ET_Core_LIB_OAuthBase {
/**
* Writes a message to the PHP error log.
*
* @since 1.1.0
*
* @param mixed $msg
*/
public static function write_log( $msg, $level = 'DEBUG', $_this = null ) {
$name = ( null !== $_this ) ? get_class( $_this ) : 'ET_Core_LIB_OAuthBase';
if ( ! is_string( $msg ) ) {
$msg = print_r( $msg, true );
}
error_log( "{$name} [{$level}]: $msg" );
}
}
class ET_Core_LIB_OAuthUtil {
public static function build_http_query( $params, $return_json=false ) {
if ( ! $params ) {
return '';
}
if ( $return_json ) {
// return json string without further processing if needed
return json_encode( $params );
}
// Url encode both the keys and the values
$keys = ET_Core_LIB_OAuthUtil::urlencode_rfc3986( array_keys( $params ) );
$values = ET_Core_LIB_OAuthUtil::urlencode_rfc3986( array_values( $params ) );
$params = array_combine( $keys, $values );
// Parameters are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort( $params, 'strcmp' );
$pairs = array();
foreach ( $params as $parameter => $value ) {
if ( is_array( $value ) ) {
// When two or more parameters share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
// June 12th, 2010 - changed to sort because of issue 164 by hidetaka
sort( $value, SORT_STRING );
foreach ( $value as $duplicate_value ) {
$pairs[] = "{$parameter}={$duplicate_value}";
}
} else {
$pairs[] = "{$parameter}={$value}";
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode( '&', $pairs );
}
public static function parse_parameters( $input = '' ) {
if ( '' === $input ) {
return array();
}
$pairs = explode( '&', $input );
$parsed_parameters = array();
foreach ( $pairs as $pair ) {
$split = explode( '=', $pair, 2 );
$parameter = ET_Core_LIB_OAuthUtil::urldecode_rfc3986( $split[0] );
$value = isset( $split[1] ) ? ET_Core_LIB_OAuthUtil::urldecode_rfc3986( $split[1] ) : '';
if ( isset( $parsed_parameters[ $parameter ] ) ) {
// We have already received parameter(s) with this name, so add to the list
// of parameters with this name
if ( is_scalar( $parsed_parameters[ $parameter ] ) ) {
// This is the first duplicate, so transform scalar (string) into an array
// so we can add the duplicates
$parsed_parameters[ $parameter ] = array( $parsed_parameters[ $parameter ] );
}
$parsed_parameters[ $parameter ][] = $value;
} else {
$parsed_parameters[ $parameter ] = $value;
}
}
return $parsed_parameters;
}
public static function urldecode_rfc3986( $string ) {
return rawurldecode( $string );
}
public static function urlencode_rfc3986( $input ) {
$output = '';
if ( is_array( $input ) ) {
$output = array_map( array( 'ET_Core_LIB_OAuthUtil', 'urlencode_rfc3986' ), $input );
} else if ( is_scalar( $input ) ) {
$output = rawurlencode( utf8_encode( $input ) );
}
return $output;
}
}
/**
* A base class for implementing a Signature Method
* See section 9 ("Signing Requests") in the spec
*/
abstract class ET_Core_LIB_OAuthSignatureMethod {
/**
* Build the signature
* NOTE: The output of this function MUST NOT be urlencoded. The encoding is handled in
* {@link ET_Core_OAuth_Request} when the final request is serialized.
*
* @param ET_Core_LIB_OAuthRequest $request
* @param ET_Core_LIB_OAuthConsumer $consumer
* @param ET_Core_LIB_OAuthToken|null $token
*
* @return string
*/
abstract public function build_signature( $request, $consumer, $token = null );
/**
* Verifies that a given signature is correct
*
* @param ET_Core_LIB_OAuthRequest $request
* @param ET_Core_LIB_OAuthConsumer $consumer
* @param ET_Core_LIB_OAuthToken $token
* @param string $signature
*
* @return bool
*/
public function check_signature( $request, $consumer, $token, $signature ) {
$built = $this->build_signature( $request, $consumer, $token );
// Check for zero length, although its unlikely here
if ( empty( $built ) || empty( $signature ) ) {
return false;
}
if ( strlen( $built ) !== strlen( $signature ) ) {
return false;
}
// Avoid a timing leak with a (hopefully) time insensitive compare
$result = 0;
for ( $i = 0; $i < strlen( $signature ); $i ++ ) {
$result |= ord( $built[ $i ] ) ^ ord( $signature[ $i ] );
}
return 0 === $result;
}
/**
* Returns the name of this Signature Method (ie HMAC-SHA1)
*
* @return string
*/
abstract public function get_name();
}
/**
* The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] where
* the Signature Base String is the text and the key is the concatenated values of the Consumer Secret and
* Token Secret (each encoded per Parameter Encoding first), separated by an '&' character (ASCII code 38)
* even if empty. As per Chapter 9.2 of the HMAC-SHA1 spec.
*/
class ET_Core_LIB_OAuthHMACSHA1 extends ET_Core_LIB_OAuthSignatureMethod {
/**
* @inheritDoc
*/
public function build_signature( $request, $consumer, $token = null ) {
$base_string = $request->get_signature_base_string();
$token = $token ? $token->secret : '';
$request->base_string = $base_string;
$key_parts = array( $consumer->secret, $token );
$key = implode( '&', $key_parts );
return base64_encode( hash_hmac( 'sha1', $base_string, $key, true ) );
}
/**
* @inheritDoc
*/
public function get_name() {
return 'HMAC-SHA1';
}
}
class ET_Core_LIB_OAuthConsumer {
public $callback_url;
public $id;
public $key;
public $secret;
public function __construct( $id, $secret, $callback_url = '' ) {
$this->id = $this->key = $id;
$this->secret = $secret;
$this->callback_url = $callback_url;
}
function __toString() {
$name = get_class( $this );
$key = 'ET_Core_LIB_OAuthConsumer' === $name ? 'key' : 'id';
return "{$name}[{$key}={$this->key}, secret={$this->secret}]";
}
}
class ET_Core_LIB_OAuthToken {
public $key;
public $secret;
public $refresh_token;
/**
* @param string $key The OAuth Token
* @param string $secret The OAuth Token Secret
*/
public function __construct( $key, $secret ) {
$this->key = $key;
$this->secret = $secret;
}
/**
* Generates the basic string serialization of a token that a server
* would respond to 'request_token' and 'access_token' calls with
*
* @return string
*/
public function __toString() {
return sprintf( "oauth_token=%s&oauth_token_secret=%s",
ET_Core_LIB_OAuthUtil::urlencode_rfc3986( $this->key ),
ET_Core_LIB_OAuthUtil::urlencode_rfc3986( $this->secret )
);
}
}
class ET_Core_LIB_OAuthRequest extends ET_Core_LIB_OAuthBase {
protected $parameters;
protected $http_method;
protected $http_url;
public static $version = '1.0';
public $base_string;
/**
* ET_Core_OAuth_Request Constructor
*
* @param string $http_method
* @param string $http_url
* @param array|null $parameters
*/
public function __construct( $http_method, $http_url, $parameters = array() ) {
$this->parameters = $parameters;
$this->http_method = $http_method;
$this->http_url = $http_url;
}
/**
* pretty much a helper function to set up the request
*
* @param ET_Core_LIB_OAuthConsumer $consumer
* @param ET_Core_LIB_OAuthToken $token
* @param string $http_method
* @param string $http_url
* @param array $parameters
*
* @return ET_Core_LIB_OAuthRequest
*/
public static function from_consumer_and_token( $consumer, $token, $http_method, $http_url, $parameters = array() ) {
$defaults = array(
"oauth_version" => ET_Core_LIB_OAuthRequest::$version,
"oauth_nonce" => ET_Core_LIB_OAuthRequest::generate_nonce(),
"oauth_timestamp" => time(),
"oauth_consumer_key" => $consumer->key
);
if ( $token ) {
$defaults['oauth_token'] = $token->key;
}
$parameters = wp_parse_args( $parameters, $defaults );
return new ET_Core_LIB_OAuthRequest( $http_method, $http_url, $parameters );
}
/**
* Returns the HTTP Method in uppercase
*
* @return string
*/
public function get_normalized_http_method() {
return strtoupper( $this->http_method );
}
/**
* parses the url and rebuilds it to be
* scheme://host/path
*
* @return string
*/
public function get_normalized_http_url() {
$parts = parse_url( $this->http_url );
$scheme = $parts['scheme'];
$host = strtolower( $parts['host'] );
$path = $parts['path'];
return "{$scheme}://{$host}{$path}";
}
/**
* @param $name
*
* @return string|null
*/
public function get_parameter( $name ) {
return isset( $this->parameters[ $name ] ) ? $this->parameters[ $name ] : null;
}
/**
* @return array
*/
public function get_parameters() {
return $this->parameters;
}
/**
* The request parameters, sorted and concatenated into a normalized string.
*
* @return string
*/
public function get_signable_parameters() {
// Grab a copy of all parameters
$params = $this->parameters;
// Remove oauth_signature if present
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
if ( isset( $params['oauth_signature'] ) ) {
unset( $params['oauth_signature'] );
}
return ET_Core_LIB_OAuthUtil::build_http_query( $params );
}
/**
* Returns the base string of this request
*
* The base string defined as the method, the url, and the parameters (normalized),
* each urlencoded and then concatenated with '&'.
*
* @return string
*/
public function get_signature_base_string() {
$parts = array(
$this->get_normalized_http_method(),
$this->get_normalized_http_url(),
$this->get_signable_parameters()
);
$parts = ET_Core_LIB_OAuthUtil::urlencode_rfc3986( $parts );
return implode( '&', $parts );
}
/**
* @param $name
*/
public function remove_parameter( $name ) {
unset( $this->parameters[ $name ] );
}
/**
* @param string $name
* @param string $value
*/
public function set_parameter( $name, $value ) {
$this->parameters[ $name ] = $value;
}
/**
* Builds the data one would send in a POST request
* @param bool $need_json indicates the query data format ( http query string or json string )
*
* @return string
*/
public function to_post_data( $need_json = false ) {
return ET_Core_LIB_OAuthUtil::build_http_query( $this->parameters, $need_json );
}
/**
* Builds a url usable for a GET request
*
* @return string
*/
public function to_url() {
$postData = $this->to_post_data();
$out = $this->get_normalized_http_url();
if ( $postData ) {
$out .= '?' . $postData;
}
return $out;
}
/**
* Builds the HTTP Authorization Header
*
* @return string
*/
public function to_header() {
$out = '';
foreach ( $this->parameters as $parameter => $value ) {
if ( 0 !== strpos( 'oauth', $parameter ) ) {
continue;
}
if ( is_array( $value ) ) {
self::write_log( 'Arrays not supported in headers!', 'ERROR' );
continue;
}
$out .= ( '' === $out ) ? 'OAuth ' : ', ';
$out .= ET_Core_LIB_OAuthUtil::urlencode_rfc3986( $parameter );
$out .= '="' . ET_Core_LIB_OAuthUtil::urlencode_rfc3986( $value ) . '"';
}
return $out;
}
/**
* @return string
*/
public function __toString() {
return $this->to_url();
}
/**
* @param ET_Core_LIB_OAuthSignatureMethod $signature_method
* @param ET_Core_LIB_OAuthConsumer $consumer
* @param ET_Core_LIB_OAuthToken $token
*/
public function sign_request( $signature_method, $consumer, $token = null ) {
$this->set_parameter( 'oauth_signature_method', $signature_method->get_name() );
$signature = $this->build_signature( $signature_method, $consumer, $token );
$this->set_parameter( 'oauth_signature', $signature );
}
/**
* @param ET_Core_LIB_OAuthSignatureMethod $signatureMethod
* @param ET_Core_LIB_OAuthConsumer $consumer
* @param ET_Core_LIB_OAuthToken $token
*
* @return string
*/
public function build_signature( $signatureMethod, $consumer, $token = null ) {
return $signatureMethod->build_signature( $this, $consumer, $token );
}
/**
* @return string
*/
public static function generate_nonce() {
return md5( microtime() . mt_rand() );
}
}

View File

@ -0,0 +1,27 @@
<?php
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
if ( ! class_exists( 'ET_Core_LIB_SilentThemeUpgraderSkin' ) ):
/**
* Theme Upgrader skin which does not output feedback.
*
* @since 3.10
*
* @private
*/
class ET_Core_LIB_SilentThemeUpgraderSkin extends WP_Upgrader_Skin {
/**
* Override feedback method.
*
* @since 3.10
*
* @private
*
* @param string $string Feedback string.
* @param mixed ...$args Optional text replacements.
*/
public function feedback( $string, ...$args ) {
return; // Suppress all feedback.
}
}
endif;

View File

@ -0,0 +1,354 @@
<?php
require_once ABSPATH . WPINC . '/class-http.php';
/**
* Some 3rd-party APIs require data to be sent in the request body for
* GET requests (eg. SendinBlue). This is not currently possible using the WP
* HTTP API. I've submitted a patch to WP Core for this. Until its merged, we
* have to extend the WP_HTTP class and override the method in question.
*
* @see https://core.trac.wordpress.org/ticket/39043
*
* @private
*/
class ET_Core_LIB_WPHttp extends WP_Http {
/**
* Send an HTTP request to a URI.
*
* Please note: The only URI that are supported in the HTTP Transport implementation
* are the HTTP and HTTPS protocols.
*
* @access public
* @since 2.7.0
*
* @param string $url The request URL.
* @param string|array $args {
* Optional. Array or string of HTTP request arguments.
*
* @type string $method Request method. Accepts 'GET', 'POST', 'HEAD', or 'PUT'.
* Some transports technically allow others, but should not be
* assumed. Default 'GET'.
* @type int $timeout How long the connection should stay open in seconds. Default 5.
* @type int $redirection Number of allowed redirects. Not supported by all transports
* Default 5.
* @type string $httpversion Version of the HTTP protocol to use. Accepts '1.0' and '1.1'.
* Default '1.0'.
* @type string $user-agent User-agent value sent.
* Default WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ).
* @type bool $reject_unsafe_urls Whether to pass URLs through wp_http_validate_url().
* Default false.
* @type bool $blocking Whether the calling code requires the result of the request.
* If set to false, the request will be sent to the remote server,
* and processing returned to the calling code immediately, the caller
* will know if the request succeeded or failed, but will not receive
* any response from the remote server. Default true.
* @type string|array $headers Array or string of headers to send with the request.
* Default empty array.
* @type array $cookies List of cookies to send with the request. Default empty array.
* @type string|array $body Body to send with the request. Default null.
* @type bool $compress Whether to compress the $body when sending the request.
* Default false.
* @type bool $decompress Whether to decompress a compressed response. If set to false and
* compressed content is returned in the response anyway, it will
* need to be separately decompressed. Default true.
* @type bool $sslverify Whether to verify SSL for the request. Default true.
* @type string sslcertificates Absolute path to an SSL certificate .crt file.
* Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'.
* @type bool $stream Whether to stream to a file. If set to true and no filename was
* given, the stream will be output to a new file in the WP temp dir
* using a name generated from the basename of the URL. Default false.
* @type string $filename Filename of the file to write to when streaming. $stream must be
* set to true. Default null.
* @type int $limit_response_size Size in bytes to limit the response to. Default null.
* @type bool|null $data_format How the `$data` should be sent ('query' or 'body'). Default null.
* If null, data will be sent as 'query' for HEAD/GET and as
* 'body' for POST/PUT/OPTIONS/PATCH/DELETE.
*
* }
* @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
* A WP_Error instance upon error.
*/
public function request( $url, $args = array() ) {
$defaults = array(
'method' => 'GET',
/**
* Filters the timeout value for an HTTP request.
*
* @since 2.7.0
*
* @param int $timeout_value Time in seconds until a request times out.
* Default 5.
*/
'timeout' => apply_filters( 'http_request_timeout', 5 ),
/**
* Filters the number of redirects allowed during an HTTP request.
*
* @since 2.7.0
*
* @param int $redirect_count Number of redirects allowed. Default 5.
*/
'redirection' => apply_filters( 'http_request_redirection_count', 5 ),
/**
* Filters the version of the HTTP protocol used in a request.
*
* @since 2.7.0
*
* @param string $version Version of HTTP used. Accepts '1.0' and '1.1'.
* Default '1.0'.
*/
'httpversion' => apply_filters( 'http_request_version', '1.0' ),
/**
* Filters the user agent value sent with an HTTP request.
*
* @since 2.7.0
*
* @param string $user_agent WordPress user agent string.
*/
'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ),
/**
* Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.
*
* @since 3.6.0
*
* @param bool $pass_url Whether to pass URLs through wp_http_validate_url().
* Default false.
*/
'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
'blocking' => true,
'headers' => array(),
'cookies' => array(),
'body' => null,
'compress' => false,
'decompress' => true,
'sslverify' => true,
'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
'stream' => false,
'filename' => null,
'limit_response_size' => null,
'data_format' => null,
);
// Pre-parse for the HEAD checks.
$args = wp_parse_args( $args );
// By default, Head requests do not cause redirections.
if ( isset( $args['method'] ) && 'HEAD' === $args['method'] ) {
$defaults['redirection'] = 0;
}
$request_args = wp_parse_args( $args, $defaults );
/**
* Filters the arguments used in an HTTP request.
*
* @since 2.7.0
*
* @param array $request_args An array of HTTP request arguments.
* @param string $url The request URL.
*/
$request_args = apply_filters( 'http_request_args', $request_args, $url );
// The transports decrement this, store a copy of the original value for loop purposes.
if ( ! isset( $request_args['_redirection'] ) ) {
$request_args['_redirection'] = $request_args['redirection'];
}
/**
* Filters whether to preempt an HTTP request's return value.
*
* Returning a non-false value from the filter will short-circuit the HTTP request and return
* early with that value. A filter should return either:
*
* - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
* - A WP_Error instance
* - boolean false (to avoid short-circuiting the response)
*
* Returning any other value may result in unexpected behaviour.
*
* @since 2.9.0
*
* @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
* @param array $request_args HTTP request arguments.
* @param string $url The request URL.
*/
$pre = apply_filters( 'pre_http_request', false, $request_args, $url );
if ( false !== $pre ) {
return $pre;
}
if ( function_exists( 'wp_kses_bad_protocol' ) ) {
if ( $request_args['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', esc_html__( 'A valid URL was not provided.' ) );
}
if ( $this->block_request( $url ) ) {
return new WP_Error( 'http_request_failed', esc_html__( 'User has blocked requests through HTTP.' ) );
}
// If we are streaming to a file but no filename was given drop it in the WP temp dir
// and pick its name using the basename of the $url
if ( $request_args['stream'] ) {
if ( empty( $request_args['filename'] ) ) {
$request_args['filename'] = get_temp_dir() . basename( $url );
}
// Force some settings if we are streaming to a file and check for existence and perms of destination directory
$request_args['blocking'] = true;
if ( ! wp_is_writable( dirname( $request_args['filename'] ) ) ) {
return new WP_Error( 'http_request_failed', esc_html__( 'Destination directory for file streaming does not exist or is not writable.' ) );
}
}
if ( is_null( $request_args['headers'] ) ) {
$request_args['headers'] = array();
}
// WP allows passing in headers as a string, weirdly.
if ( ! is_array( $request_args['headers'] ) ) {
$processedHeaders = WP_Http::processHeaders( $request_args['headers'] );
$request_args['headers'] = $processedHeaders['headers'];
}
// Setup arguments
$headers = $request_args['headers'];
$data = $request_args['body'];
$type = $request_args['method'];
$options = array(
'timeout' => $request_args['timeout'],
'useragent' => $request_args['user-agent'],
'blocking' => $request_args['blocking'],
'hooks' => new WP_HTTP_Requests_Hooks( $url, $request_args ),
);
// Ensure redirects follow browser behaviour.
$options['hooks']->register( 'requests.before_redirect', array(
get_class(),
'browser_redirect_compatibility'
) );
if ( $request_args['stream'] ) {
$options['filename'] = $request_args['filename'];
}
if ( empty( $request_args['redirection'] ) ) {
$options['follow_redirects'] = false;
} else {
$options['redirects'] = $request_args['redirection'];
}
// Use byte limit, if we can
if ( isset( $request_args['limit_response_size'] ) ) {
$options['max_bytes'] = $request_args['limit_response_size'];
}
// If we've got cookies, use and convert them to Requests_Cookie.
if ( ! empty( $request_args['cookies'] ) ) {
$options['cookies'] = WP_Http::normalize_cookies( $request_args['cookies'] );
}
// SSL certificate handling
if ( ! $request_args['sslverify'] ) {
$options['verify'] = false;
$options['verifyname'] = false;
} else {
$options['verify'] = $request_args['sslcertificates'];
}
if ( null !== $request_args['data_format'] ) {
$options['data_format'] = $request_args['data_format'];
} elseif ( 'HEAD' !== $type && 'GET' !== $type ) {
// All non-GET/HEAD requests should put the arguments in the form body.
$options['data_format'] = 'body';
}
/**
* Filters whether SSL should be verified for non-local requests.
*
* @since 2.8.0
*
* @param bool $ssl_verify Whether to verify the SSL connection. Default true.
*/
$options['verify'] = apply_filters( 'https_ssl_verify', $options['verify'] );
// Check for proxies.
$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();
}
}
// Avoid issues where mbstring.func_overload is enabled
mbstring_binary_safe_encoding();
try {
$requests_response = Requests::request( $url, $headers, $data, $type, $options );
// Convert the response into an array
$http_response = new WP_HTTP_Requests_Response( $requests_response, $request_args['filename'] );
$response = $http_response->to_array();
// Add the original object to the array.
$response['http_response'] = $http_response;
} catch ( Requests_Exception $e ) {
$response = new WP_Error( 'http_request_failed', $e->getMessage() );
}
reset_mbstring_encoding();
/**
* Fires after an HTTP API response is received and before the response is returned.
*
* @since 2.8.0
*
* @param array|WP_Error $response HTTP response or WP_Error object.
* @param string $context Context under which the hook is fired.
* @param string $class HTTP transport used.
* @param array $args HTTP request arguments.
* @param string $url The request URL.
*/
do_action( 'http_api_debug', $response, 'response', 'Requests', $request_args, $url );
if ( is_wp_error( $response ) ) {
return $response;
}
if ( ! $request_args['blocking'] ) {
return array(
'headers' => array(),
'body' => '',
'response' => array(
'code' => false,
'message' => false,
),
'cookies' => array(),
'http_response' => null,
);
}
/**
* Filters the HTTP API response immediately before the response is returned.
*
* @since 2.9.0
*
* @param array $response HTTP response.
* @param array $request_args HTTP request arguments.
* @param string $url The request URL.
*/
return apply_filters( 'http_response', $response, $request_args, $url );
}
}