REST API: Support registering one sideloaded file under multiple sizes (backport GB #77036)#49
Open
adamsilverstein wants to merge 1 commit into
Open
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
8245308 to
658fa47
Compare
5 tasks
Backport of Gutenberg PR #77036. When several registered image sizes share the same dimensions, the client generates a single physical file and sends its size names as an array, so the file is registered once and referenced under every matching size. The sideload endpoint's `image_size` parameter (and the finalize endpoint's `sub_sizes[].image_size`) now accept a string or an array of strings. Because rest_is_array() treats scalar strings as single-element lists, the enum is enforced via a validate_callback rather than a oneOf schema. sideload_item() and finalize_item() register the file under each name when an array is given.
9249e4f to
93c823b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Core backport of Gutenberg #77036 — Deduplicate client-side image sizes with matching dimensions.
Stacked on #48 (backport of GB #75888). Review/merge that first; this PR's base is
backport/75888-sideload-finalize. Part of the client-side-media restore stack (#11324).Why
When several registered image sizes resolve to the same dimensions (width, height, crop), generating a separate file per size is wasteful. The client groups them and uploads one file, then registers it under every matching size name.
How
image_sizeparameter and the finalize endpoint'ssub_sizes[].image_sizenow accept a string or an array of strings.rest_is_array()treats scalar strings as single-element lists (viawp_parse_list()), aoneOf/multi-type schema cannot enforce the enum on its own. The enum is validated per-item via avalidate_callback, which also picks up sizes registered after route registration (e.g.add_image_size()).sideload_item()returns the shared sub-size payload for an array;finalize_item()writes the file under each size name. Arrays only carry regular sub-sizes (the specialoriginal/scaledkeys remain scalar).Notes
test_sideload_image_size_arrayandtest_sideload_image_size_invalid. Validated locally withphp -l+ PHPCS (WordPress-Core). Full PHPUnit runs in upstream CI.