=== Media Size Cleanup ===
Contributors: quintaphon
Donate link: https://buymeacoffee.com/quintaphon
Tags: image sizes, thumbnails, media cleanup, regenerate thumbnails, unused images
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.2
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Remove image size files your site no longer uses, rebuild the sizes you keep, and find orphan upload files. Scan first, restore any time.

== Description ==

WordPress copies every uploaded image into each registered size. Switch themes, change the sizes under Settings > Media or remove a plugin, and the old copies stay on disk forever. On a site with a few thousand images that is often gigabytes of files nobody uses.

Media Size Cleanup finds those files and removes them safely.

* **Pick the sizes to keep.** Every size WordPress, your theme and your plugins register is listed with its dimensions. Turn off the ones your theme does not use. Files of sizes nobody registers any more are always removed.
* **Rebuild with the current settings.** Kept sizes are created again with your current Settings > Media values, and files with old dimensions are replaced.
* **Leftover files.** Size files on disk (photo-300x200.jpg) that the image's data no longer lists are found too.
* **Rebuild missing sizes only.** Creates the kept sizes for images that lack them, without removing anything.
* **Orphan files.** Finds files in the year and month upload folders that no media item uses, usually left behind when a delete did not finish.

= Built to be safe =

* **Scan first.** A scan is a dry run. It shows every file it would remove, grouped by size, with a CSV download. The cleanup only starts after a scan with the same settings.
* **Backups and restore.** Files move to a backup folder in uploads, and each image's old data is saved with them. One click on Restore puts everything back.
* **Linked files stay.** Files linked in posts, pages, custom fields or settings are skipped, so images in old articles keep working.
* **Originals are never touched.** The uploaded file, the full-size original of a scaled image and image editor backups always stay.
* **Permanent deletion is your call.** Files are only deleted for good when you type DELETE.
* **Works on large sites.** The work runs in short batches, so it never hits a PHP time limit. Only one browser tab can drive a run.

The plugin adds a screen under Media > Size Cleanup for administrators. It adds nothing to the front end of your site, sends no data anywhere and loads no external files.

Plugin site: [quintaphon.com/wordpress/media-size-cleanup](https://quintaphon.com/wordpress/media-size-cleanup/)

== Installation ==

1. Install the plugin from Plugins > Add New, or upload the `media-size-cleanup` folder to `/wp-content/plugins/`.
2. Activate it.
3. Go to Media > Size Cleanup, open Image sizes and run a scan.

== Frequently Asked Questions ==

= Is a scan safe to run on a live site? =

Yes. A scan only reads. It changes no file and no database entry.

= How do I undo a cleanup? =

Open Media > Size Cleanup > Backups and click Restore next to the cleanup. The files go back to their folders and each image gets its old size data back.

= Where are the backups, and when should I delete them? =

In `wp-content/uploads/media-size-cleanup-backup/`. Check your site for a few days after a cleanup, then delete the backup under Backups to free the space.

= What happens to the backups when I delete the plugin? =

They stay, because they hold your files. Delete them under Backups first, or remove the folder above yourself. Deleting the plugin removes only its saved settings and run data.

= Will images in my posts break? =

Not with "Skip files linked in your content" on, which is the default. Any file linked in post content, excerpts, custom fields or settings is kept, even when its size is removed.

= Does it work with WebP and AVIF? =

Yes. WebP and AVIF versions that WordPress or an image plugin records in the image data count as used, and so do files named like photo.jpg.webp next to photo.jpg.

= Does it work with images on a CDN or offloaded to cloud storage? =

It works on the files in your uploads folder. Images that live only on remote storage are not changed.

= How long does a cleanup take? =

A scan is quick. A cleanup with rebuild on takes about as long as regenerating thumbnails, because every image is resized again. Keep the tab open while it runs; you can stop it at any time.

== Screenshots ==

1. Overview: images, sizes, the last run and the space held in backups.
2. Image sizes: pick the sizes to keep and the cleanup options.
3. Scan result: what would be removed, per size, with a CSV download.
4. Orphan files found in the upload folders.
5. Backups with Restore and Delete.

== Changelog ==

= 1.2.0 =
* New admin screen under Media > Size Cleanup with Overview, Image sizes, Orphan files and Backups.
* The cleanup button turns on only after a scan with the same settings, also after a page reload.
* The page remembers the sizes and options of the last run and shows its result.
* Plugin dialogs for every confirmation; deleting for good needs DELETE typed in the dialog.
* Stop button and a warning before leaving the page while a run is going.
* When a rebuild fails, the image keeps all its size files.
* A restore that can not put every file back keeps the backup.
* Backups get a random part in their name and their file lists can not be opened from the web.
* Files are moved with the WordPress file system API; scripts and styles are loaded the WordPress way.

= 1.1.0 =
* Orphan files: find files in the year and month upload folders that no media item uses, and move them to a backup.

= 1.0.2 =
* Rebuild missing sizes only.
* A size the rebuild can not create keeps its old file.
* Only the browser tab that started a run can drive it.

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.2.0 =
New admin screen under Media > Size Cleanup. Backups made with earlier versions are listed and can still be restored.
