Skip to content

Restore and backup Image sizes with sources when an image is edited #228

@mitogh

Description

@mitogh

Description

  • When an image is edited make sure that existing images are stored in the _wp_attachment_backup_sizes meta before applying the changes into the image.
  • If the image is restored update _wp_attachment_backup_sizes array with the appropriate values.
  • At all times the value stored in the metadata of the image should reflect the same state as the images being edited.

When the constant IMAGE_EDIT_OVERWRITE is defined and is set to true edits on the file would be removed and only the previous edit would be stored in _wp_attachment_backup_sizes still allowing to rollback to the original image state, but subsequent edits would effectively remove any previous edit on the files.

Respect the constant IMAGE_EDIT_OVERWRITE

This behavior should follow the same principles for the primary image format in the secondary image format meaning that:

  • if IMAGE_EDIT_OVERWRITE is defined
    • if the value of the constant is true only the last copy of the secondary image would be kept in the filesystem and referenced in the database.
    • if the value of the constant is false multiple copies of the same edit would be kept in the filesystem and in the database in the same way it occurs with the primary image format.
  • If the constant is not defined, we should follow the same scenario as if the constant was defined as false

Restoring an image

When the original image is restored, the secondary image format would also be restored in the same way the process is applied to the primary image format. This restore would follow the rules from the constant definition IMAGE_EDIT_OVERWRITE to make sure files are removed or kept in place depending on the value of this constant.

Notes

  • In all scenarios, the values in _wp_attachment_backup_sizes should accurately reflect the file locations and properties of each edited image.
  • Image edits should include the suffix e-$id where $id is a 13 digit number specifically time() . rand( 100, 999 ) created by WP to reference any additional edit that is no longer relevant, the file name is important so WP can identify images that reference to edits and can be removed accordingly based on the definition and value of IMAGE_EDIT_OVERWRITE This suffix is also included as part of the image size name.
  • Last update or the restore point in _wp_attachment_backup_sizes uses the suffix -orig on the file name and image size in order to quickly identify which image is the last one edited or the one we need to restore. Reference

Related issues:

The work in this ticket is part of:

In order to keep things in a more manageable way.

Metadata

Metadata

Assignees

Labels

[Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions