In `media_sideload_image()`, check the returned value of `download_url()` earlier to avoid attempting to `unlink()` an instance of `WP_Error`.

Props georgestephanis. 
Fixes #28204.

Built from https://develop.svn.wordpress.org/trunk@28567


git-svn-id: http://core.svn.wordpress.org/trunk@28392 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-23 21:33:14 +00:00
parent 8bc84c0441
commit 8b7b72d75e
1 changed files with 12 additions and 15 deletions

View File

@ -802,19 +802,16 @@ function wp_media_upload_handler() {
*/ */
function media_sideload_image( $file, $post_id, $desc = null ) { function media_sideload_image( $file, $post_id, $desc = null ) {
if ( ! empty( $file ) ) { if ( ! empty( $file ) ) {
// Download file to temp location
$tmp = download_url( $file );
// Set variables for storage // Set variables for storage
// fix file filename for query strings // fix file filename for query strings
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
$file_array['name'] = basename( $matches[0] ); $file_array['name'] = basename( $matches[0] );
$file_array['tmp_name'] = $tmp; // Download file to temp location
$file_array['tmp_name'] = download_url( $file );
// If error storing temporarily, unlink // If error storing temporarily, return the error.
if ( is_wp_error( $tmp ) ) { if ( is_wp_error( $file_array['tmp_name'] ) ) {
@unlink($file_array['tmp_name']); return $file_array['tmp_name'];
$file_array['tmp_name'] = '';
} }
// do the validation and storage stuff // do the validation and storage stuff