44 } |
44 } |
45 $this->useragent = 'The Incutio XML-RPC PHP Library'; |
45 $this->useragent = 'The Incutio XML-RPC PHP Library'; |
46 $this->timeout = $timeout; |
46 $this->timeout = $timeout; |
47 } |
47 } |
48 |
48 |
|
49 /** |
|
50 * @return bool |
|
51 */ |
49 public function query() { |
52 public function query() { |
50 $args = func_get_args(); |
53 $args = func_get_args(); |
51 $method = array_shift($args); |
54 $method = array_shift($args); |
52 $request = new IXR_Request($method, $args); |
55 $request = new IXR_Request($method, $args); |
53 $xml = $request->getXml(); |
56 $xml = $request->getXml(); |
59 'user-agent' => $this->useragent, |
62 'user-agent' => $this->useragent, |
60 'body' => $xml, |
63 'body' => $xml, |
61 ); |
64 ); |
62 |
65 |
63 // Merge Custom headers ala #8145 |
66 // Merge Custom headers ala #8145 |
64 foreach ( $this->headers as $header => $value ) |
67 foreach ( $this->headers as $header => $value ) { |
65 $args['headers'][$header] = $value; |
68 $args['headers'][$header] = $value; |
|
69 } |
66 |
70 |
67 if ( $this->timeout !== false ) |
71 /** |
|
72 * Filters the headers collection to be sent to the XML-RPC server. |
|
73 * |
|
74 * @since 4.4.0 |
|
75 * |
|
76 * @param array $headers Array of headers to be sent. |
|
77 */ |
|
78 $args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] ); |
|
79 |
|
80 if ( $this->timeout !== false ) { |
68 $args['timeout'] = $this->timeout; |
81 $args['timeout'] = $this->timeout; |
|
82 } |
69 |
83 |
70 // Now send the request |
84 // Now send the request |
71 if ( $this->debug ) |
85 if ( $this->debug ) { |
72 echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; |
86 echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; |
|
87 } |
73 |
88 |
74 $response = wp_remote_post($url, $args); |
89 $response = wp_remote_post($url, $args); |
75 |
90 |
76 if ( is_wp_error($response) ) { |
91 if ( is_wp_error($response) ) { |
77 $errno = $response->get_error_code(); |
92 $errno = $response->get_error_code(); |
83 if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
98 if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
84 $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')'); |
99 $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')'); |
85 return false; |
100 return false; |
86 } |
101 } |
87 |
102 |
88 if ( $this->debug ) |
103 if ( $this->debug ) { |
89 echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n"; |
104 echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n"; |
|
105 } |
90 |
106 |
91 // Now parse what we've got back |
107 // Now parse what we've got back |
92 $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) ); |
108 $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) ); |
93 if ( ! $this->message->parse() ) { |
109 if ( ! $this->message->parse() ) { |
94 // XML error |
110 // XML error |