Find and batch delete ‘orphan’ image files?
-
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
- The topic ‘Find and batch delete ‘orphan’ image files?’ is closed to new replies.