Make WordPress Core

Opened 4 years ago

Last modified 2 weeks ago

#46554 assigned defect (bug)

Uploaded images goes to wrong folder/date structure

Reported by: kartiks16's profile kartiks16 Owned by: antpb's profile antpb
Milestone: 6.3 Priority: normal
Severity: normal Version: 5.1
Component: Media Keywords: 2nd-opinion needs-patch
Focuses: Cc:

Description

Hello Team

All test are from fresh install, default theme, no settings change, no plugin…
"Organize my uploads into month- and year-based folders” option checked.

Images upload date: 17/03/2019
Single “Test Page” published date: 27/11/2018

In WordPress 4.7 – 4.7.13 – 4.8 – 4.8.9:

images uploaded from Media Library goes to …/2019/03 folder… RIGHT
images uploaded from single “Test Page” goes to …/2018/11 folder… RIGHT

In WordPress 4.9 – 4.9.10 – 5.0.4 – 5.1.1:

images uploaded from Media Library goes to …/2019/03 folder… RIGHT
images uploaded from single “Test Page” goes to …/2019/03 folder… WRONG!!!

From 4.9 version has anything changed in the way WordPress handles image uploads?
If YES, how to go back to the old way (thus images uploaded from single “Test Page” goes to “published date” folder… and not to “upload date” folder)?

Thanks!

Change History (10)

#1 @swissspidy
4 years ago

  • Keywords close added; needs-testing needs-patch removed

This was a deliberate change made in 4.9, see #10752. Citing the commit message:

When media is uploaded to a post, the upload directory is set according to the date of the post, so that the media URLs in the post match when the post was published.

A page is a slightly different beast, pages often live for years, and are regularly updated to stay relevant. This change causes media uploaded to pages to use the upload date to determine the upload directory.

I don't know if there's an easy way to change the folder structure for uploads. What's your use case for that? Why is the changed structure a problem?

#2 @kartiks16
4 years ago

  • Keywords needs-patch added; close removed

Hello @swissspidy

Thank you for replying and sharing your thoughts.

I understand in most of the cases maybe it won't impact much.

But what if someone manages a photographer’s site with thousands of photos and it is necessary to link the photos with the individual pages as a matter of order.

Do you think there is any workaround for this?

Waiting for your reply,

Thanks.

#3 @maximo71
4 years ago

Hello @swissspidy

First sorry for my english.

For my test in 4.9 to 5.1.1 version this is not true.
Also images uploaded to a previously published Post (as well as to a Media Library and to a Pages) use the upload date to determine the upload directory and not the date of the post.

Thanks.

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


7 months ago

#5 @antpb
7 months ago

  • Milestone changed from Awaiting Review to 6.2

Moving this into 6.2 for investigation. This seems fit for a filter to allow customization of the structure.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


4 months ago

#7 @antpb
4 months ago

A bit late in the 6.2 cycle to confidently deliver this change, so this should be moved to 6.3 when possible.

#8 @sabernhardt
4 months ago

  • Milestone changed from 6.2 to 6.3

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


2 weeks ago

#10 @antpb
2 weeks ago

  • Owner set to antpb
  • Status changed from new to assigned

Talking with @joedolson in the recent Media meeting he mentioned that we could add a filter to $time in _wp_handle_upload and pass the $post object as an argument. That should allow the previous behavior to be achieved.

Note: See TracTickets for help on using tickets.