Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the upload date in image metadata on back date posts #131

Merged
merged 1 commit into from
Jan 25, 2021

Conversation

colegeissinger
Copy link
Member

Description of the Change

We noticed when uploading an image directly to an older post (via Gutenberg or through Media buttons on TinyMCE), thumbnails weren't loading properly and appeared broken. It became apparent that WordPress will backdate images to a post whose post_date is in the last month or older. When the Azure plugin swooped in, this logic wasn't factored in when the metadata was being built and would incorrectly set it for the current month. This resulted in images appearing broken as they would link to the wrong folder date.

E.g. uploading an image to November 2020, WordPress would place the image in /uploads/2020/11/ however the Azure plugin would store metadata to /uploads/2021/01/ if that was the current month and year.

This PR corrects that by ensuring we leverage wp_upload_dir() ability to change the directory in the uploads based on if we are uploading to a post and matching the date of the post. This mirrors the logic performed in wp-admin/includes/media.php:294-299

Alternate Designs

Benefits

Possible Drawbacks

Verification Process

Ran tests with various posts published, drafts, old posts and brand new posts, large and small images, tested that also all image sizes are being generated as expected. Tested image uploading directly in the Media Library and pages which will always default to the current date. Tested image uploading to custom post types. Lastly, tested in single and multisite installs.

All resulted in successfully uploaded images with the correct upload date that matches the post date or current date if Media Library or page post type.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

These appear to be relevant issues to this fix
#122
#126

Changelog Entry

@colegeissinger colegeissinger self-assigned this Jan 20, 2021
@rickalee
Copy link
Collaborator

Confirmed on my end in multiple methods of upload. We noticed that this is also for uploads in the Media modal within a post however WP core does not backdate for Image Blocks that a user drags/drops image into.

Approved for release.

@lostfields
Copy link

Looks like the issue I'm experience when I uploads image through featured image when editing older post. Any chance to get this confirmed and merged @jeffpaul ?

@jeffpaul jeffpaul added this to the 4.3.2 milestone Jan 25, 2021
@jeffpaul jeffpaul merged commit 249afec into develop Jan 25, 2021
@jeffpaul jeffpaul deleted the hotfix/upload-path-month-date branch March 3, 2021 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants