SOLVED: Media Browser: usage check misses template settings, custom fonts, custom icons, global elements and posts in the trash

Bricks version: 2.4.3

What happens The usage check before “Trash” / “Delete permanently” in the Media Browser reports 0 uses for files that Bricks itself still references, so they count as safe to delete:

  • a popup background or sticky header scrolling background (template settings)
  • a custom font file (Custom Fonts → font faces)
  • a custom icon (Icon Manager → custom icon set)
  • an image inside a global element (deprecated, but still rendered until converted)
  • an image on a page that is in the trash: deleting it and restoring the page leaves a broken image

Expected These references are listed like an image element on a page. The Academy names URL-only references, custom CSS, code elements, editor content and custom fields as not covered — these five are Bricks’ own data.

Steps to reproduce

  1. Popup template → Template settings → Popup → Background: pick an image.
  2. Media Browser → select that image → Delete permanently.
  3. The check shows the image as not in use.

Same with a font face file, a custom icon, a global element, or a page with an image element that was moved to the trash. Checked with Media_Browser_Bulk::get_attachment_usage_summary(): 0 for all of them, 1 for the same image element on a published page.

Cause includes/media-browser-bulk.php, get_usage_summary():

// ~:1141 — no BRICKS_DB_TEMPLATE_SETTINGS, no BRICKS_DB_CUSTOM_FONT_FACES
foreach ( [ 'BRICKS_DB_PAGE_HEADER', 'BRICKS_DB_PAGE_CONTENT', 'BRICKS_DB_PAGE_FOOTER', 'BRICKS_DB_PAGE_SETTINGS' ] as $constant_name ) {

// ~:1189 $global_sources — no BRICKS_DB_CUSTOM_ICONS, no BRICKS_DB_GLOBAL_ELEMENTS
'BRICKS_DB_GLOBAL_CLASSES' => [ … ], 'BRICKS_DB_THEME_STYLES' => [ … ], 'BRICKS_DB_COMPONENTS' => [ … ],

// collect_post_usage_from_database() ~:1341 — trashed posts are skipped
AND p.post_status NOT IN (%s, %s, %s)   // 'inherit', 'trash', 'auto-draft'

Suggested fix

  • Scan BRICKS_DB_TEMPLATE_SETTINGS and BRICKS_DB_CUSTOM_FONT_FACES as post meta, BRICKS_DB_CUSTOM_ICONS and BRICKS_DB_GLOBAL_ELEMENTS as options — and add them to get_usage_meta_keys() / get_usage_option_keys() too, which invalidate the confirmation.
  • Font faces store bare IDs ([ '400' => [ 'woff2' => 123 ] ]), which collect_attachment_references() does not count (only id in a media context or attachmentId / attachment_id) — the format keys need to count as IDs there.
  • Count trashed posts, maybe labelled “in trash” in the review.

Happy to provide more details if that helps.

Best Regards
Suat

Hi @UserfreundSuat,

thank you for the report. I was able to replicate the issue and I’ve added it to our internal bug tracker.

Thank you,
Matej

We’ve addressed this in Bricks 2.4.5, now available as a one-click update in your WordPress Dashboard.

Please read the changelog entry before updating, and let us know if you experience any issues.