=== Auto WebP Conversion ===
Contributors: snehalpancholi
Tags: webp, image optimization, performance, picture element, media
Requires at least: 6.0
Tested up to: 6.7
Stable tag: 1.0.0
Requires PHP: 8.1
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Automatically converts uploaded JPEG and PNG images to WebP format and serves them via the HTML picture element — no server rewrites required.

== Description ==

**Auto WebP Conversion** is a lightweight, server-native plugin that converts your media library images to the modern WebP format. Unlike rewrite-rule-based approaches that require `.htaccess` or Nginx configuration, this plugin delivers WebP images using the HTML `<picture>` element with a JPEG/PNG fallback — ensuring every browser receives an image it can display.

**Key benefits:**

* Faster page loads — WebP images are typically 25–35% smaller than JPEG at equivalent visual quality.
* No server configuration needed — works on any shared host.
* Non-destructive — the original JPEG/PNG is always preserved alongside the WebP version.
* Browser-safe — older browsers receive the original image transparently.
* Bulk conversion tool — convert your entire existing media library in the WordPress admin.

**How it works:**

1. When a JPEG or PNG is uploaded, the plugin generates a `.webp` file alongside each registered image size.
2. In post content and template images (via `wp_get_attachment_image`), any `<img>` tag pointing to a JPEG/PNG that has a WebP counterpart is automatically wrapped in a `<picture>` element:

```html
<picture>
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.jpg" alt="...">
</picture>
```

Browsers that support WebP load the smaller file; others fall back to the original silently.

== Installation ==

1. Upload the `auto-webp-conversion` folder to your `/wp-content/plugins/` directory, or install via the Plugins screen in WordPress admin.
2. Activate the plugin.
3. Go to **Media → WebP Conversion** to confirm your server supports WebP generation.
4. Adjust settings (quality, sizes) and click **Save Settings**.
5. Click **Convert All Images** to generate WebP versions of your existing media library.
6. New uploads will be converted automatically going forward.

== Frequently Asked Questions ==

= Does this require server configuration (`.htaccess` / Nginx rewrites)? =

No. Unlike some WebP plugins that rely on server-level URL rewriting to transparently swap images, this plugin uses the HTML `<picture>` element which is handled entirely in the browser. No server configuration changes are needed.

= What if the visitor's browser does not support WebP? =

The `<picture>` element includes the original JPEG or PNG as a fallback `<img>` tag. Browsers that do not support WebP (or do not recognise the `<source type="image/webp">`) will display the original image automatically. No JavaScript is involved.

= Does it affect my SEO? =

No. The original `<img>` tag and its `alt`, `title`, and other attributes are preserved intact inside the `<picture>` element. Search engines index the `<img>` element and read attributes normally. Serving smaller images also improves Core Web Vitals scores (LCP), which positively affects search rankings.

= What server requirements are needed for WebP generation? =

Your server needs either:

* **Imagick** PHP extension compiled with WebP support (recommended), or
* **GD** library compiled with `libwebp` support (the `imagewebp()` function must be available).

The plugin's admin page shows a green or red banner indicating whether WebP generation is possible on your server.

= Does it convert existing images? =

Yes. Use the **Bulk Convert** tool under **Media → WebP Conversion** to process your existing media library. Images that already have WebP versions are automatically skipped.

= Are the original files affected? =

Never. Original JPEG and PNG files are read-only during conversion. WebP files are generated alongside them (e.g. `photo.jpg` and `photo.webp` in the same directory). Deleting a WebP file does not affect the original.

= What happens when I delete an image from the media library? =

If the **Delete WebP on Attachment Delete** setting is enabled (the default), the plugin deletes all WebP files associated with that attachment when you remove it from the media library.

= Can I choose which image sizes to convert? =

Yes. Under Settings you can choose to convert all registered sizes (the default) or select specific sizes only. The original full-size file is always included when converting.

== Screenshots ==

1. **Admin page — WebP support banner and stats row.** Shows green confirmation, total images in library, converted count, WebP files on disk, and disk usage.
2. **Bulk Convert tool.** Progress bar updates in real time as each image is processed, with a per-image result table showing converted/skipped/failed counts.
3. **Settings panel.** Quality slider, toggle options for auto-convert, picture-element wrapping, delete-on-remove, and image size selector.

== Changelog ==

= 1.0.0 =
* Initial release.
* On-upload automatic WebP generation via Imagick or GD.
* `<picture>` element wrapping for post content and `wp_get_attachment_image` output.
* Srcset WebP replacement where WebP counterparts exist.
* Bulk conversion tool with real-time progress bar and result log.
* Admin stats dashboard (total images, converted count, WebP files, disk usage).
* Delete WebP files when attachment is removed from media library.
* Image-size-specific conversion filter.
* Update checker for automatic plugin updates from AddonLogic.

== Upgrade Notice ==

= 1.0.0 =
First public release — no upgrade steps required.
