=== MITS Image Optimizer ===
Contributors: mitspl, wpaluchmits
Tags: image-optimization, webp, avif, compress, image
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 8.0
Stable tag: 1.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Auto-compress images on upload, bulk convert to WebP & AVIF, manage .htaccess WebP serving, and audit your site — all in one plugin.

== Description ==

**MITS Image Optimizer** is a professional image optimization toolkit for WordPress. It compresses images automatically on upload, batch-converts your entire media library to WebP and AVIF, configures Apache to serve next-gen formats automatically, and scans your site for common technical SEO issues.

= Features =

**Auto-Compress on Upload**
Every JPG/PNG above a configurable size threshold is automatically scaled and compressed before WordPress generates its thumbnail sizes. No extra steps needed.

**Bulk Compression**
Run a background batch job to compress all existing images in your media library. Progress is tracked and the job runs asynchronously — it won't block your browser.

**WebP Converter**
Batch-convert all JPG/PNG/GIF files in your uploads directory to WebP format. Runs in the background using WP-Cron or a loopback HTTP request. Supports both Imagick and GD libraries.

**AVIF Converter**
Convert images to AVIF — the next-generation format that can be 30–50% smaller than WebP. Requires Imagick 7+ with AVIF support or PHP 8.1+ with GD `imageavif()`. The plugin detects support automatically and warns you if AVIF is unavailable on your server.

**Apache .htaccess Configuration**
One click adds `mod_rewrite` rules to your `.htaccess` so Apache automatically serves `.webp` files to browsers that support them, with no code changes required in your theme.

**Image Dimensions Scanner**
Detects images ≥ 1600 px wide that are used in posts or as featured images. Helps you find oversized images that slow down page loads, along with their file sizes, dimensions, and WebP/AVIF conversion status.

**Site Audit**
Scans your site for the most common technical issues: missing alt text, oversized images, missing SSL, outdated plugins, pages without Open Graph tags, and more. Results include actionable recommendations.

**Dashboard Widget**
A compact stats panel on the WordPress admin dashboard showing compression savings, WebP/AVIF conversion counts, and a link to the optimizer.

= Requirements =

* PHP 8.0+, WordPress 6.0+
* GD or Imagick PHP extension (for WebP/compression)
* Imagick 7+ with AVIF or PHP 8.1+ GD (for AVIF conversion)
* Apache + `mod_rewrite` (for automatic WebP serving via `.htaccess`)

= Privacy =

This plugin does not collect any personal data and does not make any external HTTP requests.

== Installation ==

1. Upload the `mits-image-optimizer` folder to `/wp-content/plugins/`.
2. Activate the plugin via **Plugins → Installed Plugins**.
3. Navigate to **MITS Optimizer** in the WordPress admin sidebar.
4. (Optional) Click **Konfiguruj .htaccess** on the WebP tab to enable automatic browser-side WebP delivery.

== Frequently Asked Questions ==

= Does this plugin delete my original images? =

No. Original images are never deleted. WebP and AVIF files are saved alongside originals with a `.webp` or `.avif` extension (e.g. `photo.jpg` → `photo.jpg.webp`).

= What happens if my server doesn't support AVIF? =

The AVIF tab will display a warning with the reason (e.g. Imagick version too old, or GD `imageavif()` not available). WebP conversion and compression still work independently of AVIF support.

= Does it work with object-cache or page-cache plugins? =

Yes. The plugin only modifies image files in your uploads directory and your `.htaccess`. It is compatible with all major caching plugins.

= Can I run compression and WebP/AVIF conversion at the same time? =

It is not recommended. Run one batch job at a time to avoid server load spikes and to keep progress tracking accurate.

= Is the .htaccess change reversible? =

Yes. The plugin wraps its rules in clearly marked comment blocks (`# BEGIN MITS WebP` … `# END MITS WebP`). You can remove them manually or via the plugin button.

= What image formats are supported? =

Auto-compression and bulk compression support JPG, JPEG, PNG, and GIF. WebP and AVIF conversion support the same formats. GIF files are converted to static WebP/AVIF (animation is not preserved).

== Screenshots ==

1. Main dashboard — image health score, library stats, and optimization overview.
2. WebP Converter tab — batch conversion controls, server library status, and progress tracking.
3. Site Audit tab — one-click free scan for performance, SEO, and security issues.

== Changelog ==

= 1.1.0 =
* Add: PNG backup restore — lists saved backup ZIPs, one-click restore extracts original PNGs, reverts WordPress metadata, content URLs, and removes .webp files.
* Fix: PNG → WebP table no longer clips the action button — removed conflicting overflow:hidden from card.
* Fix: Admin notices from other plugins (AccessiYes, Rank Math, etc.) are now suppressed on all MITS pages.

= 1.0.9 =
* Fix: PNG → WebP conversion now handles the case where a .webp file already exists (created by WebP Converter) — instead of blocking with "file exists", it skips re-encoding and proceeds to delete the PNG source and update WordPress metadata.

= 1.0.8 =
* Add: PHP WebP Serving — replaces image URLs in HTML output with .webp versions when the browser supports WebP and the .webp file exists. Works on Apache and Nginx without any server configuration. Sends Vary: Accept header for correct caching behaviour. Off by default.

= 1.0.7 =
* Add: "Pobierz ZIP (backup)" button on PNG → JPG/WebP tab — creates a ZIP archive of all found PNG originals for safe local backup before conversion.
* Change: "Konwertuj wszystkie" now automatically creates a backup ZIP before starting batch conversion; conversion is blocked if backup fails.

= 1.0.6 =
* Add: "Konwertuj wszystkie" bulk button on the PNG → JPG/WebP tab — converts all found PNG files in one click without losing the per-file option.

= 1.0.5 =
* Add: Nginx WebP serving configuration snippet in Settings (alongside Apache .htaccess).
* Change: .htaccess and Nginx sections moved into the Settings page; removed separate .htaccess tab.
* Change: Settings and O MITS moved to WordPress sidebar submenu for easier access.

= 1.0.4 =
* Add: Welcome notice shown after plugin activation with 3-step quick-start guide and a dismiss button.

= 1.0.3 =
* Fix: Dashboard scan no longer scans the filesystem — uses WordPress database queries instead, making it instant even on stores with 100k+ products.
* Fix: WebP/AVIF coverage is now estimated from a 500-attachment sample (extrapolated to full library) rather than iterating all files.

= 1.0.2 =
* Add: "Settings" quick-link on the Plugins list page.
* Fix: Missing logo-mits.svg causing 404 in the admin header.

= 1.0.1 =
* Fix: AJAX handlers now return proper JSON error responses instead of HTTP 500 HTML on unexpected PHP errors.
* Add: Built-in error logger — errors are saved to a log file in the uploads directory for easier debugging.
* Add: Hidden diagnostic page at wp-admin/admin.php?page=mits-debug showing system info (PHP, GD, Imagick, upload directory permissions, WP-Cron status) and the error log with a clear button.

= 1.0.0 =
* Initial release.
* Auto-compression on upload with configurable quality and max-width.
* Bulk compression with background batch processing and progress tracking.
* WebP Converter with Imagick and GD support.
* AVIF Converter with Imagick 7+ and GD imageavif() support.
* Apache .htaccess automatic WebP serving configuration.
* Image Dimensions Scanner detecting oversized images in use.
* Site Audit with checks for missing alt, SSL, Open Graph, plugin updates, and more.
* WordPress Dashboard Widget with optimization statistics.

== Upgrade Notice ==

= 1.0.1 =
Fixes AJAX 500 errors returning HTML instead of JSON. Adds error logging and a hidden diagnostic page.

= 1.0.0 =
Initial release — no upgrade steps required.
