WordPress plugin that converts JPEG/PNG to WebP in the browser on upload
  • PHP 54%
  • TypeScript 42.9%
  • SCSS 3.1%
Find a file
2026-04-12 18:56:17 +10:00
.claude Initial commit 2026-04-12 17:35:42 +10:00
.cursor Initial commit 2026-04-12 17:35:42 +10:00
dist Initial commit 2026-04-12 17:35:42 +10:00
resources Initial commit 2026-04-12 17:35:42 +10:00
src Initial commit 2026-04-12 17:35:42 +10:00
templates/admin Initial commit 2026-04-12 17:35:42 +10:00
tests Update to version 1.2.14: Enhance bootstrap process to handle missing vendor directory gracefully and add fallback autoloader. Introduce PluginBootstrapTest to verify plugin class loading. 2026-04-12 18:56:17 +10:00
.gitignore Initial commit 2026-04-12 17:35:42 +10:00
changelog.txt Update to version 1.2.14: Enhance bootstrap process to handle missing vendor directory gracefully and add fallback autoloader. Introduce PluginBootstrapTest to verify plugin class loading. 2026-04-12 18:56:17 +10:00
CLAUDE.md Initial commit 2026-04-12 17:35:42 +10:00
composer.json Initial commit 2026-04-12 17:35:42 +10:00
composer.lock Initial commit 2026-04-12 17:35:42 +10:00
LICENSE Initial commit 2026-04-12 17:35:42 +10:00
package-lock.json Initial commit 2026-04-12 17:35:42 +10:00
package.json Initial commit 2026-04-12 17:35:42 +10:00
phpunit.xml.dist Initial commit 2026-04-12 17:35:42 +10:00
README.md Initial commit 2026-04-12 17:35:42 +10:00
tsconfig.json Initial commit 2026-04-12 17:35:42 +10:00
vite.admin.config.ts Initial commit 2026-04-12 17:35:42 +10:00
vite.config.ts Initial commit 2026-04-12 17:35:42 +10:00
vitest.config.ts Initial commit 2026-04-12 17:35:42 +10:00
webp-upload-optimizer.php Update to version 1.2.14: Enhance bootstrap process to handle missing vendor directory gracefully and add fallback autoloader. Introduce PluginBootstrapTest to verify plugin class loading. 2026-04-12 18:56:17 +10:00

WebP Upload Optimizer

WordPress plugin that converts JPEG/PNG to WebP in the browser on upload (inspired idea by Cimo).

Legacy media: JPEG/PNG that were never processed by this plugin can be optimized from the Media modal sidebar, the attachment edit screen, or the Media Library row action. The browser converts to WebP, POST wuo/v1/attachments/{id}/replace-with-webp replaces the files and rewrites known URL references in core tables (serialized meta is handled safely). Review staging first on large sites; CDN/offload or custom DB tables may need extra handling via filters (wuo/legacy_replace/url_pairs, wuo/legacy_replace/expanded_pairs, wuo/legacy_replace_completed).

Requirements

  • WordPress 6.4+, PHP 8.2+
  • Node 20+ and Composer for building/testing
  • Chromium-based or Firefox admin (Safari may skip WebP canvas export)

Activate WebP Upload Optimizer in wp-admin, then configure Settings → WebP Upload.

Scripts

Command Purpose
npm run build Vite → dist/ (upload bridge + admin-settings.css)
npm run dev Watch build
npm run typecheck tsc --noEmit
npm test Vitest
composer test PHPUnit (needs WP)

TypeScript layout (resources/ts/)

Path Role
main.ts Vite entry: loads Window typings, global SCSS, runs app/bootstrap.
app/bootstrap.ts Wires upload hooks, wrapBlockEditorUploadMedia, block-editor iframe, media sidebar, attachment legacy panel.
upload/ Client-side conversion (image-converter.ts), drop/file hooks (hooks.ts), progress UI, REST metadata queue.
admin/ Media modal sidebar, attachment edit legacy UI, legacy-replace REST client, styles-entry.ts (admin SCSS only).
lib/ settings, wp-hooks, format-bytes, dimensions, upgrade-fetch-url, parse-rest-json.
types/ Conversion result types + window-augment.ts for wuoSettings / wuoMetadataCache.
__tests__/ Vitest unit tests.

Extending

WordPress wp.hooks filters (same naming style as core packages):

Name Description
wuo/upload/dropZoneSelectors string[] CSS selectors for drag-drop targets
wuo/upload/fileInputSelectors string[] for <input type="file"> contexts
wuo/upload/wrapMediaUtils Return false to skip wrapping both wp.mediaUtils.uploadMedia and core/upload-media addItems
wuo.convertImage.prepare Async filter: (file, 'webp', {}) → File
wuo/mediaSidebar/doRender Return false to hide the attachment sidebar block

PHP:

Filter / action Description
wuo/metabox/do_render Return false to hide meta box

REST: POST /wp-json/wuo/v1/metadata with { "metadata": [ { "filename": "…", … } ] } (used internally after upload).

Author

Ryan Allen — https://rallendev.com

License

MIT. See LICENSE.