=== Mediaspy - Detect & Clean Unused Media ===
Contributors: masum52
Tags: media, cleanup, unused media, media library, disk space
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Find unused files in your WordPress media library and safely delete them to free up disk space.

== Description ==

Mediaspy scans your entire WordPress site and shows you which media files are not used anywhere. Review the results, then delete what you don't need - one by one or all at once.

**Why Mediaspy?**

Most plugins check only post content. Mediaspy checks everything - page builders, widgets, theme CSS, customizer settings, code snippets, and more - before calling a file unused.

= What gets scanned =

* Post and page content
* Featured images
* Page builder data (Elementor, Divi, WPBakery, Kadence, and more)
* Theme CSS files
* Widget and Customizer settings
* Code snippet plugins (WPCode, Code Snippets, FluentSnippets)
* Plugin options stored in the database

= Features =

* **Scan your full media library** - every image, video, audio file, PDF, archive, and document
* **See where each file is used** - click any file to see every page, post, or setting referencing it
* **Grid and List view** - browse results as cards or a full table
* **Filter by file type** - Images, Videos, Audio, PDFs, Archives, Documents
* **Search by filename** - find any file instantly
* **Sort by size or date** - tackle the biggest space wasters first
* **Bulk delete** - select multiple files and delete with one click
* **Download ZIP** - back up unused files before deleting
* **Import ZIP** - restore a previously exported archive back into your library
* **Live sync** - uploads and deletions made elsewhere reflect instantly, no re-scan needed
* **Zero performance impact** - only runs when you click Scan Now, nothing loads on the front end

= Works with =

Gutenberg, Elementor, Divi, WPBakery, Kadence Blocks, Beaver Builder, Brizy, Oxygen, Bricks, ACF, WooCommerce, and any builder that stores data in post meta or options.

== Installation ==

1. Go to **Plugins -> Add New** in your WordPress admin
2. Search for **Mediaspy**
3. Click **Install Now** then **Activate**
4. Go to **Media -> Mediaspy** and click **Scan Now**

= Manual install =

1. Download the ZIP file
2. Go to **Plugins -> Add New -> Upload Plugin**
3. Upload the ZIP and click **Install Now**
4. Activate the plugin
5. Go to **Media -> Mediaspy** and click **Scan Now**

== Frequently Asked Questions ==

= Is it safe to delete files? =

Mediaspy checks every file against your full database before marking it unused. Even so, always take a site backup before bulk-deleting. Use the **Download ZIP** button to save a copy of unused files before you delete them.

= What if a file shows unused but I can see it on my site? =

Some plugins store data in custom database tables that Mediaspy does not scan (for example, certain booking or events plugins). If you can see a file on your site, do not delete it. Use the search bar to find and skip it.

= Does it work with Elementor, Divi, or other page builders? =

Yes. Mediaspy reads the raw post meta where builders store their data, and also scans global plugin settings in the database.

= Does it detect images used in the Site Editor or as CSS backgrounds? =

Yes. The scanner reads Global Styles and handles JSON-escaped URLs, so background images set through the Site Editor are correctly detected.

= Will it slow down my site? =

No. The plugin is admin-only. Nothing runs on public-facing pages. The scan only starts when you click **Scan Now**.

= Can I get a deleted file back? =

No - deletion is permanent. Use **Download ZIP** to save a backup before deleting if you are unsure.

= Does it support Multisite? =

Not in this version. Mediaspy is designed for single-site installations.

= How long does a scan take? =

Under 5 seconds for most sites. Libraries with 5,000+ files may take up to 30 seconds.

== Screenshots ==

1. Scan results - stat cards showing total, used, unused, and wasted space
2. Grid view - file cards with quick Delete and View actions on hover
3. List view - full table with file type, size, date, and actions
4. View Details modal - every post, page, and setting that references a file
5. Search and sort controls

== Changelog ==

= 1.0.1 =
* Refactor: rebuilt on a modular MVC structure with PSR-4 services and Composer autoloading
* New admin interface built with Vue 3 and bundled with Vite
* Scan, delete, usage details, export and import now run over the REST API (replacing admin-ajax)
* Security: hardened the ZIP import - reject path-traversal entries (Zip-Slip), extract outside the web root, and cap archive size and file count against decompression bombs
* Security: removed an over-eager import de-duplication step that could delete unrelated media sharing the same filename
* Added uninstall cleanup (removes the cached scan, transients and temporary export/import folders)
* Refreshed the header branding with the Mediaspy logo
* Source files normalised to ASCII (fixes garbled comment characters)
* No change to detection accuracy or everyday workflow

= 1.0.0 =
* Initial release
* Full media library scan with 6-layer usage detection
* Grid and list view with search, filters, and sorting
* Bulk delete, Download ZIP, and Import ZIP
* View Details modal showing every usage location per file
* Live two-way sync with the WordPress Media Library

== Upgrade Notice ==

= 1.0.1 =
Recommended update. Internal refactor (MVC + Vue + REST) plus security hardening of the ZIP import. Same features and scan accuracy as 1.0.0.

= 1.0.0 =
Initial release.
