WordPress.org

Make WordPress Core

Ticket #11640: 11640.patch

File 11640.patch, 2.8 KB (added by hakre, 4 years ago)
  • wp-admin/includes/plugin-install.php

     
    2424 * 
    2525 * @param string $action 
    2626 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API. 
    27  * @return mixed 
     27 * @return mixed plugins_api response object, WP_Error on error, mixed values   
    2828 */ 
    2929function plugins_api($action, $args = null) { 
    3030 
     
    3434        if ( !isset($args->per_page) ) 
    3535                $args->per_page = 24; 
    3636 
    37         $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter. 
    38         $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API. 
     37        $args = apply_filters('plugins_api_args', $args, $action);   //NOTE: Ensure that an object is returned via this filter. 
     38        $res  = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API. 
    3939 
    40         if ( ! $res ) { 
    41                 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); 
     40        if ( false === $res ) { 
     41                $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) ); 
    4242                if ( is_wp_error($request) ) { 
    4343                        $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message() ); 
    44                 } else { 
    45                         $res = unserialize($request['body']); 
    46                         if ( ! $res ) 
    47                                 $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']); 
     44                } elseif ( false === ( $res = unserialize( $request['body'] ) ) ) { 
     45                        $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']); 
    4846                } 
    49         } elseif ( !is_wp_error($res) ) { 
     47        } elseif ( !is_wp_error( $res ) ) { 
     48                $res = (object) $res; 
    5049                $res->external = true; 
    5150        } 
    5251 
     
    197196function install_popular($page = 1) { 
    198197        $args = array('browse' => 'popular', 'page' => $page); 
    199198        $api = plugins_api('query_plugins', $args); 
     199        if ( is_wp_error($api) ) 
     200                wp_die($api); 
    200201        display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); 
    201202} 
    202203 
     
    248249function install_updated($page = 1) { 
    249250        $args = array('browse' => 'updated', 'page' => $page); 
    250251        $api = plugins_api('query_plugins', $args); 
     252        if ( is_wp_error($api) ) 
     253                wp_die($api); 
    251254        display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); 
    252255} 
    253256