Make WordPress Core

Opened 4 months ago

Last modified 3 months ago

#64677 new defect (bug)

Client-Side Media: Move `image_editor_output_format` filtering to the upload response

Reported by: adamsilverstein's profile adamsilverstein Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: needs-patch
Focuses: Cc:

Description

In #10868 (Editor: PHP backports for Client Side Media), the image_editor_output_format filter is currently applied in the REST API index (get_index) by iterating over a list of possible input MIME types with an empty $output_formats array and no $filename parameter. As noted in this review comment, this doesn't match how wp_get_image_editor_output_format() normally applies the filter — it passes the actual filename and a pre-populated default mapping.

Problem

The current approach:

  • Passes an empty array as the default value instead of the normal default mapping
  • Does not supply a $filename parameter to the filter
  • Re-filters the same $output_formats variable across iterations, accumulating results in a way that doesn't match the server-side behavior
  • Is applied generically rather than per-upload, so plugins can't make decisions based on the actual input file

Proposed Solution

Move the image_editor_output_format logic from the REST API index response into the initial image upload response. This is already the pattern used for EXIF rotation data in client-side media processing.

Benefits:

  • The actual input filename and MIME type will be available, so the filter operates just like it does on the server side
  • Plugins that hook into image_editor_output_format will receive meaningful parameters
  • Keeps per-file processing logic in the upload response where it belongs

References

Change History (6)

#1 @adamsilverstein
4 months ago

Note: this probably needs fixing in GB and core. I will probably start in GB then backport to core.

#2 @adamsilverstein
4 months ago

I created a matching Gutenberg issue which I will work on first, then backport the changes to core. https://github.com/WordPress/gutenberg/issues/75784

#3 @swissspidy
4 months ago

This was added to the index so that the desired output mapping is known client-side. Iif a plugin wants to convert all JPEGs to WebP for example, the client-side media handling can do it automatically.

Of course it's not possible to pass a filename in that case. Updating documentation accordingly is reasonable IMO.

Move the image_editor_output_format logic from the REST API index response into the initial image upload response

But then the image is already uploaded and you can't convert it in the browser anymore.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 months ago

#5 @suhan2411
3 months ago

I can reproduce the issue locally and would like to investigate moving the image_editor_output_format filtering earlier so it is reflected correctly in the upload response.

Working on a patch.

#6 @mukesh27
3 months ago

  • Milestone changed from 7.0 to Future Release
  • Version trunk deleted

Hi there!

We’re very close to RC1, and there’s still some work to be done.

Let’s move this to Future Release for now. Feel free to bring it back into the milestone if it’s ready to ship.

Note: See TracTickets for help on using tickets.