Reverting Images

How to restore original images after processing.

Every image processed through Picture Optimizer can be reverted to its original state with one click. The revert system restores the original file, undoes all URL changes, and removes redirect rules.

How to Revert

  1. Go to Media Library in WordPress
  2. Find the processed image (it will show a "Processed" status)
  3. Click Revert to Original in the row actions

The plugin will restore the original image and confirm success.

What Gets Restored

File Restoration

  • The original file is copied back from the backup directory (image-forge-originals/)
  • The processed file and its thumbnails are deleted
  • WordPress regenerates thumbnails from the restored original
  • The attachment MIME type is restored if the format had changed

URL Reversal

  • All URL replacements made during processing are reversed — new URLs in post content, post meta, and options are changed back to the original URLs
  • The replacement map stored in _image_forge_url_replacements is used to perform the reverse search-and-replace

.htaccess Cleanup

  • The RedirectMatch 301 rule added during processing is removed from .htaccess
  • The redirect block is cleanly maintained — if all redirects are removed, the entire # BEGIN/END Picture Optimizer Redirects block is removed

GUID Restoration

  • The attachment guid column is updated back to the original URL

Action Hook

After revert, the plugin fires:

do_action( 'image_forge_after_revert', $attachment_id, $restored_url );

This allows CDN plugins or custom integrations to purge caches for the restored URL.

What Is Preserved

After reverting, the following data is kept for reference:

  • _image_forge_metadata — The AI-generated metadata remains stored (can be re-applied later)
  • _image_forge_status — Set to reverted to indicate the image was processed and then reverted

Re-Processing After Revert

A reverted image is treated as unprocessed by the smart skip system. If you select it for processing again, it will go through the full pipeline without being skipped.