• Resolved intelligentdb

    (@intelligentdb)


    Greetings, Eusebiu Oprinoiu,

    Short question: Can we use your autoremove-attachments plug-in to identify and safely batch delete ‘orphan’ image files in the WordPress library?

    Longer explanation:

    1. I am a developer specializing in the FileMaker platform and have used various RESTful APIs, including most recently for WooCommerce.
    I am not a web developer or WordPress developer, though I am working with the WP developer on this project.

    2. I have everything in our FileMaker-to-WooCommerce API integration working great (creating/updating Categories and Products). We were about to move to the production site when we started running out of storage space.

    I discovered that every time I send a product update that includes the list of image urls from our local server, WooCommerce does not simply replace previously uploaded images with the new images, but keeps adding to the WordPress library. Note that of course not all updates include the ‘images’ data, but if someone wants to add or remove or rearrange the order of images for a product, the WooCommerce API only allows the option to re-send and re-upload the complete list, rather than perhaps an ‘add/drop/reorder’ instruction.

    I can manually search the WordPress Media Library and see that there may be dozens of redundant image files for a single product. They all appear to be attached to a product, but there’s no way for me to tell which are the ones that the product is currently attached to. Via the WooCommerce API, I can obtain the ID of the image, but the API does not have a ‘Delete Image’ function (!).

    3. I have done some cursory searching and it appears from various posts that
    a. others are confounded by the same issue.
    b. this is normal WordPress behavior
    c. one might use the WordPress API to delete images. I’m not about to start from ground zero and learn/integrate that API as well at this point.

    We need a quick fix to reliably perform occasional maintenance, removing these ‘orphan’ image files, even if initiated manually. We don’t have a high volume of image re-uploading (this problem was only discovered when we ran out of space while performing some stress testing with high volumes). Nonetheless, we can’t keep collecting and storing orphan image files.

    We are not deleting the products themselves, even after being sold out, so deleting the images is not something that should only occur when the ‘parent’ product record is deleted (if I understand the description of your plug-in).

    Your thoughts, suggestions are greatly appreciated.
    Stay safe.
    — Sincerely, Erik

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Hello, Erik!

    Unfortunately, no. The plugin can’t be used to search and remove unused media.
    I considered adding this feature in the past, but I quickly dropped the idea. Removing files in bulk is a sensitive process, especially when taking into consideration custom fields (which can be used to store both URLs and IDs) and the various non-standard ways in which other plugins use the media library.

    But you might be able to achieve your desired results with Media Cleaner.
    Depending on how your website is set up, the Free version might be enough, but I would recommend going with the Pro version which has support for various third-party plugins and WP-CLI. For a website with a media library as big as yours, WP-CLI is probably a must, both in terms of speed and convenience. A shell script run on a daily basis by a cron job will make your life very easy.
    https://www.ads-software.com/plugins/media-cleaner
    https://meowapps.com/plugin/media-cleaner

    If that doesn’t work, keep an eye on Happy Files Pro. Removing unused media files is on their roadmap. (and they are usually quick to implement new features)
    https://happyfiles.io

    Best regards,
    Eusebiu Oprinoiu

    Thread Starter intelligentdb

    (@intelligentdb)

    Yes, Media Cleaner was also recommended to me by colleague today, and we’ll be looking into that ASAP. I’m not a CLI or shell script type, but hopefully our web developer is. Thank you again. — Sincerely, Erik

    Plugin Author Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    You’re welcome. I hope Media Cleaner is a good fit for your needs.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Find and batch delete ‘orphan’ image files?’ is closed to new replies.