Opened 5 months ago
Closed 5 weeks ago
#64876 closed enhancement (worksforme)
Media: add filter on client-side supported MIME types
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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 (8)
This ticket was mentioned in PR #11277 on WordPress/wordpress-develop by @adamsilverstein.
5 months ago
#1
- Keywords has-patch has-unit-tests added
#4
@
3 months ago
Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.
#5
@
3 months ago
- Version trunk
Since this is an enhancement, there's no first version of WordPress this can be reproduced in. Removing trunk version.
@adamsilverstein commented on PR #11277:
8 weeks ago
#6
Closing - the upstream PR was closed.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## 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