=== Unused Media Checker ===
Contributors: derwebfuchsde
Tags: media, cleanup, optimization, unused, gallery
Requires at least: 6.0
Requires PHP: 8.0
Tested up to: 6.9
Stable tag: 1.3.7
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Identify, inspect and delete unused media files in your media library, including integrations for Advanced Ads and Photo Gallery (10Web).

== Description ==
= English =
Unused Media Checker helps you identify, inspect, and safely remove unused media files from your WordPress Media Library.

The plugin analyzes your site and lists attachments that are *not* referenced in:

- Posts, pages, and all public custom post types (including featured images/thumbnails)
- Post content (Gutenberg blocks and classic content with `wp-image-ID` classes)
- Direct image URLs from the uploads folder (`wp-content/uploads/...`)
- Advanced Ads (media referenced via the `advanced_ads_media` meta)
- Theme Customizer (site logo, site icon, header image, background image – including retina variants)
- Rank Math FAQ blocks (images stored in FAQ block attributes)
- Photo Gallery (10Web): optional filename-based warning in the unused list (usage is not mapped via attachment IDs)

Key features:

- Clear list of potentially unused attachments with thumbnails, title, date and quick "Inspect" link
- Accurate detection that respects logos, favicons, featured images and common SEO/ads integrations
- Bulk delete with nonce protection and clear success messages – no unexpected white screens
- Safe individual delete buttons per item with confirmation dialog
- Pagination and list rendering powered by WordPress's native `WP_List_Table` class
- Optional Photo Gallery (10Web) helpers:
  - Media Library warning when a file with the same name exists in Photo Gallery
  - Photo Gallery files report (uploads/photo-gallery/) with grouping and an "unused motif" filter
- Fully translation-ready via the textdomain `unused-media-checker`

= Deutsch =
Unused Media Checker hilft Ihnen, ungenutzte Dateien in Ihrer WordPress‑Mediathek zu identifizieren, zu überprüfen und sicher zu entfernen.

Das Plugin analysiert Ihre Website und listet Anhänge, die *nicht* referenziert werden in:

- Beiträgen, Seiten und allen öffentlichen Custom Post Types (inkl. Beitragsbilder/Thumbnails)
- Beitragsinhalten (Gutenberg‑Blöcke und klassischer Editor mit `wp-image-ID`‑Klassen)
- Direkt eingebundenen Bild‑URLs aus dem Uploads‑Ordner (`wp-content/uploads/...`)
- Advanced Ads (Medien im Meta‑Feld `advanced_ads_media`)
- Theme‑Customizer (Website‑Logo, Website‑Icon, Header‑Bild, Hintergrundbild – inkl. Retina‑Varianten)
- Rank‑Math‑FAQ‑Blöcken (Bilder in den FAQ‑Block‑Attributen)
- Photo Gallery (10Web): optionaler Dateinamen‑Hinweis in der Unused‑Liste (Nutzung wird nicht über Attachment‑IDs gemappt)

Funktionen:

- Übersichtliche Liste potenziell ungenutzter Anhänge mit Vorschaubild, Titel, Datum und "Inspect"‑Link
- Präzise Erkennung, die Logos, Favicons, Beitragsbilder und gängige SEO/Ads‑Integrationen berücksichtigt
- Massenlöschung mit Nonce‑Schutz und klaren Erfolgsmeldungen – keine unerwarteten weißen Seiten
- Sicheres, einzelnes Löschen je Datei mit Bestätigungsdialog
- Massenaktionen und Paginierung basierend auf der WordPress‑Klasse `WP_List_Table`
- Optionale Photo Gallery (10Web) Hilfen:
  - Warnhinweis in der Mediathek‑Unused‑Liste, wenn ein gleichnamiges File in Photo Gallery existiert
  - Report für Photo Gallery Dateien (uploads/photo-gallery/) inkl. Gruppierung und Filter „Nur ungenutzte Motive“
- Übersetzungsbereit über die Textdomain `unused-media-checker` (z. B. Deutsch, Englisch und weitere Sprachen)

== Installation ==

Download the plugin ZIP file.

In the WordPress admin, go to Plugins > Add New > Upload Plugin and select the ZIP.

Activate the plugin through the Plugins menu.

Navigate to Media > Unused Media Checker to start cleaning up.

== Changelog ==
= 1.3.7 =

- New scan modes:
  - Quick scan (faster, may miss usage) — trash only
  - Thorough scan (recommended) — can delete permanently
- New deep scan options (Thorough scan only): Widgets and Uploaded-to
- Performance: conservative caching for aggregated "used attachment IDs" and cache invalidation on relevant content changes
- Performance: reduced DB query load in Media Library list rendering
- Performance: improved cache-miss scan performance for large sites
- Inspect: cached detected usage sources for faster repeated inspections
- Developer: optional profiling output via ?umc_profile=1 to diagnose slow scans (time, queries, cache hit/miss)
- Fix: improved PHP 8+ compatibility for cache invalidation hooks

= 1.3.6 =

- Photo Gallery (10Web): show a warning in the Media Library unused list when a file with the same name exists in Photo Gallery
- Photo Gallery (10Web) files report: improved motif grouping so imported Media Library variants (imported_from_media_libray/.original + thumb) are grouped consistently

= 1.3.5 =

- Improved pagination UX after deletions:
  - stay on the current page when deleting a single item
  - automatically fall back to the last valid page if a page becomes empty
  - only show the "No unused media found" message when all unused items are really gone

= 1.3.4 =

- Tested with WordPress 6.9 and updated compatibility headers
- Fixed nonce handling for bulk actions to avoid "Security check failed" errors from unrelated POST requests
- Prevented blank pages after deletion and improved success notices directly on the Unused Media Checker screen
- Greatly improved detection of *used* media:
  - scans all public post types (not only posts/pages)
  - detects direct image URLs from the uploads folder
  - includes Theme Customizer media (logo, site icon, header/background images, retina variants)
  - recognizes images used in Rank Math FAQ blocks

= 1.3.3 =

Removed unused CSS/JS – now relies on native List Table styles

Updated version and README

= 1.3.2 =

Removed script.js and style.css enqueue

= 1.3.1 =

Added Inspect button before delete

= 1.3.0 =

Database queries with LIMIT/OFFSET

WP_List_Table integration

AdvancedAds support

Centralized capability and nonce checks

== Frequently Asked Questions ==
= Will deleting unused media files affect my site? =
No. Only files identified as unused are listed. Use the “Inspect” button to verify before removal.

= Why aren’t my AdvancedAds images listed? =
Media used in AdvancedAds is automatically detected and excluded from the list.

= Do I need any settings? =
No. Install and activate the plugin – it works out of the box.

== Support ==
For issues or questions, visit:
https://derwebfuchs.de/wordpress-mediathek-aufraumen-unused-media-checker/

== Upgrade Notice ==
= 1.3.7 =
Adds Quick/Thorough scan modes and deep scan options, plus significant performance improvements (caching and reduced query load).

= 1.3.6 =
Photo Gallery (10Web) improvements: warning in Media Library unused list + improved motif grouping for imported Media Library variants.

= 1.3.5 =
Improved pagination after deletions and better UX for single-item deletes. Recommended for a smoother cleanup workflow.

= 1.3.4 =
Important compatibility update for WordPress 6.9 with more accurate detection of unused media and improved bulk deletion UX. Please update.

= 1.3.3 =
Minor code optimizations and removal of unused assets.

= 1.3.0 =
Major update: Inspect button, AdvancedAds support, performance improvements.