iftiarhossain
Forum Replies Created
-
Forum: Plugins
In reply to: [Post Media Cleanup] Media Usage Detection Issues & Test ScenariosSubject: Re: Post Media Cleanup — media detection issue
Hi Hamed,
Thanks for the detailed report and reproduction steps — really useful, and you’re right on all three counts.
I’ve confirmed the root cause: the reference-detection logic only ever checked the featured-image meta and a literal URL match inside post content. That missed anything referenced by ID rather than by URL, which is exactly why a shared WooCommerce gallery image, an Elementor-only reference, and an image used in another post’s content could all get flagged and deleted.
I’ve rebuilt the detection into a single shared checker used by both the real-time delete and the bulk scanner, so the two can’t disagree with each other. It now also checks:
- WooCommerce product gallery (_product_image_gallery)
- Elementor data (_elementor_data), including escaped JSON
- ACF image/file/gallery/repeater/flexible-content fields
- Gutenberg image/gallery blocks and [gallery ids="…"] / WPBakery shortcodes
- Term meta (e.g. category thumbnails)
- A few known site options (custom logo, site icon)
On your conservative-detection point — agreed, and I built it that way: a bare numeric value that happens to match an attachment ID is never treated as a reference by itself. For ACF specifically, it only trusts a value once it’s confirmed against the actual field definition that the field is really an image/file/gallery type.
I also added the re-check you suggested: the bulk scanner now re-verifies each attachment immediately before deleting it, rather than trusting the earlier scan result, so a long-running scan can’t delete something that became referenced in the meantime.
This is going out as 2.2.0. I’d genuinely like to see that reference-detection implementation you mentioned — if you’re happy to share it, I’ll take a look and see if there’s anything worth folding in. And if you’re up for testing 2.2.0 against the same three scenarios (plus anything else you think of), I’d appreciate it — happy to turn around any follow-up quickly.
Thanks again for taking the time to write this up properly.
Best,
Iftiar