Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#61189 closed defect (bug) (fixed)

REST API: Attachments are not uploaded to the post's year/month folder

Reported by: swissspidy's profile swissspidy Owned by: swissspidy's profile swissspidy
Milestone: 6.6 Priority: normal
Severity: normal Version: 4.7
Component: Media Keywords: has-patch has-unit-tests
Focuses: rest-api Cc:

Description

If you upload an image to an existing post through the old media library modal, the image will be stored in the wp-content/uploads/<year>/<month> based on the post's publish date. For example, now is May, but if I upload it to a post from January, the image will be in wp-content/uploads/2024/01.

However, when uploading an image via the REST API (for example via drag & drop in the block editor), this is not the case, even though this comment on #40343 says otherwise.

So for consistency reasons, WP_REST_Attachments_Controller should be updated to match the media modal behavior (which can be found in media_handle_upload().

Props @patricia70 for helping me discover this.

Change History (5)

#2 @adamsilverstein
7 months ago

Good catch. PR looks good, thanks for including the tests.

@TimothyBlynJacobs commented on PR #6538:


7 months ago
#3

nice fix!

#4 @swissspidy
7 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58130:

REST API: Ensure attachments are uploaded to the post's year/month folder.

If organizing uploads into month- and year-based folders, uploading an attachment to an existing post should store the file in wp-content/uploads/<year>/<month> based on the post's publish date. This is in line with the behavior in classic editor / the media modal.

Props swissspidy, adamsilverstein, timothyblynjacobs, skithund, sergeybiryukov, patricia70.
Fixes #61189.

Note: See TracTickets for help on using tickets.