]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-http-ixr-client.php
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-includes / class-wp-http-ixr-client.php
index 4c36334eeef5d4117afbb3ab2e55119065316267..e4ed55020fcd48ff67440de0972aae29fa5e75a1 100644 (file)
@@ -7,18 +7,35 @@
  *
  */
 class WP_HTTP_IXR_Client extends IXR_Client {
-       function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) {
+       public $scheme;
+       /**
+        * @var IXR_Error
+        */
+       public $error;
+
+       /**
+        * @param string $server
+        * @param string|bool $path
+        * @param int|bool $port
+        * @param int $timeout
+        */
+       public function __construct($server, $path = false, $port = false, $timeout = 15) {
                if ( ! $path ) {
                        // Assume we have been given a URL instead
                        $bits = parse_url($server);
                        $this->scheme = $bits['scheme'];
                        $this->server = $bits['host'];
-                       $this->port = isset($bits['port']) ? $bits['port'] : 80;
+                       $this->port = isset($bits['port']) ? $bits['port'] : $port;
                        $this->path = !empty($bits['path']) ? $bits['path'] : '/';
 
                        // Make absolutely sure we have a path
-                       if ( ! $this->path )
+                       if ( ! $this->path ) {
                                $this->path = '/';
+                       }
+
+                       if ( ! empty( $bits['query'] ) ) {
+                               $this->path .= '?' . $bits['query'];
+                       }
                } else {
                        $this->scheme = 'http';
                        $this->server = $server;
@@ -29,13 +46,17 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                $this->timeout = $timeout;
        }
 
-       function query() {
+       /**
+        * @return bool
+        */
+       public function query() {
                $args = func_get_args();
                $method = array_shift($args);
                $request = new IXR_Request($method, $args);
                $xml = $request->getXml();
 
-               $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path;
+               $port = $this->port ? ":$this->port" : '';
+               $url = $this->scheme . '://' . $this->server . $port . $this->path;
                $args = array(
                        'headers'    => array('Content-Type' => 'text/xml'),
                        'user-agent' => $this->useragent,
@@ -43,15 +64,27 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                );
 
                // Merge Custom headers ala #8145
-               foreach ( $this->headers as $header => $value )
+               foreach ( $this->headers as $header => $value ) {
                        $args['headers'][$header] = $value;
+               }
+
+               /**
+                * Filters the headers collection to be sent to the XML-RPC server.
+                *
+                * @since 4.4.0
+                *
+                * @param array $headers Array of headers to be sent.
+                */
+               $args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] );
 
-               if ( $this->timeout !== false )
+               if ( $this->timeout !== false ) {
                        $args['timeout'] = $this->timeout;
+               }
 
                // Now send the request
-               if ( $this->debug )
+               if ( $this->debug ) {
                        echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n";
+               }
 
                $response = wp_remote_post($url, $args);
 
@@ -62,16 +95,17 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                        return false;
                }
 
-               if ( $response['response']['code'] != 200 ) {
-                       $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
+               if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
+                       $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
                        return false;
                }
 
-               if ( $this->debug )
-                       echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
+               if ( $this->debug ) {
+                       echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
+               }
 
                // Now parse what we've got back
-               $this->message = new IXR_Message( $response['body'] );
+               $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
                if ( ! $this->message->parse() ) {
                        // XML error
                        $this->error = new IXR_Error(-32700, 'parse error. not well formed');
@@ -88,4 +122,3 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                return true;
        }
 }
-?>
\ No newline at end of file