Make WordPress Core

Changeset 12742


Ignore:
Timestamp:
01/17/2010 03:26:50 AM (17 years ago)
Author:
dd32
Message:

Add extra error checking to the Plugin Browser and Plugin API function. Fixes #11640

File:
1 edited

Legend:

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

    r12673 r12742  
    2525 * @param string $action
    2626 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
    27  * @return mixed
     27 * @return object plugins_api response object on success, WP_Error on failure.
    2828 */
    2929function plugins_api($action, $args = null) {
    … …  
    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.
    39 
    40         if ( ! $res ) {
    41                 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
     37        // Allows a plugin to override the WordPress.org API entirely.
     38        // Use the filter 'plugins_api_result' to mearly add results.
     39        // Please ensure that a object is returned from the following filters.
     40        $args = apply_filters('plugins_api_args', $args, $action);
     41        $res = apply_filters('plugins_api', false, $action, $args);
     42
     43        if ( false === $res ) {
     44                $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) );
    4245                if ( is_wp_error($request) ) {
    4346                        $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() );
    4447                } else {
    4548                        $res = unserialize($request['body']);
    46                         if ( ! $res )
     49                        if ( false === $res )
    4750                                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
    4851                }
    … …  
    198201        $args = array('browse' => 'popular', 'page' => $page);
    199202        $api = plugins_api('query_plugins', $args);
     203        if ( is_wp_error($api) )
     204                wp_die($api);
    200205        display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
    201206}
    … …  
    249254        $args = array('browse' => 'updated', 'page' => $page);
    250255        $api = plugins_api('query_plugins', $args);
     256        if ( is_wp_error($api) )
     257                wp_die($api);
    251258        display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
    252259}
Note: See TracChangeset for help on using the changeset viewer.