Make WordPress Core


Ignore:
Timestamp:
03/27/2008 07:36:30 AM (17 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

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.