=== Pipe9 Media Optimizer ===
Contributors: altunyurt
Tags: images, webp, optimization, media
Requires at least: 6.4
Tested up to: 7.0
Stable tag: 1.5.2
Requires PHP: 7.4
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Convert images to WebP automatically. Serve via .htaccess rewrites, picture tags, or PHP passthru. Lightweight, zero bloat.

== Description ==

Pipe9 Media Optimizer converts your uploaded images to WebP automatically — no batch jobs, no manual steps, no complex configuration. When a browser supports WebP (all modern browsers do), the optimized version is served instead of the original, reducing page weight by 25-35% on average with zero visible quality loss.

**How it works:**

When you upload an image to WordPress, the plugin creates a WebP copy and stores it alongside the original in `uploads/pipe9-media-optimizer/webp/`. When a visitor loads a page, the plugin detects browser support via the `Accept` header and serves the WebP version — either through server-level rewrite rules, HTML markup, or a lightweight PHP endpoint.

**Key features:**

* **Automatic conversion** on upload — JPEG, PNG, and static GIF images are converted to WebP as soon as they hit the media library. Animated GIFs are converted to animated WebP via gif2webp or Imagick (previously a Pro feature — now free!)
* **Six serving strategies**: Apache rewrite rules (zero PHP cost — the fastest option), HTML `<picture>` wrapping (single buffer scan per page), Nginx config snippet (paste and go — includes theme image rules), PHP passthru endpoint (works on any server), WP Engine optimized mode, or conversion-only mode (no serving changes)
* **Theme image conversion** — scans and converts images inside active theme directories
* **Bulk conversion** — convert your entire existing media library with one click, with a real-time progress bar
* **Media Library integration** — each image gets a format column showing WebP status, with per-image convert and remove actions
* **Memory guard** — automatically detects when an image is too large to convert without blowing through PHP's memory limit, and skips it gracefully
* **Pluggable architecture** — modules register themselves via WordPress hooks; the Pro add-on adds AVIF and animated format support through the same system

**Pro add-on** (separate purchase from pipe9.uk) adds:
* Static AVIF conversion (JPEG/PNG/GIF → AVIF) — even smaller files than WebP
* Animated AVIF conversion (animated GIF → animated AVIF via ffmpeg)

== Installation ==

1. Upload the `pipe9-media-optimizer` folder to `/wp-content/plugins/`
2. Activate the plugin through the Plugins screen
3. Go to Settings → Pipe9 Media Optimizer
4. Choose your serving strategy (Auto-detect works for most setups)

== Frequently Asked Questions ==

= What image formats are converted? =

JPEG, PNG, and static GIF images are automatically converted to WebP. Animated GIFs are now also converted to animated WebP in the free version (via gif2webp binary or Imagick). For animated AVIF conversion, use the Pro add-on.

= How much will this reduce my image sizes? =

Typical savings are at least 25-35% compared to JPEG, and at least 15-25% compared to PNG. Lossy WebP at quality 80 is visually indistinguishable from the original JPEG but substantially smaller. Lossless WebP preserves PNG transparency with smaller file sizes.

= Does this work with my hosting provider? =

Yes. Apache rewrite mode generates static `.htaccess` rules with zero PHP overhead — it's the fastest option. Nginx and WP Engine modes show ready-to-paste config snippets. A PHP passthru mode works on any server, including locked-down hosts that don't allow `.htaccess` overrides.

= Will this affect my existing images? =

No. Only newly uploaded images are converted automatically. Use the Bulk Convert tool on the settings page to convert your existing media library. You can also convert existing images one by one in the media listing section.

= How do I verify it's working? =

Check the "Formats" column in Media Library list view — it shows which WebP copies exist. Or use browser DevTools to inspect response headers (look for `Content-Type: image/webp`).

= Does the Pro add-on require a separate installation? =

Yes, the Pro add-on is a separate plugin that requires Pipe9 Media Optimizer (free) to be installed and active.

== Screenshots ==

1. Plugin settings page with serving strategy selection
2. Media Library with format column and row actions
3. Bulk convert interface with progress bar

== Changelog ==

= 1.5.2 =
* Fixed double `.webp.webp` bug — `on_media_edited()` now checks MIME type via `get_post_mime_type()` instead of file extension, preventing re-conversion of images already converted to WebP by WordPress core
* Intermediate sizes loop now checks `$size['mime-type']` to skip WebP thumbnails from WordPress core conversion
* Upload pipeline switched from hardcoded extension whitelist to MIME-based detection (`image/*` except `image/webp`) — future-proof for any image source format

= 1.5.1 =
* Refactored option prefix handling — removed dynamic `$prefix`/`$option_prefix` variables from all `register_setting()` calls, replaced with hardcoded module prefixes (e.g. `p9mo_webp`, `p9mo_avif`, `p9mo_animated_avif`)
* Removed `get_option_prefix()` method and `option_prefix` format key
* Removed `$prefix` parameter from `register_extra_settings()` in all modules

= 1.5.0 =
* **Animated GIF → WebP now in free version** — animated GIFs are converted to animated WebP inline via gif2webp binary (preferred) or Imagick coalesceImages() fallback (previously required the Pro add-on)
* Theme images now served via passthru/picture instead of themes .htaccess — simpler, fewer rewrite rules, works on all server types
* Nginx config output now includes theme image location blocks with try_files fallback
* Extracted all inline JS to external files (media-actions.js, serving-settings.js, bulk-convert.js) — ~700 lines of PHP-built JS eliminated
* Bulk convert UI consolidated into one parameterized JS component (replaces 4 near-duplicate per-module implementations)
* Resolved WordPress.org and PluginCheck review issues (translators comments, option prefix uniqueness, ABSPATH guards, heredoc elimination)

= 1.4.3 =
* cwebp binary support — Google's command-line WebP encoder is now auto-detected and preferred over Imagick/GD for artifact-free high-quality output
* Fixed WebP block artifacts ('dots', 'crunchy' look) at high quality settings — Imagick now uses webp:method=6, webp:auto-filter, webp:preprocessing=2 for smooth gradients
* Fixed bulk convert pagination hole — no longer stops when page 1's posts all have WebP files from previous single converts
* Fixed silent conversion failure when exec() is disabled — detect() now checks P9MO_CAN_EXEC before selecting cwebp

= 1.4.2 =
* Theme image conversion — automatically scans and converts images in active theme directories
* Improved output buffer handling — skips AJAX, cron, and XML-RPC requests
* Bug fixes and stability improvements

= 1.4.0 =
* Initial release of the refactored plugin with pluggable module architecture
* Pro add-on support with AVIF, Animated WebP, and Animated AVIF modules

== Upgrade Notice ==

= 1.5.2 =
Bug fix: prevents `.webp.webp` double-extension files and duplicate conversions when WordPress core also converts images to WebP during upload.

= 1.5.1 =
Internal refactor: option prefixes are now hardcoded in all register_setting() calls. No functional changes.

= 1.5.0 =
Animated GIF → WebP conversion is now free! Also includes simplified theme image serving, external JS files, and bulk convert UI improvements. Recommended update for all users.

= 1.4.3 =
Fixes WebP quality artifacts, adds cwebp binary support, and fixes bulk convert pagination. Recommended update for all users.
