[wp-trac] [WordPress Trac] #63626: Improve Media Library's "Attached" status to reflect actual usage in posts/pages, not just direct uploads.

WordPress Trac noreply at wordpress.org
Fri Jun 27 16:02:55 UTC 2025


#63626: Improve Media Library's "Attached" status to reflect actual usage in
posts/pages, not just direct uploads.
-------------------------+------------------------------
 Reporter:  sr33hgs      |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Media        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by pbiron):

 Thank you for raising this issue and opening this ticket.  Welcome to
 trac!

 Replying to [comment:1 sr33hgs]:
 > If the current attached/unattached status is not intended to reflect
 media usage in content

 "attached/unattached" is, in fact, **not** intended to reflect media usage
 in content.  It means whether or not the media was uploaded to a specific
 post, that is all.

 I don't know the history, but I suspect that is the **reason** for the
 Attached/Unattached/Detach language instead of "Used/Unused".

 > could we consider introducing an alternate way in Core to track which
 media files are actually unused? This would greatly help site owners
 understand what’s safe to delete - especially on sites with storage limits
 or large content libraries.

 A number of years ago (pre-block editor days) I tried to write a plugin
 that did just that.  I eventually gave up on that plugin because it is
 very difficult (if not impossible) to do so reliably.

 It's easy to tell whether a given attachment is **directly** used within
 post content, but it's the **indirect** usages that are hard/impossible to
 detect reliably.

 Consider a post that uses a shortcode registered by some plugin.  Core
 doesn't know whether that shortcode will use a specific attachment.  The
 tactic the plugin I was writing used was to define a filter that plugins
 registering shortcodes (or themes that use images in templates) could hook
 into and their callback for that filter could indicate whether the given
 attachment was used.  But even that proved unreliable.  For instance, some
 shortcodes allow users to add "content" in their shortcode (e.g.,
 `[Plugin_A_shortcode]some user entered content [Plugin_B_shortcode] other
 user entered content[/Plugin_A_shortcode]`.  So even if Plugin A hooked
 into that filter, if Plugin B did not hook into that filter, the results
 would be unreliable.

 With the block editor the problem became worse given template parts,
 reusable blocks, etc.

 Another tactic would be to **render** every post on the site and search
 the rendered HTML for the URL of the attachment.  That __might__ be
 reliable (I never tried it), but would be **extremely** inefficient,
 likely making the Media List table impractical to use.

 Thus, the goal of knowing when it is safe to delete a given attachment
 because it is not used anywhere on the site is really a no-win situation.

 I would love to have a practical solution to that, but I don't think one
 exists.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63626#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list