Opened 7 months ago
Last modified 6 months ago
#64677 new defect (bug)
Client-Side Media: Move `image_editor_output_format` filtering to the upload response
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | Focuses: |
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 (6)
#2
@
7 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
@
7 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Note: this probably needs fixing in GB and core. I will probably start in GB then backport to core.