feat: migrate-from-smush + Picture-tag rewriter (v0.2.0)
Unblocks production use on sites previously running Smush.
migrate-from-smush:
- Reads wp-smpro-smush-data postmeta, writes _h4b_img_optim marker
- --dry-run / --force-rescan / --remove-smush-meta / --limit flags
- Verified: 100 attachments migrated cleanly on dev.rds.ink,
bulk count drops from 734 → 634
Picture_Tag rewriter:
- Hooks the_content + post_thumbnail_html + widget_text + Elementor
frontend + wp_get_attachment_image at priority 99
- Wraps <img> in <picture><source avif><source webp><img></picture>
when sibling files exist
- Double-wrap protection via byte-range tracking of existing <picture> blocks
- Per-image opt-out via data-no-h4b attribute
- Cached sibling lookups per request
- 8 edge-case tests pass
LOC: 2480 (was 1997). Adds class-cli-migrate.php (193 LOC) and
class-picture-tag.php (284 LOC).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
32
CHANGELOG.md
32
CHANGELOG.md
@@ -5,6 +5,38 @@ All notable changes to **h4b-image-optim** will be documented here.
|
||||
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.2.0] — 2026-05-19
|
||||
|
||||
Added migrate-from-smush + Picture-tag rewriter. The plugin is now usable
|
||||
end-to-end on a site that previously ran Smush — no double-processing, and
|
||||
WebP / AVIF actually get served to visitors.
|
||||
|
||||
### Added
|
||||
- **`wp h4b-img migrate-from-smush`** — reads Smush's `wp-smpro-smush-data`
|
||||
postmeta, writes equivalent `_h4b_img_optim` markers so our bulk command
|
||||
skips already-optimised attachments.
|
||||
- `--dry-run` to see counts only
|
||||
- `--force-rescan` to mark for re-optimisation instead (use when migrating
|
||||
off Smush completely)
|
||||
- `--remove-smush-meta` to delete the Smush postmeta after migration
|
||||
- **`Picture_Tag`** rewriter (the_content + post_thumbnail_html + widget_text +
|
||||
Elementor frontend + wp_get_attachment_image filters at priority 99). Wraps
|
||||
`<img>` tags with `<picture><source type="image/avif"><source type="image/webp"><img></picture>`
|
||||
when sibling files exist on disk.
|
||||
- Skips images already inside a `<picture>` block (double-wrap protection
|
||||
via byte-range tracking)
|
||||
- Skips images with `data-no-h4b` attribute (per-image opt-out)
|
||||
- Resolves siblings either alongside the JPG (`foo.jpg.webp`) or in Smush's
|
||||
`wp-content/smush-webp/` mirror tree
|
||||
- Caches sibling lookups per request to keep it cheap
|
||||
- Preserves srcset, sizes, alt, class, and all other original `<img>` attrs
|
||||
|
||||
### Verified
|
||||
- migrate-from-smush: 100 attachments migrated cleanly on dev.rds.ink
|
||||
- bulk count correctly drops after migration (734 → 634)
|
||||
- Picture_Tag: 8 edge-case tests pass (no siblings, multiple images, opt-out,
|
||||
srcset preservation, external URLs, no `<img>`, existing `<picture>`, mixed)
|
||||
|
||||
## [0.1.0] — 2026-05-19
|
||||
|
||||
Initial MVP. Replaces Smush Pro's optimisation pipeline without the
|
||||
|
||||
Reference in New Issue
Block a user