Skip to content

Ensure edited image sources are backed up when restoring the original image #295

@felixarntz

Description

@felixarntz

Bug Description

Follow-up to #228: When editing an image in WordPress core (related: #158), the original image's sizes are backed up. This is primarily to restore them later. If then the original image is restored again or another round of edits to the same image is saved, the edited image's sizes get backed up. There is no way to restore these via the WordPress UI, but WordPress intentionally does not delete any edits at any point, and it keeps their metadata backups as well.

Our WebP uploads module does not behave in the same way with our _wp_attachment_backup_sources storage: When restoring the original image, the edited image data is not included in that backup anymore, while it is included in core's _wp_attachment_backup_sizes. Note that this problem only concerns the full size in any case, because all sub-size sources are included in WordPress's own storage by definition. But it is a bug we need to fix.

This is probably not critical because there's no way to restore them, but it's still a bug in the WebP uploads module based on how WordPress core works. We do keep the files around as expected, but we don't keep the meta data backup around, which makes it even more inconsistent even with our own approach.

Steps to reproduce

  1. Upload a JPEG image with the WebP Uploads module active. WebP versions are generated in addition to the JPEG versions.
  2. Edit the image through the WordPress UI (e.g. crop, rotate, anything). Then save.
  3. View the attachment's _wp_attachment_backup_sizes and _wp_attachment_backup_sources post meta values. Both have the necessary data stored, the first for all individual sizes (including sources for each size), the latter just the main sources, i.e. for the original image (under full-orig, for consistency with the backup sizes).
  4. Now restore the original.
  5. View the attachment's _wp_attachment_backup_sizes and _wp_attachment_backup_sources post meta values. You will now recognize that the previous edit's file paths etc are present in _wp_attachment_backup_sizes, but not in _wp_attachment_backup_sources - the latter still only has the full-orig data and is missing the hashed data with references to the previously edited image, which is the problem we need to fix here.

Metadata

Metadata

Assignees

Labels

[Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] BugAn existing feature is broken

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions