Meow Apps

Media Cleaner: Tutorial

Navigation Close

Media Cleaner is a very advanced tool and should be used by someone who understands the mechanics of WordPress very well. This is not a one-click cleanup kind of tool, and cannot be. Also, cleaning the database of temporary entries or old drafts is easy, but files always are potentially in use. Media Cleaner is a tool in your hand. Make sure you are in control of it.

Remember to backup your install (the database and the /uploads directory) before using this plugin. I recommend you to use your hosting service backup system if they have any, a staging website if you use WPEngine, or the very well-made BlogVault service.

The Dashboard

The Media Cleaner’s Dashboard is found under Media > Cleaner. Before doing anything here, you will need to decide your settings. However, it’s better to understand how the plugin works, and this dashboard is where the magic happens.

Media Cleaner for WordPress

How to use it

Here is how you should use the plugin, without going into the details of what the scan is really doing and how. Again, remember that you must prepare a backup before doing all this.

  1. Scan. Click Start Scan and then enjoy a coffee. The plugin will analyze your WordPress. Once it’s done, the results will be displayed. 
  2. Verify. There might be false-positive. For example, images used by the theme directly, such as logos, headers, etc. Look for them, and if they are part of those results, select them and click Ignore. They will never be deleted by the plugin.
  3. Delete or Ignore. You can search (= filter) through them. If you click Delete all after a search, only the results of this search will be deleted. You can also delete the entries one by one or by selecting a few of them. If there aren’t enough entries listed on each page for you, you can set this up differently in the settings. Remember that the files are being moved to the internal trash of the plugin, so they are still taking space in your install.
  4. Test and Repair (if needed). Browse your website thoroughly. If possible, let it be for a while, without adding new content. Is a file missing? Go back to the dashboard, click on Trash, find the entries, select them, and click Restore
  5. Free space. Has everything been fine for a little while? Click on Empty trash. The entries will be permanently deleted. Good job!

Different types of issues

  • Seems not use. The media entry (or file) has not been found in the content of your website.
  • No attached file. The media entry has no attached files. This media entry is broken.
  • Not in Library. The file doesn’t belong to any entry in your Media Library. It’s probably an orphaned file, such as a thumbnail used by a previous theme.
  • Orphan Retina or WebP. File which doesn’t have a master anymore. You can delete those your eyes closed.

Now that you know the process of Media Cleaner, let’s have a look at the settings.

The Settings

The settings are found under Meow Apps > Cleaner

Method

This is the most important setting. In the Free version, only the Media Library method is available. This will go through all the registered media and it will check if they are in use. The Filesystem method will go through all the files under your /uploads directory and will check if they are registered as a media and/or use somewhere else (check the Scanning settings to know more about this).

Scanning

  • Media. Only for the Filesystem method. This will check if the files are registered in a media, including all the sizes.
  • Posts. This is important as it checks the content of your posts (and any post types, such as pages, products, and so on): URLs, CSS classes using the IDs of the media, background images, src-set, and more.
  • Post Meta. This is where the Featured Image is stored, but not only! Many Page Builders are keeping their data there, gallery plugins as well.
  • Widgets. They sometimes contain images or even galleries.
  • Logs. This will create a file (reset at every scan) containing all the files detected in your install in the first section, then the result of the scan for every media or file in a second section.

Filters

Filters are applied during the scan. However, keep in mind that you can also search through the results of your scan using the search function in the dashboard. For example, you can type “/2020” in the search and results will be filtered by that directory.

Filters are only used with the Filesystem method. 

Directories Filter and Files Filter can restrict the scanning to specific folders and/or files depending on a regular expression (expressed between two slashes). If you don’t know how to write a regular expression, it might be interesting for you to learn. There are many tutorials online, and then you can test them on websites such as Regex101. Here are a few examples:

  • Directories Filter: /^$/ (only scan the root of your /uploads directory)
  • Directories Filter: /^2018/ (scan only the files from 2018)
  • Directories Filter: /^[0-9]{4}\/02/ (scan only the files in the February directories)
  • Directories Filter: /^((?!wp-slimstat|woocommerce-pdf-invoices|wpo_wcpdf|arprice|mk_assets|fvm).)*$/ (avoid scanning specific directories)
  • Files Filter: /400×400.jpg/ (scan only the files of resolution 400×400)
  • Files Filter: /.jpg|.png/ (scan only the png and jpg files)

Thumbnails Only will only scan your thumbnails and avoid the original (full-size) images. This could also have been done with a regular expression but is to make life easier for most users. Have a look at the Recommended Procedures for the usual usage of this option.

Before the filters are applied, the scan will need to go through all the directories and files first. Therefore, it is perfectly normal that the plugin is analyzing a directory which logically should be skipped (one of the reasons is that a directory that matches the filters might actually be under it).

Recommended Procedures

Having a headache already? Here are the typical procedures that you should be aware of.

Standard Check (Media Library Method)

This will check which Media entries are used or not based on the content of your website (which includes pretty much everything, your posts, products, widgets, the meta associated to them, etc). Live Content will slow down the scanning but might deliver more accuracy in the results.

Media Cleaner

Start the scan, then wait. It takes more or less time depending on your install. If it stops suddenly, please check how to debug Media Cleaner. When it is finished, have a look at the results and firstly, search for the images used by your theme directly (usually, the header, the hero, the logo). Those might have been detected by the plugin but it is not certain, as it is often used silently by your theme. Mark them as ignored if they are part of the results.

Check the files which were detected as not in use. Are they really not in use? Check a few of them randomly, at least. Then delete them with the plugin. They will be moved to the plugin’s trash and the database entry for the media will be also kept.

Use your website for a while. Everything works? Empty the trash. Many broken files? Restore them using the Media Cleaner dashboard, or your backup.

Meticulous Check (Filesystem Method)

I recommend doing this after having checked your Media Library first. Now that your Media Library is clean, we would like to know which files in your /uploads directory are actually not registered as part of a media. I would preferably use the following settings.

Media Cleaner Settings

All the files which are not part of a media will be detected. This makes sure that everything in your files is actually properly registered in your Media Library.

The combination of those two checks will make your install very optimized, sparkling. Everything is used and properly registered. This is ideal! :)

Broken Media Check

That’s another alternative check you can perform with Media Cleaner. With the Media Library method and all the checkboxes ticked off, logically, we should get the list of all the Media entries. That wouldn’t be very useful; so in that case, Media Cleaner will only detect the broken media entries.

Media Cleaner Settings

This wouldn’t delete any files, of course, but that will clean your database from useful Media entries and the associated metadata.

Delete All Thumbnails

There are plugins that are supposed to delete the thumbnails, but they actually only delete the thumbnails which are registered and don’t see the previously created ones. Only Media Cleaner can do that, so please take advantage of it to clean your install easily :)

Pick Filesystem as the method first, then pick Thumbnails Only.

In that case, it doesn’t make much sense to analyze your install for references, you will just want to get the list, then delete them. You probably want to regenerate the fresh thumbnails that you need with another plugin after that. Remember that if you don’t need all those image sizes, you can use the remove_image_size function of WordPress or plugin such as Stop Generating Image Sizes.

WP-CLI

If you are the admin of your server or if your hosting services offer you SSH access and WP-CLI, you can run Media Cleaner from the command line. This also brings new possibilities like running a scan every once in a while, getting the results by e-mail, etc.

To run the scanning based your current settings:

> wp media-cleaner scan

You can override the settings it is running with by specifying the method filesystem or media) and the options (check-media, uncheck-media, check-content, uncheck-content). For example, for running the Standard Check, you would use:

> wp media-cleaner scan media check-content

At the end of the scan, the list of issues will be displayed. If you need to have it displayed again (or to count the number of lines), you can use:

> wp media-cleaner issues

If you want to go further and automate all this, at this point, you should prepare a backup. Then you can run the deletion process:

> wp media-cleaner delete

All the issues will be sent to the trash. And the final command, to empty the trash, is this one:

> wp media-cleaner trash