Understand how source files are replaced

Image Optimizer replaces the attachment’s main file after successful processing, keeping the same filename and URL. It does not maintain a permanent “originals” archive that an administrator can restore later.

Protection during processing

The module processes a separate temporary copy and checks that the finished image can be fully decoded before replacing the source. A readable header or a non-zero file size alone is not sufficient. If compression, validation, or replacement fails, the source file remains unchanged.

Each source image and WebP companion is replaced atomically: visitors receive a complete file while processing runs. If the filesystem cannot perform the replacement, the module reports a failure and keeps the previous file. Temporary working files are removed when the attempt ends; they are not a recovery archive.

If the source succeeds but a later WebP conversion fails, the validated source remains optimized and its dimensions and file size stay accurate. An existing companion is kept until a valid replacement is ready. The attachment remains eligible for Optimize missing images so companion generation can be retried.

What a successful run changes

A successful run can:

  • resize the main image when its longest side exceeds 2560 pixels;
  • compress and overwrite the main file;
  • update stored width, height, file size, and savings information;
  • create WebP companions for the main file and generated sizes;
  • remove generated variants for that attachment that no longer belong to current metadata.

Optimize all images also clears the module’s completed marker before rebuilding the selected attachment metadata.

Prepare a recoverable test

  1. Copy the uploads directory and database to a restorable backup.
  2. Select images that represent transparency, large dimensions, photography, graphics, AVIF, GIF, and existing WebP.
  3. Record each original filename, dimensions, file size, and attachment URL.
  4. Optimize only the test set first.
  5. Compare visual quality at full size and every frontend crop.
  6. Keep the external backup until the production review is complete.

Recover an earlier original

Disabling the module cannot reverse a successful overwrite. Restore the required file from the pre-operation backup, then regenerate attachment sizes with an approved WordPress media workflow if necessary. Verify that attachment metadata and frontend URLs still describe the restored files.