WordPress.org

Make WordPress Core

Ticket #8620: 8620.patch

File 8620.patch, 3.4 KB (added by hakre, 9 years ago)

Update against current trunk, DocBlocks extended to highlight WP_Error.

  • wp-includes/http.php

     
    19641964 * @since 2.7.0
    19651965 *
    19661966 * @param array $response HTTP response.
    1967  * @return array The headers of the response. Empty array if incorrect parameter given.
     1967 * @return array The headers of the response. Empty array if incorrect parameter (e.g. a WP_Error) given.
    19681968 */
    19691969function wp_remote_retrieve_headers(&$response) {
    1970         if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers']))
    1971                 return array();
    1972 
    1973         return $response['headers'];
     1970        $sanitzed = (array) $response; 
     1971        if ( isset($sanitzed['headers']) && is_array($sanitzed['headers']) )
     1972                return $sanitzed['headers'];   
     1973        return array();
    19741974}
    19751975
    19761976/**
     
    19801980 *
    19811981 * @param array $response
    19821982 * @param string $header Header name to retrieve value from.
    1983  * @return string The header value. Empty string on if incorrect parameter given, or if the header doesnt exist.
     1983 * @return string The header value. Empty string on if incorrect parameter given (e.g. a WP_Error), or if the header doesnt exist.
    19841984 */
    19851985function wp_remote_retrieve_header(&$response, $header) {
    1986         if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers']))
    1987                 return '';
    1988 
    1989         if ( array_key_exists($header, $response['headers']) )
    1990                 return $response['headers'][$header];
    1991 
    1992         return '';
     1986        $sanitzed = (array) $response;
     1987        return isset($sanitzed['headers'][$header]) ? $sanitzed['headers'][$header] : '';
    19931988}
    19941989
    19951990/**
     
    20001995 * @since 2.7.0
    20011996 *
    20021997 * @param array $response HTTP response.
    2003  * @return string the response code. Empty string on incorrect parameter given.
     1998 * @return string the response code. Empty string on incorrect parameter (e.g. a WP_Error) given.
    20041999 */
    20052000function wp_remote_retrieve_response_code(&$response) {
    2006         if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response']))
    2007                 return '';
    2008 
    2009         return $response['response']['code'];
     2001        $sanitzed = (array) $response;
     2002        return isset($sanitzed['response']['code']) ? $sanitzed['response']['code'] : '';
    20102003}
    20112004
    20122005/**
     
    20172010 * @since 2.7.0
    20182011 *
    20192012 * @param array $response HTTP response.
    2020  * @return string The response message. Empty string on incorrect parameter given.
     2013 * @return string The response message. Empty string on incorrect parameter (e.g. a WP_Error) given.
    20212014 */
    20222015function wp_remote_retrieve_response_message(&$response) {
    2023         if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response']))
    2024                 return '';
    2025 
    2026         return $response['response']['message'];
     2016        $sanitzed = (array) $response;
     2017        return isset($sanitzed['response']['message']) ? $sanitzed['response']['message'] : '';
    20272018}
    20282019
    20292020/**
     
    20322023 * @since 2.7.0
    20332024 *
    20342025 * @param array $response HTTP response.
    2035  * @return string The body of the response. Empty string if no body or incorrect parameter given.
     2026 * @return string The body of the response. Empty string if no body or incorrect parameter (e.g. a WP_Error) given.
    20362027 */
    20372028function wp_remote_retrieve_body(&$response) {
    2038         if ( is_wp_error($response) || ! isset($response['body']) )
    2039                 return '';
    2040 
    2041         return $response['body'];
     2029        $sanitzed = (array) $response;
     2030        return isset($sanitzed['body']) ? $sanitzed['body'] : '';
    20422031}
    20432032
    20442033?>