Keep date folder when optimizing existing media
This was reported by @PatriciaBT, but I actually cannot reproduce the issue. The date folder is already kept.
What I did:
- Deactivate Media Experiments
- Upload an image to a blog post from January 2024
- The image was stored in
wp-content/uploads/2024/01 - Activate Media Experiments
- Edit the blog post, optimize the existing image
- The optimized image is also stored in
wp-content/uploads/2024/01
Proof:
Aside: the file names are incorrect, I'll fix that separately.
Thank you @swissspidy When I add a file to a post from another month, it goes anyway in the current month, so it is indeed probably unrelated to the plugin. Also on your above image, it's month May (5) right?
Ah, you're right! My bad 🤦
So I just looked into this more closely...
When I add a file to a post from another month, it goes anyway in the current month, so it is indeed probably unrelated to the plugin.
I think this is a bug in WordPress.
If I insert an image block in an old post from January, click on "Media Library" and upload an image in the popup there, the file is going to the January folder.
(This is handled by media_handle_upload() and only works for post types other than page.
However, if I drag & drop an image into the editor, the file actually goes to the current month (May).
So this is inconsistent. I'll see how/where we can fix that in WordPress.
There is also another use case:
- Upload an image to a blog post from January, the image is stored in
2024/01. - Create a new post in February and insert the existing January image
- Optimize the image
- Should it now be uploaded in
2024/01(which is the date of the post) or in2024/01(the date of the original image)?
I just opened https://core.trac.wordpress.org/ticket/61189 / https://github.com/WordPress/wordpress-develop/pull/6538 to fix this in core.