On this page
wp_get_http( string $url, string|bool $file_path = false, int $red = 1 ): Requests_Utility_CaseInsensitiveDictionary|false
This function has been deprecated. Use WP_Http() instead.
Perform a HTTP HEAD or GET request.
Description
If $file_path is a writable filename, this will do a GET request and write the file to that path.
See also
Parameters
$urlstring Required-
URL to fetch.
$file_pathstring|bool Optional-
File path to write request to.
Default:
false $redint Optional-
The number of Redirects followed, Upon 5 being hit, returns false.
Default:
1
Return
Requests_Utility_CaseInsensitiveDictionary|false Headers on success, false on failure.
Source
File: wp-includes/deprecated.php. View all references
function wp_get_http( $url, $file_path = false, $red = 1 ) {
_deprecated_function( __FUNCTION__, '4.4.0', 'WP_Http' );
@set_time_limit( 60 );
if ( $red > 5 )
return false;
$options = array();
$options['redirection'] = 5;
if ( false == $file_path )
$options['method'] = 'HEAD';
else
$options['method'] = 'GET';
$response = wp_safe_remote_request( $url, $options );
if ( is_wp_error( $response ) )
return false;
$headers = wp_remote_retrieve_headers( $response );
$headers['response'] = wp_remote_retrieve_response_code( $response );
// WP_HTTP no longer follows redirects for HEAD requests.
if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
return wp_get_http( $headers['location'], $file_path, ++$red );
}
if ( false == $file_path )
return $headers;
// GET request - write it to the supplied filename.
$out_fp = fopen($file_path, 'w');
if ( !$out_fp )
return $headers;
fwrite( $out_fp, wp_remote_retrieve_body( $response ) );
fclose($out_fp);
clearstatcache();
return $headers;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_get_http() wp-includes/deprecated.php | Perform a HTTP HEAD or GET request. |
| wp_safe_remote_request() wp-includes/http.php | Retrieve the raw response from a safe HTTP request. |
| wp_remote_retrieve_headers() wp-includes/http.php | Retrieve only the headers from the raw response. |
| wp_remote_retrieve_response_code() wp-includes/http.php | Retrieve only the response code from the raw response. |
| wp_remote_retrieve_body() wp-includes/http.php | Retrieve only the body from the raw response. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| wp_get_http() wp-includes/deprecated.php | Perform a HTTP HEAD or GET request. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_http