WP_HTTP_IXR_Client

WP_HTTP_IXR_Client.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-wp-http-ixr-client.php  
  1. class WP_HTTP_IXR_Client extends IXR_Client { 
  2. public $scheme; 
  3. /** 
  4. * @var IXR_Error 
  5. */ 
  6. public $error; 
  7.  
  8. /** 
  9. * @param string $server 
  10. * @param string|bool $path 
  11. * @param int|bool $port 
  12. * @param int $timeout 
  13. */ 
  14. public function __construct($server, $path = false, $port = false, $timeout = 15) { 
  15. if ( ! $path ) { 
  16. // Assume we have been given a URL instead 
  17. $bits = parse_url($server); 
  18. $this->scheme = $bits['scheme']; 
  19. $this->server = $bits['host']; 
  20. $this->port = isset($bits['port']) ? $bits['port'] : $port; 
  21. $this->path = !empty($bits['path']) ? $bits['path'] : '/'; 
  22.  
  23. // Make absolutely sure we have a path 
  24. if ( ! $this->path ) { 
  25. $this->path = '/'; 
  26.  
  27. if ( ! empty( $bits['query'] ) ) { 
  28. $this->path .= '?' . $bits['query']; 
  29. } else { 
  30. $this->scheme = 'http'; 
  31. $this->server = $server; 
  32. $this->path = $path; 
  33. $this->port = $port; 
  34. $this->useragent = 'The Incutio XML-RPC PHP Library'; 
  35. $this->timeout = $timeout; 
  36.  
  37. /** 
  38. * @return bool 
  39. */ 
  40. public function query() { 
  41. $args = func_get_args(); 
  42. $method = array_shift($args); 
  43. $request = new IXR_Request($method, $args); 
  44. $xml = $request->getXml(); 
  45.  
  46. $port = $this->port ? ":$this->port" : ''; 
  47. $url = $this->scheme . '://' . $this->server . $port . $this->path; 
  48. $args = array( 
  49. 'headers' => array('Content-Type' => 'text/xml'),  
  50. 'user-agent' => $this->useragent,  
  51. 'body' => $xml,  
  52. ); 
  53.  
  54. // Merge Custom headers ala #8145 
  55. foreach ( $this->headers as $header => $value ) { 
  56. $args['headers'][$header] = $value; 
  57.  
  58. /** 
  59. * Filters the headers collection to be sent to the XML-RPC server. 
  60. * @since 4.4.0 
  61. * @param array $headers Array of headers to be sent. 
  62. */ 
  63. $args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] ); 
  64.  
  65. if ( $this->timeout !== false ) { 
  66. $args['timeout'] = $this->timeout; 
  67.  
  68. // Now send the request 
  69. if ( $this->debug ) { 
  70. echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; 
  71.  
  72. $response = wp_remote_post($url, $args); 
  73.  
  74. if ( is_wp_error($response) ) { 
  75. $errno = $response->get_error_code(); 
  76. $errorstr = $response->get_error_message(); 
  77. $this->error = new IXR_Error(-32300, "transport error: $errno $errorstr"); 
  78. return false; 
  79.  
  80. if ( 200 != wp_remote_retrieve_response_code( $response ) ) { 
  81. $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')'); 
  82. return false; 
  83.  
  84. if ( $this->debug ) { 
  85. echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n"; 
  86.  
  87. // Now parse what we've got back 
  88. $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) ); 
  89. if ( ! $this->message->parse() ) { 
  90. // XML error 
  91. $this->error = new IXR_Error(-32700, 'parse error. not well formed'); 
  92. return false; 
  93.  
  94. // Is the message a fault? 
  95. if ( $this->message->messageType == 'fault' ) { 
  96. $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); 
  97. return false; 
  98.  
  99. // Message must be OK 
  100. return true;