43 * |
43 * |
44 * @param string $url URL to retrieve. |
44 * @param string $url URL to retrieve. |
45 * @param array $args Optional. Request arguments. Default empty array. |
45 * @param array $args Optional. Request arguments. Default empty array. |
46 * See WP_Http::request() for information on accepted arguments. |
46 * See WP_Http::request() for information on accepted arguments. |
47 * @return array|WP_Error The response or WP_Error on failure. |
47 * @return array|WP_Error The response or WP_Error on failure. |
|
48 * See WP_Http::request() for information on return value. |
48 */ |
49 */ |
49 function wp_safe_remote_request( $url, $args = array() ) { |
50 function wp_safe_remote_request( $url, $args = array() ) { |
50 $args['reject_unsafe_urls'] = true; |
51 $args['reject_unsafe_urls'] = true; |
51 $http = _wp_http_get_object(); |
52 $http = _wp_http_get_object(); |
52 return $http->request( $url, $args ); |
53 return $http->request( $url, $args ); |
69 * |
70 * |
70 * @param string $url URL to retrieve. |
71 * @param string $url URL to retrieve. |
71 * @param array $args Optional. Request arguments. Default empty array. |
72 * @param array $args Optional. Request arguments. Default empty array. |
72 * See WP_Http::request() for information on accepted arguments. |
73 * See WP_Http::request() for information on accepted arguments. |
73 * @return array|WP_Error The response or WP_Error on failure. |
74 * @return array|WP_Error The response or WP_Error on failure. |
|
75 * See WP_Http::request() for information on return value. |
74 */ |
76 */ |
75 function wp_safe_remote_get( $url, $args = array() ) { |
77 function wp_safe_remote_get( $url, $args = array() ) { |
76 $args['reject_unsafe_urls'] = true; |
78 $args['reject_unsafe_urls'] = true; |
77 $http = _wp_http_get_object(); |
79 $http = _wp_http_get_object(); |
78 return $http->get( $url, $args ); |
80 return $http->get( $url, $args ); |
95 * |
97 * |
96 * @param string $url URL to retrieve. |
98 * @param string $url URL to retrieve. |
97 * @param array $args Optional. Request arguments. Default empty array. |
99 * @param array $args Optional. Request arguments. Default empty array. |
98 * See WP_Http::request() for information on accepted arguments. |
100 * See WP_Http::request() for information on accepted arguments. |
99 * @return array|WP_Error The response or WP_Error on failure. |
101 * @return array|WP_Error The response or WP_Error on failure. |
|
102 * See WP_Http::request() for information on return value. |
100 */ |
103 */ |
101 function wp_safe_remote_post( $url, $args = array() ) { |
104 function wp_safe_remote_post( $url, $args = array() ) { |
102 $args['reject_unsafe_urls'] = true; |
105 $args['reject_unsafe_urls'] = true; |
103 $http = _wp_http_get_object(); |
106 $http = _wp_http_get_object(); |
104 return $http->post( $url, $args ); |
107 return $http->post( $url, $args ); |
121 * |
124 * |
122 * @param string $url URL to retrieve. |
125 * @param string $url URL to retrieve. |
123 * @param array $args Optional. Request arguments. Default empty array. |
126 * @param array $args Optional. Request arguments. Default empty array. |
124 * See WP_Http::request() for information on accepted arguments. |
127 * See WP_Http::request() for information on accepted arguments. |
125 * @return array|WP_Error The response or WP_Error on failure. |
128 * @return array|WP_Error The response or WP_Error on failure. |
|
129 * See WP_Http::request() for information on return value. |
126 */ |
130 */ |
127 function wp_safe_remote_head( $url, $args = array() ) { |
131 function wp_safe_remote_head( $url, $args = array() ) { |
128 $args['reject_unsafe_urls'] = true; |
132 $args['reject_unsafe_urls'] = true; |
129 $http = _wp_http_get_object(); |
133 $http = _wp_http_get_object(); |
130 return $http->head( $url, $args ); |
134 return $http->head( $url, $args ); |
144 * @see WP_Http::request() For information on default arguments. |
148 * @see WP_Http::request() For information on default arguments. |
145 * |
149 * |
146 * @param string $url URL to retrieve. |
150 * @param string $url URL to retrieve. |
147 * @param array $args Optional. Request arguments. Default empty array. |
151 * @param array $args Optional. Request arguments. Default empty array. |
148 * See WP_Http::request() for information on accepted arguments. |
152 * See WP_Http::request() for information on accepted arguments. |
149 * @return array|WP_Error { |
153 * @return array|WP_Error The response array or a WP_Error on failure. |
150 * The response array or a WP_Error on failure. |
154 * See WP_Http::request() for information on return value. |
151 * |
|
152 * @type string[] $headers Array of response headers keyed by their name. |
|
153 * @type string $body Response body. |
|
154 * @type array $response { |
|
155 * Data about the HTTP response. |
|
156 * |
|
157 * @type int|false $code HTTP response code. |
|
158 * @type string|false $message HTTP response message. |
|
159 * } |
|
160 * @type WP_HTTP_Cookie[] $cookies Array of response cookies. |
|
161 * @type WP_HTTP_Requests_Response|null $http_response Raw HTTP response object. |
|
162 * } |
|
163 */ |
155 */ |
164 function wp_remote_request( $url, $args = array() ) { |
156 function wp_remote_request( $url, $args = array() ) { |
165 $http = _wp_http_get_object(); |
157 $http = _wp_http_get_object(); |
166 return $http->request( $url, $args ); |
158 return $http->request( $url, $args ); |
167 } |
159 } |
176 * |
168 * |
177 * @param string $url URL to retrieve. |
169 * @param string $url URL to retrieve. |
178 * @param array $args Optional. Request arguments. Default empty array. |
170 * @param array $args Optional. Request arguments. Default empty array. |
179 * See WP_Http::request() for information on accepted arguments. |
171 * See WP_Http::request() for information on accepted arguments. |
180 * @return array|WP_Error The response or WP_Error on failure. |
172 * @return array|WP_Error The response or WP_Error on failure. |
|
173 * See WP_Http::request() for information on return value. |
181 */ |
174 */ |
182 function wp_remote_get( $url, $args = array() ) { |
175 function wp_remote_get( $url, $args = array() ) { |
183 $http = _wp_http_get_object(); |
176 $http = _wp_http_get_object(); |
184 return $http->get( $url, $args ); |
177 return $http->get( $url, $args ); |
185 } |
178 } |
194 * |
187 * |
195 * @param string $url URL to retrieve. |
188 * @param string $url URL to retrieve. |
196 * @param array $args Optional. Request arguments. Default empty array. |
189 * @param array $args Optional. Request arguments. Default empty array. |
197 * See WP_Http::request() for information on accepted arguments. |
190 * See WP_Http::request() for information on accepted arguments. |
198 * @return array|WP_Error The response or WP_Error on failure. |
191 * @return array|WP_Error The response or WP_Error on failure. |
|
192 * See WP_Http::request() for information on return value. |
199 */ |
193 */ |
200 function wp_remote_post( $url, $args = array() ) { |
194 function wp_remote_post( $url, $args = array() ) { |
201 $http = _wp_http_get_object(); |
195 $http = _wp_http_get_object(); |
202 return $http->post( $url, $args ); |
196 return $http->post( $url, $args ); |
203 } |
197 } |
212 * |
206 * |
213 * @param string $url URL to retrieve. |
207 * @param string $url URL to retrieve. |
214 * @param array $args Optional. Request arguments. Default empty array. |
208 * @param array $args Optional. Request arguments. Default empty array. |
215 * See WP_Http::request() for information on accepted arguments. |
209 * See WP_Http::request() for information on accepted arguments. |
216 * @return array|WP_Error The response or WP_Error on failure. |
210 * @return array|WP_Error The response or WP_Error on failure. |
|
211 * See WP_Http::request() for information on return value. |
217 */ |
212 */ |
218 function wp_remote_head( $url, $args = array() ) { |
213 function wp_remote_head( $url, $args = array() ) { |
219 $http = _wp_http_get_object(); |
214 $http = _wp_http_get_object(); |
220 return $http->head( $url, $args ); |
215 return $http->head( $url, $args ); |
221 } |
216 } |
387 * that requirement to the capabilities array. |
382 * that requirement to the capabilities array. |
388 * |
383 * |
389 * @return bool |
384 * @return bool |
390 */ |
385 */ |
391 function wp_http_supports( $capabilities = array(), $url = null ) { |
386 function wp_http_supports( $capabilities = array(), $url = null ) { |
392 $http = _wp_http_get_object(); |
|
393 |
|
394 $capabilities = wp_parse_args( $capabilities ); |
387 $capabilities = wp_parse_args( $capabilities ); |
395 |
388 |
396 $count = count( $capabilities ); |
389 $count = count( $capabilities ); |
397 |
390 |
398 // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array. |
391 // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array. |
540 * Examples of URLs that are considered unsafe: |
533 * Examples of URLs that are considered unsafe: |
541 * |
534 * |
542 * - ftp://example.com/caniload.php - Invalid protocol - only http and https are allowed. |
535 * - ftp://example.com/caniload.php - Invalid protocol - only http and https are allowed. |
543 * - http:///example.com/caniload.php - Malformed URL. |
536 * - http:///example.com/caniload.php - Malformed URL. |
544 * - http://user:pass@example.com/caniload.php - Login information. |
537 * - http://user:pass@example.com/caniload.php - Login information. |
545 * - http://exampleeeee.com/caniload.php - Invalid hostname, as the IP cannot be looked up in DNS. |
538 * - http://example.invalid/caniload.php - Invalid hostname, as the IP cannot be looked up in DNS. |
546 * |
539 * |
547 * Examples of URLs that are considered unsafe by default: |
540 * Examples of URLs that are considered unsafe by default: |
548 * |
541 * |
549 * - http://192.168.0.1/caniload.php - IPs from LAN networks. |
542 * - http://192.168.0.1/caniload.php - IPs from LAN networks. |
550 * This can be changed with the {@see 'http_request_host_is_external'} filter. |
543 * This can be changed with the {@see 'http_request_host_is_external'} filter. |
697 |
690 |
698 /** |
691 /** |
699 * A wrapper for PHP's parse_url() function that handles consistency in the return values |
692 * A wrapper for PHP's parse_url() function that handles consistency in the return values |
700 * across PHP versions. |
693 * across PHP versions. |
701 * |
694 * |
702 * PHP 5.4.7 expanded parse_url()'s ability to handle non-absolute URLs, including |
695 * Across various PHP versions, schemeless URLs containing a ":" in the query |
703 * schemeless and relative URLs with "://" in the path. This function works around |
696 * are being handled inconsistently. This function works around those differences. |
704 * those limitations providing a standard output on PHP 5.2~5.4+. |
|
705 * |
|
706 * Secondly, across various PHP versions, schemeless URLs containing a ":" in the query |
|
707 * are being handled inconsistently. This function works around those differences as well. |
|
708 * |
697 * |
709 * @since 4.4.0 |
698 * @since 4.4.0 |
710 * @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`. |
699 * @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`. |
711 * |
700 * |
712 * @link https://www.php.net/manual/en/function.parse-url.php |
701 * @link https://www.php.net/manual/en/function.parse-url.php |