=== SSIM Compress ===
Contributors: vanleoadrivan
Tags: image, compression, optimization, jpg, png, ssim, multisite
Requires at least: 5.5
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 1.0.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Background image compression powered by the SSIM Compress API. Works on single sites and multisite networks.

== Description ==

SSIM Compress shrinks your JPG and PNG attachments without visible quality loss. Compression runs in the background — drop your API key in, click "Start scan", and walk away. Newly uploaded images are auto-queued.

Features:

* Bullet-proof background queue with automatic retries, exponential backoff, and stale-claim recovery
* Auto-pauses if the SSIM API is unreachable or rate-limited, resumes when it comes back
* Configurable batch size + delay so the queue can't overwhelm the SSIM API or your host
* Optional originals backup with bulk restore by day / week / month
* WordPress cron by default, or external (server) cron for low-traffic sites
* Multisite network mode — settings, queue, and stats shared across all subsites
* Auto-optimize newly uploaded images (toggle in settings)
* Re-optimization protection (won't compress the same image twice)

== Installation ==

1. Upload the `ssim-compress` folder to `/wp-content/plugins/`, or install the .zip from the WordPress plugin uploader.
2. Activate the plugin (per-site) or network-activate it (multisite).
3. Go to the SSIM Compress menu and paste your API key. Get one at https://ssim.testingah.com.
4. (Optional) Switch to External cron and add the displayed URL to your hosting panel's cron jobs.
5. Click "Start scan" to queue every existing JPG/PNG in the media library.

== Frequently Asked Questions ==

= Will this compress images I've already optimized? =

No. Both the plugin's local tracking and the API's `SSIM_OPTIMIZED` marker prevent re-processing.

= What happens if the SSIM site goes down? =

The plugin pings the SSIM API once a minute. If it's unreachable, the queue auto-pauses for 5 minutes and resumes automatically. Permanent errors (corrupt images, unsupported formats) are marked as skipped and never retried.

= Does this slow down my site? =

By default the queue processes 1 image per minute with a 3-second internal delay. You can tune this in Settings → Processing if your host can handle more.

= Can I restore originals if I don't like the results? =

Yes — enable backups in Settings, then use the Backups tab to restore any group (by day, week, or month) in one click.

== Changelog ==

= 1.0.5 =
* Default SSIM API endpoint switched from ssim.testingah.com to ssim.realclear.au (the new production host). Installs that never explicitly changed the endpoint pick this up automatically on upgrade.
* Migration: installs that had ssim.testingah.com explicitly stored are nudged to the new endpoint on first load after upgrade. Custom endpoints (anything else) are left alone.

= 1.0.4 =
* Autonomous outage recovery — server-unreachable and rate-limited failures no longer burn per-image retry budgets, so a long API outage (hours or days) can't shunt healthy images into the ERROR bucket.
* Exponential backoff on the pause TTL: 5, 10, 20, 40, 60, 60... minutes (capped at 1 hour). Reset to 5 min on the next successful compress. Cuts outage-time API pings from ~288/day to ~26/day.
* One-shot upgrade migration: any queue rows currently parked in ERROR from a transport-level failure (unreachable, rate-limited, timeout, DNS, connection refused, HTTP 5xx / 429) get requeued automatically the first time this update loads. No manual "Reset errors" click needed.
* On the first successful compress after any future outage streak, ERROR rows caused by that outage are auto-rehabbed to PENDING.

= 1.0.3 =
* DB migration runner — fires on every plugin load (not just activation), so updates installed via Upload Plugin don't leave the schema behind.
* Backfills `ssim_history` from existing "done" queue rows on upgrade so the Optimized tab is populated immediately after updating from 1.0.0–1.0.2.
* Reconciles "Total optimized" and "Bytes saved" against the actual history rows on upgrade — fixes the dashboard / queue count mismatch when the running counter had drifted.
* New "Rebuild from queue & reconcile stats" button on the Optimized tab — re-runs the same backfill on demand.

= 1.0.2 =
* New "Optimized" tab — paginated table of every successfully compressed image with thumbnail, title, URLs, original/optimized size, and % savings.
* New `ssim_history` table — appended on every successful optimization, survives "Clear done/skipped" so the Optimized tab keeps its data.
* Scan is now crash-resilient: each tick wrapped in try/catch; a failing chunk is retried 3 times before being skipped, so a single bad attachment cannot stall the scan.
* Scan now has Pause / Resume buttons, and a "Retry failed sites" button surfaces after the scan completes if any chunks were skipped.
* Re-clicking "Start scan" while one is in progress no longer resets your offset — you can resume mid-scan even after refreshing the page.
* JS auto-retries AJAX failures during scan with exponential backoff; after 5 failed retries it auto-pauses the scan and surfaces the error.

= 1.0.1 =
* Network-wide media library scan when network-activated (previously only scanned the current blog).
* "Currently working on" list now shows the subsite name for each image.
* Broadened MIME match to include rare `image/jpg` variants.
* Scan progress shows a per-subsite breakdown when there's more than one site.

= 1.0.0 =
* Initial release.
