Deleting unused images - an unsolved problem

I have a 5 GB site, years old, and I know lots of the images in uploads are not used by any current pages or posts.

A 5 GB site is tough to backup.

There are the DNUI and Image Cleanup plugins, but 25-50% of the reviews are 1 star because the plugins deleted actual used images. Apparently it's a tough problem - unattached doesn't mean unused, and themes and plugins point to images on disk in a way that these plugins don't find when trawling the database.

Seems to be a common problem, too.

Opportunity for wpmudev?

  • Rupok

    Hi Greg, hope you had a wonderful day.

    "unattached doesn't mean unused, and themes and plugins point to images on disk in a way that these plugins don't find when trawling the database"
    Yeah, right. But the problem is, suppose you have uploaded an image on your server and then manually added that image in any template with <img> tag. This image is unattached, but used. Logo image is a good example of this.

    So, for a plugin, it's almost impossible to detect which images are being used and which are not. Suppose your site has 5000 pages and 5000 images. So your plugin has to check 5000 pages and that means this plugin has to dynamically generate 5000 pages for each image. Total query will be 25000000 requests which is insane. So I'm not sure what will be the best approach for doing this. What you can do is, take a full backup of your site (I know it's heavy but no other way actually) and then use any of the plugins you stated above. So if those plugins remove any of the images, you can upload those from your backup. I think number of wrongly deleted images will not be high.

    What do you suggest?

    Have a nice day. Cheers!
    Rupok

  • Greg

    Hi Rupok,

    Thanks for the reply. Good points.

    I'd say anybody pointing to resources in wp-content/uploads from wp-content/themes sort of gets what they deserve :slight_smile: That's a pretty bad structure.

    Also, checking the site manually after a backup and purge, as you suggest, would technically cause the same 25000000 requests - but take a lot longer since it was manual.

    Some people say they use a 404 checking service (eg. W3C) to make sure the site's not broken after an image purge... no reason a plugin couldn't build that functionality in.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.