In the spirit of cleaning up digitally, it would be useful to have a sort of tool that spots if an image isn’t being used anywhere on the site. Over time, so many images get uploaded and lost. If there was a tool to see that images aren’t being used anywhere, admins could remove them and making the site a bit more green.




Discussion
Based on this idea, I have experimented with a service called "Media Cleaner" that identifies unused media files in a WordPress website, to easily find and remove them. The service can be tested and checked here: https://github.com/greenpeace/planet4-master-theme/pull/2994 This implementation, in particular, only looks for media used as a featured image or as part of the Image block or the Cover block. Implementing a service like this is more complicated than it seems. Because WordPress has no centralized media usage registry, each system stores references differently, so all unused media must be searched for separately. Just to name a few, these are some of the places where media can be found: Featured image, Classic editor, Gutenberg blocks, ACF fields, Elementor, Divi, WooCommerce, Widgets, Nav menus, Site logo/favicon, Hardcoded in theme, etc. Furthermore, every new custom piece of code added by a plugin or a child theme introduces a new potential place where media files can be uploaded and found. There exists, however, a popular plugin used to identify and remove unused files: Media Cleaner. For testing and comparison, I installed it and used it on my local instance, and surprisingly, I got the same results as the custom solution of this PR. The problem with the plugin, nevertheless, is the same I mentioned before: media files are only analyzed in parts of the website already pre-established. There is no way to check for all of them globally.