X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/98a4d31e52bd56c908617df281730bd4ba58d110..58f607a1de715c9bca69340a4d6fb9e1b9c2bed2:/wp-admin/includes/plugin-install.php diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index f81ecc82..f348e609 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -24,27 +24,30 @@ * * @param string $action * @param array|object $args Optional. Arguments to serialize for the Plugin Info API. - * @return mixed + * @return object plugins_api response object on success, WP_Error on failure. */ function plugins_api($action, $args = null) { - if( is_array($args) ) + if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) $args->per_page = 24; - $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter. - $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API. + // Allows a plugin to override the WordPress.org API entirely. + // Use the filter 'plugins_api_result' to mearly add results. + // Please ensure that a object is returned from the following filters. + $args = apply_filters('plugins_api_args', $args, $action); + $res = apply_filters('plugins_api', false, $action, $args); - if ( ! $res ) { - $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); + if ( false === $res ) { + $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) ); if ( is_wp_error($request) ) { - $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.
Try again'), $request->get_error_message() ); + $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() ); } else { $res = unserialize($request['body']); - if ( ! $res ) - $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']); + if ( false === $res ) + $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), $request['body']); } } elseif ( !is_wp_error($res) ) { $res->external = true; @@ -136,16 +139,20 @@ function install_dashboard() { $api_tags = install_popular_tags(); - //Set up the tags in a way which can be interprated by wp_generate_tag_cloud() - $tags = array(); - foreach ( (array)$api_tags as $tag ) - $tags[ $tag['name'] ] = (object) array( - 'link' => esc_url( admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ), - 'name' => $tag['name'], - 'id' => sanitize_title_with_dashes($tag['name']), - 'count' => $tag['count'] ); echo '