-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Today I was cleaning up a hosting account for a freelance client by backing up and deleting sites that they no longer use. My typical process for this is to create a zip of the site's final state (including a database export and uploads directory) and tucking it away for safe keeping for a period of time.
One site had a very large uploads directory because of a large number of registered image sizes. This meant a very large ZIP file. However, after removing the generated image sizes leaving only the original, the ZIP file backup was significantly smaller. If I ever need to spin up this site again for whatever reason, I can just restore the database and run wp media regenerate, and all of the image sizes would be present.
I used find . -name "*-*x*.*" | xargs rm -f to accomplish this (props here), but this could remove original files that happen to follow a -400x400. naming pattern. It would be great if there was a command that:
- Grabbed the list of registered image sizes.
- Looked at each attachment and removed any generated image that matches a registered image size.
- Deleted all of these matches from the uploads directory.
Abandoned image sizes (images generated and stored in attachment meta that no longer correspond to a registered image size) would need to remain because those cannot be regenerated, but still may be linked in content.
Almost a reverse regenerate-thumbnails command.