=== Ethwebs Media Cleanup ===
Contributors: sanmathiraj
Donate link: https://wayanad.co.in
Tags: auto delete, media cleanup, delete attachments, orphan images, media library
Requires at least: 5.8
Tested up to: 7.0
Stable tag: 1.2.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Automatically deletes attached media and thumbnails when a post is permanently deleted, while protecting shared images, logos, and advertisements.

== Description ==

Ethwebs Media Cleanup keeps your WordPress Media Library tidy automatically. When you permanently delete a post, the plugin scans for its featured image and embedded images, verifies they are not used anywhere else on your site, and safely removes them along with all generated thumbnail sizes.

= Key Features =
* Automatic deletion of featured images and content images upon post purge.
* Safeguards shared images (will not delete if used in another post or page).
* Keyword & Subfolder protection to protect logos, site assets, and advertisements.
* Built-in Existing Orphaned Media Scanner with AJAX batching to handle 30,000+ images without server timeouts.
* Chunked batch deletion system with real-time statistics counter and Cancel Deletion support.
* Pause and Resume controls for long-running media library scans.
* Client-side UI pagination (25 items per page) to ensure smooth browser rendering on massive media libraries.
* Flexible selection controls: choose "Select Current Page" for page-by-page cleanup or "Select All (All Pages)" for bulk purging.
* Interactive checkboxes for safe manual approval before deletion.
* Completely lightweight with zero external dependencies.

== Installation ==

1. Upload the `ethwebs-media-cleanup` folder to the `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Go to 'Settings' -> 'Media Cleanup' to configure protected keywords or run an orphan scan.

== Frequently Asked Questions ==

= Does this delete images when I move a post to Trash? =
No. Deletion only occurs when you permanently delete a post by clicking "Delete Permanently" or "Empty Trash".

= Will it delete my site logo, header assets, or sidebar ads? =
No. You can define custom protected keywords (e.g., ad-, logo, banner, header) or protected subfolders under the settings page to prevent specific media from ever being deleted.

= Should I protect media using image titles or actual filenames? =
Always use the actual **image filename** (or file path URL) rather than the attachment title! Protection rules check the physical file name on your server (e.g., `company-logo.jpg` or `ad-sidebar.png`). If you add `logo` or `ad-` to your protected keywords list, any file containing those terms in its filename or URL path will be automatically skipped and preserved.

= How does the scanner handle sites with tens of thousands of images? =
The scanner uses a chunked AJAX batch processor (50 images per request) on the server, paired with DOM pagination (25 items per view) on the frontend. This prevents both server timeouts and browser freezing.

== Screenshots ==

1. Admin Settings Page - Configure protected keywords and subfolders.
2. Existing Orphaned Media Scanner - Live batch scanning progress and controls.
3. Pagination & Selection UI - Browse discovered orphans with page-by-page selection.

== Changelog ==

= 1.2.9 =
* Updated all prefixes from emc_ to ethwmc_ (6 characters) to meet WordPress.org minimum 4-character prefix requirement.

= 1.2.8 =
* Renamed plugin to Ethwebs Media Cleanup using established brand identifier.
* Separated inline JavaScript to an enqueued admin.js file.