WordPress.org

Make WordPress Core

Changeset 7547


Ignore:
Timestamp:
03/27/2008 07:36:30 AM (13 years ago)
Author:
ryan
Message:

Return WP_Error from download_url() on HTTP Errors. Fix cases where current plugin filename differs from the WordPress.org slug. Props DD32. see #5586

Location:
trunk/wp-admin/includes
Files:
2 edited

Legend:

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

    r7414 r7547  
    193193*
    194194* @param string $url the URL of the file to download
    195 * @return mixed false on failure, string Filename on success.
     195* @return mixed WP_Error on failure, string Filename on success.
    196196*/
    197197function download_url( $url ) {
    198198    //WARNING: The file is not automatically deleted, The script must unlink() the file.
    199199    if( ! $url )
    200         return false;
     200        return new WP_Error('http_no_url', __('Invalid URL Provided'));
    201201
    202202    $tmpfname = tempnam(get_temp_dir(), 'wpupdate');
    203203    if( ! $tmpfname )
    204         return false;
     204        return new WP_Error('http_no_file', __('Could not create Temporary file'));
    205205
    206206    $handle = @fopen($tmpfname, 'w');
    207207    if( ! $handle )
    208         return false;
     208        return new WP_Error('http_no_file', __('Could not create Temporary file'));
    209209
    210210    require_once( ABSPATH . 'wp-includes/class-snoopy.php' );
     
    212212    $snoopy->fetch($url);
    213213
     214    if( $snoopy->status != '200' ){
     215        fclose($handle);
     216        unlink($tmpfname);
     217        return new WP_Error('http_404', trim($snoopy->response_code));
     218    }
    214219    fwrite($handle, $snoopy->results);
    215220    fclose($handle);
  • trunk/wp-admin/includes/update.php

    r7465 r7547  
    177177    $file = download_url($package);
    178178
    179     if ( !$file )
    180         return new WP_Error('download_failed', __('Download failed.'));
     179    if ( is_wp_error($file) )
     180        return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
    181181
    182182    $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php');
     
    195195    }
    196196
    197     // Once installed, delete the package
     197    // Once extracted, delete the package
    198198    unlink($file);
    199199
    200200    if ( is_plugin_active($plugin) ) {
    201         //Deactivate the plugin
     201        //Deactivate the plugin silently, Prevent deactivation hooks from running.
    202202        apply_filters('update_feedback', __('Deactivating the plugin'));
    203203        deactivate_plugins($plugin, true);
     
    210210   
    211211    // If plugin is in its own directory, recursively delete the directory.
    212     if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' )
     212    if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
    213213        $deleted = $wp_filesystem->delete($plugin_dir, true);
    214214    else
     
    227227    }
    228228
     229    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     230    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     231
    229232    // Remove working directory
    230233    $wp_filesystem->delete($working_dir, true);
     
    233236    delete_option('update_plugins');
    234237   
    235     //Return the new plugin file.
    236     if ( ! preg_match('!/([a-z0-9\-]+)/?$!i', $working_dir, $mat) )
    237         return false;
    238     $plugin = get_plugins('/' . $mat[1]); //Pass it with a leading slash
    239     $list = array_keys($plugin);
    240     return $mat[1] . '/' . $list[0]; //Pass it without a leading slash.
     238    if( empty($filelist) )
     239        return false; //We couldnt find any files in the working dir
     240   
     241    $folder = $filelist[0];
     242    $plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder,
     243    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
     244
     245    return  $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
    241246}
    242247
Note: See TracChangeset for help on using the changeset viewer.