Support » Plugin: Media Cleaner » Bug causing unexpected data loss

  • Resolved Marco Chiesi


    first of all, thank you very much for this precious and useful plugin.
    I am writing to report a bug that I’ve encountered recently during a media library cleanup on a very large site.
    I have moved lots of images to the Media Cleaner Trash and I kept them there for a couple of weeks. During this time new images were uploaded to the website.
    When I finally emptied the trash, the automatic procedure also deleted inadvertently some of the new images that were uploaded recently. After further investigation, I’ve found that images currently in the media library with the very same file name (and in the same original folder) of the ones that were being deleted from the trash were deleted as well.
    You should be able to reproduce the issue, by moving an image to the trash and then upload a new image with the very same name, and finally empty the trash.
    P.s. In my case, there were many (75k+) images, including many with generic file names (i.e. IMG_0001.jpg) and moreover I had the option “Organize my uploads into month- and year-based folders” disabled; these things increased the probability of matching file names.

Viewing 1 replies (of 1 total)
  • Plugin Author Jordy Meow



    I am quite annoyed, I replied to this in details but somehow the reply wasn’t posted >< I need to go soon but I really wanted to reply so let me know if it’s not enough details.

    First, thanks for finding this, and it actually makes sense. The issue only appears with the Media Library method, not the Filesystem Method.

    When a Media Entry is trashed, the files are moved by the cleaner to physical trash handled by the plugin, and the DB entry is marked as deleted but still in the database (by the WordPress API). When the trash is emptied, files are removed (and that’s fine) but the Cleaner also calls the WordPress API to permanently delete the DB entry. WordPress makes sure everything related to that DB entry is removed… the old location of the files included! That’s actually normal.

    One solution would be to modify the DB entry before it’s removed temporarily: the location of the files would be updated to the trash folder. If it’s restored, then Media Cleaner would restore the previous settings.

    The second solution would be for Media Cleaner to stop using the trash for the Media entries, and to start handling everything by itself. No need to set up this constant in the wp-config neither. The problem is that it’s a big change, and it’s hard for me to guess the downsides.

    I would rather go for solution two. It’s more difficult, but solution 1 is also tricky and brings no advantages for my users (and you are the only one who encountered that issue). I would prefer to go for solution two since it removes the need of creating the constant so that it works better for you, and easier to uses for the others 🙂

    Testing will be definitely needed. If you are interested in this, it would be great if you could get in touch with me (

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.