Repository navigation
REST API: Use wp_get_image_editor_output_format() for image_output_format and image_quality fields - #14614
REST API: Use wp_get_image_editor_output_format() for image_output_format and image_quality fields#14614robelsust wants to merge 1 commit into
Conversation
…rmat and image_quality fields. In WP_REST_Attachments_Controller::prepare_item_for_response(), use wp_get_image_editor_output_format() to retrieve output formats instead of manually seeding apply_filters( 'image_editor_output_format' ). This provides full parity with WP_Image_Editor::get_output_format(), ensuring plugins using array union (+) without overwriting keys are evaluated correctly. See #64677.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Description
In
WP_REST_Attachments_Controller::prepare_item_for_response(), theimage_output_formatandimage_qualityfields directly calledapply_filters( 'image_editor_output_format', array( $mime_type => $mime_type ), ... ).Seeding the filter with
array( $mime_type => $mime_type )causes issues for plugins that add mappings using array union (+) rather than key assignment (e.g.,add_filter( 'image_editor_output_format', fn( $formats ) => $formats + [ 'image/jpeg' => 'image/webp' ] )). Because$mime_typewas already present as a key in the seeded array, the union operator would preserve the original MIME type instead of the plugin's mapped format.This PR replaces those direct
apply_filters()calls withwp_get_image_editor_output_format( $filename ? $filename : '', $mime_type ). This aligns the REST API behavior withWP_Image_Editor::get_output_format(), which also relies onwp_get_image_editor_output_format().Changes
WP_REST_Attachments_Controller::prepare_item_for_response()insrc/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.phpto usewp_get_image_editor_output_format().WP_Image_Editor::get_output_format().test_image_output_format_with_array_union_filter()intests/phpunit/tests/rest-api/rest-attachments-controller.phpcovering filters using array union (+).Testing Instructions
test_image_output_format_and_progressive_defaults_in_create_responsetest_image_output_format_with_custom_filtertest_image_output_format_with_array_union_filtertest_image_save_progressive_with_custom_filtertest_image_output_format_skipped_for_non_imageTrac ticket: https://core.trac.wordpress.org/ticket/64677