{"id":19023150,"date":"2026-09-18T07:50:37","date_gmt":"2026-09-18T07:50:37","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/media-usage-detection-issues-test-scenarios\/"},"modified":"2026-09-18T07:50:37","modified_gmt":"2026-09-18T07:50:37","slug":"media-usage-detection-issues-test-scenarios","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/media-usage-detection-issues-test-scenarios\/","title":{"rendered":"Media Usage Detection Issues &amp; Test Scenarios"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi Iftiar,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have tested <strong>Post Media Cleanup 2.1.0<\/strong> on a staging WordPress site, and I found an important issue with the media usage detection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I tested the following scenarios:<\/p>\n\n\n\n<ol>\n<li><strong>Shared WooCommerce product image<\/strong>\n<ul>\n<li>An image is used by Product A.<\/li>\n\n\n\n<li>The same image is also used by Product B.<\/li>\n\n\n\n<li>Product A is permanently deleted.<\/li>\n\n\n\n<li><strong>Expected:<\/strong> The image must be preserved because Product B still uses it.<\/li>\n\n\n\n<li><strong>Actual:<\/strong> The image was deleted.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Elementor<\/strong>\n<ul>\n<li>An image is used inside an Elementor page\/template.<\/li>\n\n\n\n<li>The original post containing the image is deleted.<\/li>\n\n\n\n<li><strong>Expected:<\/strong> The image must be preserved if Elementor still references it.<\/li>\n\n\n\n<li><strong>Actual:<\/strong> The image was deleted.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Another post\/article<\/strong>\n<ul>\n<li>An image is used in another WordPress post\/article.<\/li>\n\n\n\n<li>The original post is deleted.<\/li>\n\n\n\n<li><strong>Expected:<\/strong> The image must be preserved because another post still references it.<\/li>\n\n\n\n<li><strong>Actual:<\/strong> The image was deleted.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">So, in these three scenarios, the result was negative.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, I think the media reference detection should ideally consider a much broader range of real-world WordPress usage scenarios, including:<\/p>\n\n\n\n<ul>\n<li>Featured images (<code>_thumbnail_id<\/code>)<\/li>\n\n\n\n<li>WooCommerce product galleries (<code>_product_image_gallery<\/code>)<\/li>\n\n\n\n<li>WooCommerce variation images<\/li>\n\n\n\n<li>Images used in other products<\/li>\n\n\n\n<li>Images embedded in post\/page\/CPT content<\/li>\n\n\n\n<li>Classic Editor image URLs<\/li>\n\n\n\n<li>Gutenberg image blocks<\/li>\n\n\n\n<li>Gutenberg galleries<\/li>\n\n\n\n<li><code><div class=\"tiled-gallery type-rectangular tiled-gallery-unresized\" data-original-width=\"500\" data-carousel-extra='null' itemscope itemtype=\"http:\/\/schema.org\/ImageGallery\" > <div class=\"gallery-row\" style=\"width: 500px; height: 333px;\" data-original-width=\"500\" data-original-height=\"333\" > <div class=\"gallery-group images-1\" style=\"width: 333px; height: 333px;\" data-original-width=\"333\" data-original-height=\"333\" > <div class=\"tiled-gallery-item tiled-gallery-item-large\" itemprop=\"associatedMedia\" itemscope itemtype=\"http:\/\/schema.org\/ImageObject\"> <a href=\"https:\/\/wordpress.org\/support\/wordpress-logo-128x128\/\" border=\"0\" itemprop=\"url\"> <meta itemprop=\"width\" content=\"329\"> <meta itemprop=\"height\" content=\"329\"> <img decoding=\"async\" class=\"\" data-attachment-id=\"10615628\" data-orig-file=\"https:\/\/wordpress.org\/support\/files\/2018\/08\/wordpress-logo-128x128.png\" data-orig-size=\"128,128\" data-comments-opened=\"\" data-image-title=\"wordpress-logo-128&amp;#215;128\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/08\/wordpress-logo-128x128.png?fit=128%2C128&#038;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/08\/wordpress-logo-128x128.png?fit=128%2C128&#038;ssl=1\" src=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/08\/wordpress-logo-128x128.png?w=329&#038;h=329&#038;crop=1&#038;ssl=1\" width=\"329\" height=\"329\" loading=\"lazy\" data-original-width=\"329\" data-original-height=\"329\" itemprop=\"http:\/\/schema.org\/image\" title=\"wordpress-logo-128x128\" alt=\"wordpress-logo-128x128\" style=\"width: 329px; height: 329px;\" \/> <\/a> <\/div> <\/div> <!-- close group --> <div class=\"gallery-group images-2\" style=\"width: 167px; height: 333px;\" data-original-width=\"167\" data-original-height=\"333\" > <div class=\"tiled-gallery-item tiled-gallery-item-small\" itemprop=\"associatedMedia\" itemscope itemtype=\"http:\/\/schema.org\/ImageObject\"> <a href=\"https:\/\/wordpress.org\/support\/wordpress-logotype-wmark\/\" border=\"0\" itemprop=\"url\"> <meta itemprop=\"width\" content=\"163\"> <meta itemprop=\"height\" content=\"163\"> <img decoding=\"async\" class=\"\" data-attachment-id=\"10746561\" data-orig-file=\"https:\/\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png\" data-orig-size=\"1000,1000\" data-comments-opened=\"\" data-image-title=\"WordPress-logotype-wmark\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?fit=300%2C300&#038;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?fit=1000%2C1000&#038;ssl=1\" src=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?w=163&#038;h=163&#038;crop=1&#038;ssl=1\" srcset=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?w=1000&amp;ssl=1 1000w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-2.png?resize=768%2C768&amp;ssl=1 768w\" width=\"163\" height=\"163\" loading=\"lazy\" data-original-width=\"163\" data-original-height=\"163\" itemprop=\"http:\/\/schema.org\/image\" title=\"WordPress-logotype-wmark\" alt=\"WordPress-logotype-wmark\" style=\"width: 163px; height: 163px;\" \/> <\/a> <\/div> <div class=\"tiled-gallery-item tiled-gallery-item-small\" itemprop=\"associatedMedia\" itemscope itemtype=\"http:\/\/schema.org\/ImageObject\"> <a href=\"https:\/\/wordpress.org\/support\/wordpress-logotype-wmark-2\/\" border=\"0\" itemprop=\"url\"> <meta itemprop=\"width\" content=\"163\"> <meta itemprop=\"height\" content=\"162\"> <img decoding=\"async\" class=\"\" data-attachment-id=\"10746566\" data-orig-file=\"https:\/\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png\" data-orig-size=\"1000,1000\" data-comments-opened=\"\" data-image-title=\"WordPress-logotype-wmark\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?fit=300%2C300&#038;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?fit=1000%2C1000&#038;ssl=1\" src=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?w=163&#038;h=162&#038;ssl=1\" srcset=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?w=1000&amp;ssl=1 1000w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wmark-3.png?resize=768%2C768&amp;ssl=1 768w\" width=\"163\" height=\"162\" loading=\"lazy\" data-original-width=\"163\" data-original-height=\"162\" itemprop=\"http:\/\/schema.org\/image\" title=\"WordPress-logotype-wmark\" alt=\"WordPress-logotype-wmark\" style=\"width: 163px; height: 162px;\" \/> <\/a> <\/div> <\/div> <!-- close group --> <\/div> <!-- close row --> <div class=\"gallery-row\" style=\"width: 500px; height: 83px;\" data-original-width=\"500\" data-original-height=\"83\" > <div class=\"gallery-group images-1\" style=\"width: 151px; height: 83px;\" data-original-width=\"151\" data-original-height=\"83\" > <div class=\"tiled-gallery-item tiled-gallery-item-small\" itemprop=\"associatedMedia\" itemscope itemtype=\"http:\/\/schema.org\/ImageObject\"> <a href=\"https:\/\/wordpress.org\/support\/wordpress-logotype-alternative\/\" border=\"0\" itemprop=\"url\"> <meta itemprop=\"width\" content=\"147\"> <meta itemprop=\"height\" content=\"79\"> <img decoding=\"async\" class=\"\" data-attachment-id=\"10769825\" data-orig-file=\"https:\/\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png\" data-orig-size=\"2000,1080\" data-comments-opened=\"\" data-image-title=\"WordPress-logotype-alternative\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?fit=300%2C162&#038;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?fit=1024%2C553&#038;ssl=1\" src=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?w=147&#038;h=79&#038;ssl=1\" srcset=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?resize=300%2C162&amp;ssl=1 300w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?resize=768%2C415&amp;ssl=1 768w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-alternative.png?resize=1024%2C553&amp;ssl=1 1024w\" width=\"147\" height=\"79\" loading=\"lazy\" data-original-width=\"147\" data-original-height=\"79\" itemprop=\"http:\/\/schema.org\/image\" title=\"WordPress-logotype-alternative\" alt=\"WordPress-logotype-alternative\" style=\"width: 147px; height: 79px;\" \/> <\/a> <\/div> <\/div> <!-- close group --> <div class=\"gallery-group images-1\" style=\"width: 349px; height: 83px;\" data-original-width=\"349\" data-original-height=\"83\" > <div class=\"tiled-gallery-item tiled-gallery-item-large\" itemprop=\"associatedMedia\" itemscope itemtype=\"http:\/\/schema.org\/ImageObject\"> <a href=\"https:\/\/wordpress.org\/support\/wordpress-logotype-wordmark-2\/\" border=\"0\" itemprop=\"url\"> <meta itemprop=\"width\" content=\"345\"> <meta itemprop=\"height\" content=\"79\"> <img decoding=\"async\" class=\"\" data-attachment-id=\"10769830\" data-orig-file=\"https:\/\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png\" data-orig-size=\"2000,460\" data-comments-opened=\"\" data-image-title=\"WordPress-logotype-wordmark-2\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?fit=300%2C69&#038;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?fit=1024%2C236&#038;ssl=1\" src=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?w=345&#038;h=79&#038;ssl=1\" srcset=\"https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?resize=300%2C69&amp;ssl=1 300w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?resize=768%2C177&amp;ssl=1 768w, https:\/\/i0.wp.com\/wordpress.org\/support\/files\/2018\/10\/WordPress-logotype-wordmark-2.png?resize=1024%2C236&amp;ssl=1 1024w\" width=\"345\" height=\"79\" loading=\"lazy\" data-original-width=\"345\" data-original-height=\"79\" itemprop=\"http:\/\/schema.org\/image\" title=\"WordPress-logotype-wordmark-2\" alt=\"WordPress-logotype-wordmark-2\" style=\"width: 345px; height: 79px;\" \/> <\/a> <\/div> <\/div> <!-- close group --> <\/div> <!-- close row --> <\/div><\/code> and similar gallery shortcodes<\/li>\n\n\n\n<li>Elementor content and Elementor templates<\/li>\n\n\n\n<li>Elementor <code>_elementor_data<\/code>, including escaped JSON URLs<\/li>\n\n\n\n<li>ACF image fields<\/li>\n\n\n\n<li>ACF gallery fields<\/li>\n\n\n\n<li>ACF repeater\/flexible content fields containing images<\/li>\n\n\n\n<li>SCF image\/gallery\/repeater fields<\/li>\n\n\n\n<li>Images stored in custom post meta<\/li>\n\n\n\n<li>Real attachment URLs stored inside custom fields<\/li>\n\n\n\n<li>Real attachment paths stored inside custom fields<\/li>\n\n\n\n<li>URLs\/paths nested inside JSON data<\/li>\n\n\n\n<li>URLs\/paths nested inside serialized PHP data<\/li>\n\n\n\n<li>Images referenced by taxonomy\/term metadata<\/li>\n\n\n\n<li>Images referenced by widgets or theme options<\/li>\n\n\n\n<li>Images referenced by menus or other WordPress configuration<\/li>\n\n\n\n<li>PDF and other media files linked from content<\/li>\n\n\n\n<li>Resized image URLs and registered WordPress image sizes<\/li>\n\n\n\n<li><code>-scaled<\/code> image variants<\/li>\n\n\n\n<li>URL-encoded and JSON-escaped versions of URLs<\/li>\n\n\n\n<li>Media referenced by other supported plugins or page builders<\/li>\n\n\n\n<li>An attachment whose original parent post has already been deleted, but which is still genuinely referenced elsewhere<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">At the same time, I believe the scanner should be conservative about what constitutes a reference.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, simply finding a numeric value equal to an attachment ID should <strong>not<\/strong> necessarily mean that the media is being used. A generic custom field such as:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>image_id = 123<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">or a JSON\/serialized value containing:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>{\"id\":123}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">should not automatically be treated as a valid media reference unless the plugin knows that this field actually represents a media reference.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The general rule I would suggest is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A confirmed real media reference \u2192 KEEP the attachment.<br \/>No confirmed reference \u2192 candidate for deletion.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, the scanner should ideally re-check the media immediately before deletion, because the site may change while a large scan is running.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I understand that supporting every possible plugin and data structure is difficult, and I am not suggesting that every WordPress plugin in existence must be supported. I am mainly pointing out the reference types that I believe are important for a reliable general-purpose media cleanup tool.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are interested, I would also be happy to share a small reference-detection implementation I developed for my own WordPress projects. It is designed around identifying <strong>actual media references rather than simply matching attachment IDs<\/strong>, and it may give you some ideas for improving the scanner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I would be glad to test a future version as well and provide detailed reproduction steps for any issues I find.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Best regards,<br \/>Hamed Sedaghat<\/p>\n","protected":false},"template":"","class_list":["post-19023150","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19023150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19023150\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19023150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}