WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 19 months ago

#16777 closed defect (bug) (fixed)

media_sideload_image() doesn't upload in past "/year/month/" folders

Reported by: Coolkevman Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.1
Component: Upload Keywords: has-patch 3.5-early
Focuses: Cc:

Description

When using the media_sideload_image() method to upload a remote image, you can specify as a second parameter the ID of post to which this image belongs.

The upload process works great and the new uploaded image is well attached to the post we specify.

Now if the post is already published in the past (say April 1st, 2009), the image is uploaded to the /wp-content/uploads/2011/03/ folder (which is the current month and the current year). The problem is that we expect the image to be uploaded to /wp-content/uploads/2009/04/ instead.

I expect media_sideload_image() to use the post's publishing month and year as this is the default behavior when you use the administration interface to upload content in an already published post.

This was consistently reproduced on the latest WordPress 3.1 (and its RCs).

Attachments (1)

16777.diff (2.7 KB) - added by solarissmoke 3 years ago.

Download all attachments as: .zip

Change History (6)

solarissmoke3 years ago

comment:1 solarissmoke3 years ago

  • Keywords has-patch added

Patch makes wp_handle_sideload() consistent with wp_handle_upload(), using post_date to determine the upload folder.

comment:3 Otto4222 months ago

  • Keywords 3.5-early added

Dunno if we're tagging 3.5-early or not yet, but let's get this in.

comment:4 SergeyBiryukov22 months ago

  • Milestone changed from Awaiting Review to 3.5

comment:5 nacin19 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [22105]:

Pass the post date to wp_upload_dir() during sideloads, just as we do uploads. Ensures that sideloaded images make it into the right uploads directory.

props solarisssmoke, fixes #16777.

Note: See TracTickets for help on using tickets.