=== WebP Image Converter & Replacer – Convert to WebP, No Duplicates ===
Contributors: coreessentials
Tags: webp, webp converter, convert to webp, image optimization, media library
Requires at least: 5.8
Requires PHP: 7.4
Tested up to: 6.8
Stable tag: 1.1.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Convert images to WebP and replace originals—no duplicates. Save storage and speed up your site. Auto-convert on upload & bulk tools (premium).

== Description ==

**WebP Image Converter & Replacer** converts your images (JPEG, PNG, static GIF) to **WebP**, replaces originals **only when smaller**, and updates database references so your site transparently serves `.webp`. No duplicate files. No front-end bloat. Just **faster pages** and **less disk usage**.

**Why this plugin**
- **No Duplicate Images:** Converts and replaces originals when WebP is smaller, keeping `/uploads` lean.
- **Real Performance Gains:** WebP typically reduces size ~25–35% at similar quality, aiding Core Web Vitals.
- **Safety First:** Never deletes the original unless conversion succeeds **and** the WebP is smaller.
- **Full DB Integration:** All generated sizes are converted; URLs in content/meta are updated to `.webp`.
- **On-Server Only:** Uses PHP **GD** or **Imagick**. No external API, keys, or privacy concerns.
- **Lightweight:** Runs only during conversion—nothing extra on the front end.

**Free features**
- Convert individual images from **Media → Library** (list view).
- **Optimization Overview** with counts: convertible, converted, remaining, skipped, failed, total space saved.
- Smart memory handling to avoid PHP exhaustion on large images.

**Premium features**
- **Auto-convert on upload:** New images become WebP automatically.
- **Bulk convert selected:** Multi-select in Media Library (list view).
- **Bulk convert all:** Library-wide conversion with progress + pause/resume.

> Whether you’re tight on storage or chasing better performance, this is a **safe, effective** way to modernize images.

**IMPORTANT:** Because originals may be deleted, **back up** your `/wp-content/uploads/` and database before converting. Test on staging if possible.

=== How it works ===
1. Plugin checks server support (GD/Imagick with WebP).
2. You convert images (single/bulk/premium auto).
3. If the `.webp` is smaller, the original file is removed and **all DB refs switch to `.webp`**.
4. Your site now serves WebP transparently—no theme changes required.

== Installation ==

1. **Back up** `/wp-content/uploads/` and your database.
2. Install via **Plugins → Add New** (search “WebP Image Converter & Replacer”) or upload the ZIP.
3. Activate.
4. Ensure **Imagick** or **GD** with WebP is available (the plugin will warn if not).
5. Go to **Settings → Media → WebP Image Converter & Replacer** for overview & tools.
6. (Recommended) Install **Phoenix Media Rename** for robust database URL updates (see below).

== Usage ==

**Optimization Overview**
- **Settings → Media** → “WebP Image Converter & Replacer”
- See totals converted/remaining/skipped/failed and **space saved**.

**Convert individual images**
- **Media → Library** (list view) → **Convert to WebP** link under each item.

**Premium**
- **Auto-convert on upload**: toggle under **Settings → Media**.  
- **Bulk convert selected**: select items in Media Library (list view) → bulk action **Convert to WebP**.  
- **Bulk convert all**: **Start Bulk Optimization** with progress + pause/resume.  

**After conversion**
- Verify pages serve `.webp` in browser dev tools.
- Clear any caches/CDN.

== Phoenix Media Rename Integration ==

We integrate with [**Phoenix Media Rename**](https://en-gb.wordpress.org/plugins/phoenix-media-rename/) to safely update **all** database references.

**Why Phoenix?**
- Mature, reliable database URL updates across posts, custom fields, widgets, Customizer, etc.
- Reduces risk vs. “DIY” find/replace logic used by other optimizers.
- Lets this plugin focus on **conversion** while Phoenix handles **DB updates**.

**Flow**
1. Convert to WebP.
2. Phoenix updates URLs from `.jpg/.png/.gif` to `.webp`.
3. Your site serves WebP with no broken links.

== Frequently Asked Questions ==

= Will this plugin delete my images? =
Only if the WebP conversion **succeeds** and the WebP is **smaller**. Otherwise, the original stays. Always keep backups.

= Why are the “space saved” numbers sometimes larger than the single file size? =
WordPress creates multiple thumbnail sizes. Savings are calculated across **the original + all thumbs** vs. **their WebP equivalents**. Thumbnails can outweigh the original file, so total savings can exceed the original’s size.

= What if I uninstall the plugin? =
Your site will continue serving the existing WebP files. Settings are removed; deleted originals are not restored.

= Does this compress or just change format? =
It **converts** format using standard WebP quality defaults (approx. 80–85). No downscaling or custom per-image quality controls in this version.

= Can I change WebP quality? =
Not via UI. Advanced users can modify via filter hooks.

= AVIF or other formats? =
Currently WebP only. AVIF may be added when browser and server support are broadly stable.

= Animated GIFs? =
We auto-detect animated gifs and mark them as skipped, we do not convert them.

= Multisite support? =
Yes. Network-activate, then run conversions per site. Always back up each site first.

= I hit a timeout/error. =
Use bulk pause/resume, try smaller batches, or raise PHP memory/time limits. The plugin includes memory guards, but extreme libraries may need server tweaks.

= Does it support all browsers? =
Modern browsers do. Legacy/very old browsers may not; if those matter, use a different approach.

= Why use Phoenix Media Rename instead of doing DB updates internally? =
We rely on a dedicated, proven solution for comprehensive, safe URL updates—lower risk, better coverage.

== Screenshots ==

1. Optimization Overview – library status and space saved  
2. Phoenix Integration Status – compatibility & guidance  
3. Media Library – “Convert to WebP” links  
4. Example Savings – footprint cut after conversion  
5. Premium – bulk convert & auto-convert on upload  
6. Dev Tools – confirming `.webp` on the front end

== Changelog ==

= 1.1.3 =
* Bug fix: "Fix WebP MIME Types" Utility
* Enhancement: MIME type updated after metadata generation

= 1.1.2 =
* Enhancement: Animated GIFs - Better protected & auto-skipped
* Enhancement: Oversized images - Detected & auto-skipped
* Enhancement: Server limits - Respects ImageMagick & WebP constraints
* Bug fix: Large images: 5-min timeout + execution limit
* Bug fix: Timeout handling - Client-side polling for accuracy

= 1.1.1 =
* Bug fix: improved handling of premium activation edge cases.

= 1.1.0 =
* Major: Auto-Convert on Upload (Premium)
* Major: Optimization Overview (real-time stats)
* Enhancement: Phoenix Media Rename integration + auto-install/activation help
* Enhancement: Memory management to prevent PHP exhaustion on large images
* Enhancement: Stats cleanup on media deletion
* Enhancement: Bulk conversion with pause/resume and better progress
* Enhancement: Bulk select conversion via Media Library
* Enhancement: Caching for faster operations
* Enhancement: Better error handling and debug logging
* Enhancement: WPCS compliance and clearer UI messaging
* Bug fix: improved handling of animated GIFs in stats and conversion logic

= 1.0.1 =
* Minor fixes and performance improvements
* Enhanced compatibility testing

= 1.0.0 =
* Initial release: manual bulk conversion, automatic replacement when WebP is smaller, individual conversion links, JPEG/PNG/static GIF support, GD/Imagick required.

== Upgrade Notice ==

= 1.1.0 =
Major update: auto-convert on upload (premium), overview stats, Phoenix integration, reliability & UX improvements.

= 1.1.1 =
* Enhancement: Longer timeouts for slower servers / larger images
* Enhancement: Status polling to prevent failed false positive
* Enhancement: Better animated Gif detection
* Enhancement: Reduced checking for faster conversions