Opened 3 weeks ago
Last modified 3 days ago
#64677 new defect (bug)
Client-Side Media: Move `image_editor_output_format` filtering to the upload response
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| 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
$filenameparameter to the filter - Re-filters the same
$output_formatsvariable 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_formatwill receive meaningful parameters - Keeps per-file processing logic in the upload response where it belongs
References
- PR: #10868
- Review: @westonruter's comment
- Response: @adamsilverstein's response
Change History (5)
#2
@
3 weeks 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
@
3 weeks 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.
Note: this probably needs fixing in GB and core. I will probably start in GB then backport to core.