[wp-trac] [WordPress Trac] #56442: Ensure `wp_editor_set_quality` filter consistently passes output mime type
WordPress Trac
noreply at wordpress.org
Fri Sep 16 18:56:25 UTC 2022
#56442: Ensure `wp_editor_set_quality` filter consistently passes output mime type
--------------------------------------+------------------------------
Reporter: adamsilverstein | Owner: adamsilverstein
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 6.1
Component: Media | Version: 5.8
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Comment (by adamsilverstein):
[attachment:"56442.diff"]:
* Add a new test `test_quality_with_image_conversion_file_sizes` to verify
that the `wp_editor_set_quality` correctly passes the mime type and
applies correctly:
- uses the `image_editor_output_format` filter to generate both JPEG and
WebP sub sizes for a test image (including a `-scaled` version).
- sets quality very low for JPEG and very high for WebP and verifies
that the file sizes are all larger for the WebP generated files.
- Update `WP_Image_Editor::set_quality` to set the output type by calling
`get_output_format`.
These tests fail in trunk because the mime type is not set to the output
type early enough - the first time it is called for WebP (for each editor
initialization), the mime type was set to JPEG even if the eventual output
was in WebP. Therefore, certain image sizes were using the JPEG quality
setting, not the expected WebP quality setting.
Previous tests for mime type in wp_editor_set_quality weren't catching
this because they didn't look at all runs of the filter. The new test
looks at all generated sizes.
The fix is a [https://github.com/WordPress/wordpress-
develop/pull/3250/files#diff-
ade9004b026644e1dcaad2085e43797fd06eb3595c7b5ae0f4c033d046b235c1R264
single line] change to call `get_output_format` in set_quality. This
ensures that `$this->output_format` is properly set on the next line and
the correct mime type is used. After this change, the test passes - the
correct mime type is passed to the filter..
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56442#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list