Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#28204 closed defect (bug) (fixed)

`media_sideload_image()` tries to unlink a WP_Error object.

Reported by: georgestephanis Owned by: wonderboymusic
Priority: low Milestone: 4.0
Component: Media Version: 2.7
Severity: minor Keywords: has-patch
Cc: Focuses:

Description

Traced back to: https://core.trac.wordpress.org/changeset/8959/trunk/wp-admin/includes/media.php by @noel

Long story short, the conditional block will only be entered if $tmp is a WP_Error object, then once in, it will try to unlink $file_array['tmp_name'] -- which was just set equal to $tmp and is therefore also a WP_Error object and not a file path, so unlink will always fail!

Also, instead of setting $file_array['tmp_name'] to an empty string and causing it to fail and pass back a WP_Error later, let's just pass back the WP_Error directly.

Attachments (1)

28204.diff​ (1.0 KB ) - added by georgestephanis 12 years ago.

Download all attachments as: .zip

Change History (4)

#2 @wonderboymusic
12 years ago

  • Milestone Awaiting Review → 4.0

#3 @wonderboymusic
12 years ago

  • Owner set to wonderboymusic
  • Resolution → fixed
  • Status new → closed

In 28567:

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.

Note: See TracTickets for help on using tickets.