mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
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
git-svn-id: https://develop.svn.wordpress.org/trunk@7547 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -192,25 +192,30 @@ function wp_handle_upload( &$file, $overrides = false ) {
|
||||
* Downloads a url to a local file using the Snoopy HTTP Class
|
||||
*
|
||||
* @param string $url the URL of the file to download
|
||||
* @return mixed false on failure, string Filename on success.
|
||||
* @return mixed WP_Error on failure, string Filename on success.
|
||||
*/
|
||||
function download_url( $url ) {
|
||||
//WARNING: The file is not automatically deleted, The script must unlink() the file.
|
||||
if( ! $url )
|
||||
return false;
|
||||
return new WP_Error('http_no_url', __('Invalid URL Provided'));
|
||||
|
||||
$tmpfname = tempnam(get_temp_dir(), 'wpupdate');
|
||||
if( ! $tmpfname )
|
||||
return false;
|
||||
return new WP_Error('http_no_file', __('Could not create Temporary file'));
|
||||
|
||||
$handle = @fopen($tmpfname, 'w');
|
||||
if( ! $handle )
|
||||
return false;
|
||||
return new WP_Error('http_no_file', __('Could not create Temporary file'));
|
||||
|
||||
require_once( ABSPATH . 'wp-includes/class-snoopy.php' );
|
||||
$snoopy = new Snoopy();
|
||||
$snoopy->fetch($url);
|
||||
|
||||
if( $snoopy->status != '200' ){
|
||||
fclose($handle);
|
||||
unlink($tmpfname);
|
||||
return new WP_Error('http_404', trim($snoopy->response_code));
|
||||
}
|
||||
fwrite($handle, $snoopy->results);
|
||||
fclose($handle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user