Skip to content

REST API: Support registering one sideloaded file under multiple sizes (backport GB #77036)#49

Open
adamsilverstein wants to merge 1 commit into
backport/75888-sideload-finalizefrom
backport/77036-multi-size
Open

REST API: Support registering one sideloaded file under multiple sizes (backport GB #77036)#49
adamsilverstein wants to merge 1 commit into
backport/75888-sideload-finalizefrom
backport/77036-multi-size

Conversation

@adamsilverstein
Copy link
Copy Markdown
Owner

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

  • 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 (via wp_parse_list()), a oneOf/multi-type schema cannot enforce the enum on its own. The enum is validated per-item via a validate_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 special original/scaled keys remain scalar).

Notes

  • The JS counterpart (client-side grouping of matching sizes) ships via the Gutenberg → Core package sync.
  • Tests: added test_sideload_image_size_array and test_sideload_image_size_invalid. Validated locally with php -l + PHPCS (WordPress-Core). Full PHPUnit runs in upstream CI.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca26f9a0-8b81-4278-a254-300942b13d9a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backport/77036-multi-size

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant