Opened 2 months ago
Last modified 8 hours ago
#64876 new enhancement
Media: add filter on client-side supported MIME types
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Media | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
Description
Currently, the list of MIME types supported by client-side media processing (via WebAssembly-based vips) is hardcoded. This makes it impossible for plugins to add support for additional formats or restrict processing to a subset of formats.
This ticket adds a client_side_supported_mime_types filter that allows plugins to customize which image formats are processed client-side. The filtered list is exposed via the REST API root index endpoint (for users with the upload_files capability) and consumed by the JavaScript upload media store.
Changes
REST API (class-wp-rest-server.php)
- Add
client_side_supported_mime_typesfield to the REST API root index response - Add
client_side_supported_mime_typesfilter with default value:['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif'] - Only exposed when
current_user_can( 'upload_files' )
Preload paths (edit-form-blocks.php, site-editor.php)
- Add
client_side_supported_mime_typesto the preloaded root fields list in both the post editor and site editor - Required so the preloaded URL matches the JavaScript request, avoiding an extra fetch on editor load
Example usage
<?php // Remove AVIF from client-side processing. add_filter( 'client_side_supported_mime_types', function ( $mime_types ) { return array_diff( $mime_types, array( 'image/avif' ) ); } );
<?php // Add HEIC to client-side processing. add_filter( 'client_side_supported_mime_types', function ( $mime_types ) { $mime_types[] = 'image/heic'; return $mime_types; } );
Props
adamsilverstein
Related
Change History (5)
This ticket was mentioned in PR #11277 on WordPress/wordpress-develop by @adamsilverstein.
2 months ago
#1
- Keywords has-patch has-unit-tests added
## Summary
Add a
client_side_supported_mime_typesfilter and REST API index field so plugins can customize which image formats are processed client-side via WebAssembly-based vips.client_side_supported_mime_typesfilter with default list:image/jpeg,image/png,image/gif,image/webp,image/avifupload_filescapability)## Changes
src/wp-includes/rest-api/class-wp-rest-server.php— Add filter and REST index fieldsrc/wp-admin/edit-form-blocks.php— Add field to preload pathssrc/wp-admin/site-editor.php— Add field to preload pathstests/qunit/fixtures/wp-api-generated.js— Update test fixture## Related