wp_get_http

The timeline below displays how wordpress function wp_get_http has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 * @deprecated 4.4.0 Use WP_Http
 * @see WP_Http
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
 *                               returns false. Default 1.
 * @return \WpOrg\Requests\Utility\CaseInsensitiveDictionary|false Headers on success, false on failure.
 */
function wp_get_http($url, $file_path = false, $red = 1)
{
    _deprecated_function(__FUNCTION__, '4.4.0', 'WP_Http');
    if (function_exists('set_time_limit')) {
        @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;
}

WordPress Version: 6.1

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 * @deprecated 4.4.0 Use WP_Http
 * @see WP_Http
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       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.
 */
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;
}

WordPress Version: 5.4

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 * @deprecated 4.4.0 Use WP_Http
 * @see WP_Http
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
 *                               returns false. Default 1.
 * @return bool|string False on failure and string of headers if HEAD request.
 */
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;
}

WordPress Version: 4.6

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 * @deprecated 4.4.0 Use WP_Http
 * @see WP_Http
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
 *                               returns false. Default 1.
 * @return bool|string False on failure and string of headers if HEAD request.
 */
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;
}

WordPress Version: 4.4

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 * @deprecated 4.4.0 Use WP_Http
 * @see WP_Http
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
 *                               returns false. Default 1.
 * @return bool|string False on failure and string of headers if HEAD request.
 */
function wp_get_http($url, $file_path = false, $red = 1)
{
    _deprecated_function(__FUNCTION__, '4.4', '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;
}

WordPress Version: 4.0

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 *
 * @param string      $url       URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to. Default false.
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
 *                               returns false. Default 1.
 * @return bool|string False on failure and string of headers if HEAD request.
 */
function wp_get_http($url, $file_path = false, $red = 1)
{
    @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;
}

WordPress Version: 3.7

/**
 * Perform a HTTP HEAD or GET request.
 *
 * If $file_path is a writable filename, this will do a GET request and write
 * the file to that path.
 *
 * @since 2.5.0
 *
 * @param string $url URL to fetch.
 * @param string|bool $file_path Optional. File path to write request to.
 * @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false.
 * @return bool|string False on failure and string of headers if HEAD request.
 */
function wp_get_http($url, $file_path = false, $red = 1)
{
    @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;
}