Make WordPress Core

Opened 2 months ago

Last modified 8 hours ago

#64876 new enhancement

Media: add filter on client-side supported MIME types

Reported by: adamsilverstein's profile adamsilverstein Owned by:
Milestone: 7.1 Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description (last modified by adamsilverstein)

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_types field to the REST API root index response
  • Add client_side_supported_mime_types filter 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_types to 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

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_types filter and REST API index field so plugins can customize which image formats are processed client-side via WebAssembly-based vips.

  • Adds client_side_supported_mime_types filter with default list: image/jpeg, image/png, image/gif, image/webp, image/avif
  • Exposes the filtered value in the REST API root index response (for users with upload_files capability)
  • Updates preload paths in both post editor and site editor to include the new field

## Changes

  • src/wp-includes/rest-api/class-wp-rest-server.php — Add filter and REST index field
  • src/wp-admin/edit-form-blocks.php — Add field to preload paths
  • src/wp-admin/site-editor.php — Add field to preload paths
  • tests/qunit/fixtures/wp-api-generated.js — Update test fixture

## Related

#2 @adamsilverstein
2 months ago

  • Description modified (diff)
  • Keywords has-patch has-unit-tests removed

#3 @adamsilverstein
2 months ago

  • Description modified (diff)

#4 @audrasjb
18 hours ago

Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.

#5 @desrosj
8 hours ago

  • Version trunk deleted

Since this is an enhancement, there's no first version of WordPress this can be reproduced in. Removing trunk version.

Note: See TracTickets for help on using tickets.