=== Thumbnail Manager ===
Contributors: yoohw
Tags: thumbnails, regenerate, media, images, cleanup
Requires at least: 6.3
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Clean, control, and regenerate thumbnails with precision — remove unused sizes, prevent bloat, and rebuild what matters.

== Description ==

Thumbnail Manager is a powerful tool to take full control over your WordPress image system.

Instead of letting themes and plugins generate dozens of unnecessary thumbnails, you can now:

- **Control which sizes are created**
- **Remove unused thumbnails safely**
- **Regenerate only what you actually need**

All in one place.

---

### 🚀 What it does

**1. Regenerate Thumbnails (NEW)**
- Regenerate thumbnails based on your current enabled sizes
- Works in batches with progress tracking (no timeout issues)
- Perfect after disabling unwanted sizes
- Ensures your Media Library stays consistent and optimized

**2. Prune Unused Thumbnails**
- Select sizes you want to **KEEP**
- Automatically detect and remove all other generated thumbnails
- Supports:
  - Registered sizes
  - Orphan `-WxH` files
  - `.webp`, `.bak`, `@2x`, `-1` variants

**3. Orphan File Discovery**
- Detect leftover thumbnails no longer registered
- Clean legacy sizes from old themes/plugins
- Optional aggressive cleanup mode

**4. Disable Sizes for Future Uploads**
- Prevent unnecessary thumbnails from being generated
- Reduce storage usage going forward
- Keeps your system lean and predictable

**5. Recommendations**
- Get recommendations for commonly safe thumbnail sizes
- Highlights WordPress core and WooCommerce-related sizes
- Helps identify likely unused custom sizes
- Quickly apply suggested sizes before regenerating or pruning

**6. Scoped Processing**
- Limit operations to specific folders (year/month)
- Safer testing on large Media Libraries

---

### ❌ What it does NOT do

- It **does NOT delete original full-size images**
- It **does NOT modify image quality or compression**
- It **does NOT replace image optimization plugins**
- It does not automatically run actions without your confirmation

---

### 🎯 Who is it for?

- WooCommerce stores with heavy image usage
- Sites using multiple themes/page builders
- Developers cleaning legacy media bloat
- Anyone hitting disk limits or slow backups

---

## Features

- 4-tab UI: **Regenerate**, **Recommendations**, **Prune Files**, **Thumbnail Sizes**
- Batch processing with AJAX (no timeouts)
- Dry-run preview before deletion
- Smart orphan detection
- Progress bars + live feedback
- Future upload size control
- Multisite compatible (run per site)
- Recommendation engine for safer cleanup decisions
- WooCommerce-aware protected size detection
- Apply recommended sizes with one click

---

## Installation

1. Upload the plugin to `/wp-content/plugins/` or install via WordPress.
2. Activate the plugin.
3. Go to **Tools → Thumbnail Manager**.

---

## Usage

### Recommended Workflow

1. Go to **Recommendations**
2. Scan media usage suggestions
3. Apply recommended sizes
4. Go to **Thumbnail Sizes**
5. Save changes and run regenerate
6. Review and clean old thumbnails in **Prune Files**

---

### Prune Files

1. Select sizes to **KEEP**
2. Run **Dry-run** first
3. Review results
4. Switch to **Delete** and execute

---

### Thumbnail Sizes

- Enable/disable sizes for future uploads
- Does NOT affect existing images until prune/regenerate is used

---

## Frequently Asked Questions

### Will this delete my original images?
No. Only generated thumbnails are affected.

### Should I back up first?
Yes. Always back up before deleting files.

### What is “Orphan discovery”?
It detects thumbnails on disk that are no longer registered in WordPress.

### When should I use Regenerate?
After changing enabled sizes — to rebuild correct thumbnails.

### Are Recommendations fully automatic?
No. Recommendations are based on protected/core thumbnail sizes and common usage patterns. Always review suggestions and use Dry-run before deleting thumbnails.

### Does it unregister sizes?
No. It prevents generation using filters instead.

### Is it safe for large sites?
Yes. Uses batch processing and folder scoping.

---

## Screenshots

1. Regenerate tab with progress system  
2. Recommendations tab with suggested sizes  
3. Prune Files with dry-run preview  
4. Thumbnail Sizes configuration panel

---

## Technical Notes

- Uses `intermediate_image_sizes_advanced` to control generation
- Uses AJAX batching to avoid server timeout
- Safe file targeting via pattern matching
- Requires `manage_options` capability

---

## Changelog

= 1.2 (May 9, 2026) =
* ✨ Added **Recommendations** tab for safer thumbnail cleanup decisions
* ✨ Added recommendation engine for WordPress core and WooCommerce-related sizes
* ✨ Added one-click “Apply recommended sizes”
* ✨ Added improved workflow: Recommendations → Sizes → Regenerate → Prune
* ✨ Added scoped regenerate processing:
  - All media
  - Current year
  - Specific uploads folders
  - Specific attachment IDs
* ✨ Added “Force regenerate all” option
* ✨ Added “Only generate missing thumbnails” optimization
* ✨ Added “Save changes and run regenerate” workflow
* ✨ Added Regenerate as the default tab
* 🔧 Improved regenerate batching and UI progress handling
* 🔧 Improved AJAX architecture and tab interaction handling
* 🔧 Improved overall media optimization workflow for large sites

= 1.1 (Mar 19, 2026) =
* ✨ Added **Regenerate Thumbnails** feature with batch processing and progress UI
* ✨ Added **“Save changes and run regenerate”** workflow
* ✨ Set **Regenerate tab as default entry**
* ✨ Improved UX flow between Sizes → Regenerate → Prune
* ✨ Added automatic trigger for regenerate after saving sizes
* ✨ Improved admin JS handling for multi-tab interaction
* 🔧 Refactored internal handlers for regeneration logic
* 🔧 Improved performance for large media libraries

= 1.0.1 (Dec 3, 2025) =
* Added full translation support
* Improved UI labels and formatting
* Accessibility improvements

= 1.0 (Oct 5, 2025) =
* Initial release
* Prune Files with dry-run and batch deletion
* Orphan detection
* Disable sizes for future uploads

---

## Upgrade Notice

= 1.2 =
Major update introducing Recommendations and advanced Regenerate workflow.

Recommended workflow:
Recommendations → Thumbnail Sizes → Regenerate → Prune.

---

## Privacy

This plugin does not collect or transmit any personal data.  
All operations are performed locally on your server.