WordPress.org

Make WordPress Core

Changeset 17928


Ignore:
Timestamp:
05/14/2011 07:45:07 PM (9 years ago)
Author:
nacin
Message:

Use wp_remote_retrieve_* helper functions instead of the raw HTTP response array. props aaroncampbell, fixes #17416.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r17895 r17928  
    12091209        );
    12101210
    1211         $raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
    1212 
    1213         if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] )
    1214             return;
     1211        $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
     1212
     1213        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     1214            return false;
    12151215
    12161216        /**
     
    12251225         *  'img_src_ssl' - string - An image (over SSL) representing the browser
    12261226         */
    1227         $response = unserialize( $raw_response['body'] );
     1227        $response = unserialize( wp_remote_retrieve_body( $response ) );
    12281228
    12291229        if ( ! $response )
  • trunk/wp-admin/includes/file.php

    r17749 r17928  
    491491    }
    492492
    493     if ( $response['response']['code'] != '200' ){
     493    if ( 200 != wp_remote_retrieve_response_code( $response ) ){
    494494        unlink( $tmpfname );
    495         return new WP_Error( 'http_404', trim( $response['response']['message'] ) );
     495        return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
    496496    }
    497497
  • trunk/wp-admin/includes/plugin-install.php

    r16469 r17928  
    4646            $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
    4747        } else {
    48             $res = unserialize($request['body']);
     48            $res = unserialize( wp_remote_retrieve_body( $request ) );
    4949            if ( false === $res )
    50                 $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), $request['body']);
     50                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
    5151        }
    5252    } elseif ( !is_wp_error($res) ) {
     
    368368}
    369369add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
    370 
  • trunk/wp-admin/includes/schema.php

    r17831 r17928  
    763763        if ( is_wp_error( $page ) )
    764764            $errstr = $page->get_error_message();
    765         elseif ( 200 == $page['response']['code'] )
     765        elseif ( 200 == wp_remote_retrieve_response_code( $page ) )
    766766                $vhost_ok = true;
    767767
  • trunk/wp-admin/includes/theme.php

    r17633 r17928  
    397397            $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
    398398        } else {
    399             $res = unserialize($request['body']);
     399            $res = unserialize( wp_remote_retrieve_body( $request ) );
    400400            if ( ! $res )
    401             $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), $request['body']);
     401            $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
    402402        }
    403403    }
  • trunk/wp-includes/class-feed.php

    r17771 r17928  
    8181                $this->success = false;
    8282            } else {
    83                 $this->headers = $res['headers'];
    84                 $this->body = $res['body'];
    85                 $this->status_code = $res['response']['code'];
     83                $this->headers = wp_remote_retrieve_headers( $res );
     84                $this->body = wp_remote_retrieve_body( $res );
     85                $this->status_code = wp_remote_retrieve_response_code( $res );
    8686            }
    8787        } else {
  • trunk/wp-includes/class-wp-http-ixr-client.php

    r17811 r17928  
    6565        }
    6666
    67         if ( $response['response']['code'] != 200 ) {
    68             $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
     67        if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
     68            $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
    6969            return false;
    7070        }
    7171
    7272        if ( $this->debug )
    73             echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
     73            echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
    7474
    7575        // Now parse what we've got back
    76         $this->message = new IXR_Message( $response['body'] );
     76        $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
    7777        if ( ! $this->message->parse() ) {
    7878            // XML error
  • trunk/wp-includes/comment.php

    r17795 r17928  
    16201620        return false;
    16211621
    1622     if ( isset( $response['headers']['x-pingback'] ) )
    1623         return $response['headers']['x-pingback'];
     1622    if ( wp_remote_retrieve_header( $response, 'x-pingback' ) )
     1623        return wp_remote_retrieve_header( $response, 'x-pingback' );
    16241624
    16251625    // Not an (x)html, sgml, or xml page, no use going further.
    1626     if ( isset( $response['headers']['content-type'] ) && preg_match('#(image|audio|video|model)/#is', $response['headers']['content-type']) )
     1626    if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )
    16271627        return false;
    16281628
     
    16331633        return false;
    16341634
    1635     $contents = $response['body'];
     1635    $contents = wp_remote_retrieve_body( $response );
    16361636
    16371637    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
  • trunk/wp-includes/functions.php

    r17841 r17928  
    601601    wp_protect_special_option( $option );
    602602
    603     /* 
     603    /*
    604604     * FIXME the next two lines of code are not necessary and should be removed.
    605605     * @see http://core.trac.wordpress.org/ticket/13480
     
    13061306
    13071307    $headers = wp_remote_retrieve_headers( $response );
    1308     $headers['response'] = $response['response']['code'];
     1308    $headers['response'] = wp_remote_retrieve_response_code( $response );
    13091309
    13101310    // WP_HTTP no longer follows redirects for HEAD requests.
     
    13211321        return $headers;
    13221322
    1323     fwrite( $out_fp,  $response['body']);
     1323    fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
    13241324    fclose($out_fp);
    13251325    clearstatcache();
     
    15571557        return false;
    15581558
    1559     return $response['body'];
     1559    return wp_remote_retrieve_body( $response );
    15601560}
    15611561
     
    28772877 * @param string|array $args Optional arguements to control behaviour.
    28782878 */
    2879 function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) { 
     2879function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
    28802880    global $wp_xmlrpc_server;
    28812881    $defaults = array( 'response' => 500 );
     
    28832883    $r = wp_parse_args($args, $defaults);
    28842884
    2885     if ( $wp_xmlrpc_server ) { 
    2886         $error = new IXR_Error( $r['response'] , $message); 
    2887         $wp_xmlrpc_server->output( $error->getXml() ); 
     2885    if ( $wp_xmlrpc_server ) {
     2886        $error = new IXR_Error( $r['response'] , $message);
     2887        $wp_xmlrpc_server->output( $error->getXml() );
    28882888    }
    28892889    die();
     
    28922892/**
    28932893 * Filter to enable special wp_die handler for xmlrpc requests.
    2894  * 
     2894 *
    28952895 * @since 3.2.0
    28962896 * @access private
    28972897 */
    2898 function _xmlrpc_wp_die_filter() { 
     2898function _xmlrpc_wp_die_filter() {
    28992899    return '_xmlrpc_wp_die_handler';
    29002900}
  • trunk/wp-includes/rss.php

    r17071 r17928  
    556556    // Also note, WP_HTTP lowercases all keys, Snoopy did not.
    557557    $return_headers = array();
    558     foreach ( $resp['headers'] as $key => $value ) {
     558    foreach ( wp_remote_retrieve_headers( $resp ) as $key => $value ) {
    559559        if ( !is_array($value) ) {
    560560            $return_headers[] = "$key: $value";
     
    566566
    567567    $response = new stdClass;
    568     $response->status = $resp['response']['code'];
    569     $response->response_code = $resp['response']['code'];
     568    $response->status = wp_remote_retrieve_response_code( $resp );
     569    $response->response_code = wp_remote_retrieve_response_code( $resp );
    570570    $response->headers = $return_headers;
    571     $response->results = $resp['body'];
     571    $response->results = wp_remote_retrieve_body( $resp );
    572572
    573573    return $response;
  • trunk/wp-includes/update.php

    r17619 r17928  
    7272    $response = wp_remote_get($url, $options);
    7373
    74     if ( is_wp_error( $response ) )
    75         return false;
    76 
    77     if ( 200 != $response['response']['code'] )
    78         return false;
    79 
    80     $body = trim( $response['body'] );
     74    if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     75        return false;
     76
     77    $body = trim( wp_remote_retrieve_body( $response ) );
    8178    $body = str_replace(array("\r\n", "\r"), "\n", $body);
    8279    $new_options = array();
     
    176173    $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
    177174
    178     if ( is_wp_error( $raw_response ) )
    179         return false;
    180 
    181     if ( 200 != $raw_response['response']['code'] )
    182         return false;
    183 
    184     $response = unserialize( $raw_response['body'] );
     175    if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
     176        return false;
     177
     178    $response = unserialize( wp_remote_retrieve_body( $raw_response ) );
    185179
    186180    if ( false !== $response )
     
    274268    $raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
    275269
    276     if ( is_wp_error( $raw_response ) )
    277         return false;
    278 
    279     if ( 200 != $raw_response['response']['code'] )
     270    if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
    280271        return false;
    281272
     
    284275    $new_update->checked = $checked;
    285276
    286     $response = unserialize( $raw_response['body'] );
     277    $response = unserialize( wp_remote_retrieve_body( $raw_response ) );
    287278    if ( false !== $response )
    288279        $new_update->response = $response;
Note: See TracChangeset for help on using the changeset viewer.