Skip to content

REST API: Add 'scaled' to sideload route image_size enum#11015

Open
adamsilverstein wants to merge 6 commits intoWordPress:trunkfrom
adamsilverstein:add-scaled-to-sideload-route
Open

REST API: Add 'scaled' to sideload route image_size enum#11015
adamsilverstein wants to merge 6 commits intoWordPress:trunkfrom
adamsilverstein:add-scaled-to-sideload-route

Conversation

@adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Feb 23, 2026

Summary

When client-side media processing handles big image scaling, the client creates a -scaled version and sideloads it back via the REST API. The sideload route's image_size enum was missing scaled, causing 400 validation errors.

This PR:

  • Adds 'scaled' to the image_size enum in the sideload route registration
  • Adds handling in sideload_item() to record the original file as original_image and update the attachment to point to the scaled version
  • Updates the filter_wp_unique_filename() regex to recognize the -scaled suffix, preventing unwanted numeric suffixes

Test plan

  • Upload a large image (>2560px) with client-side media processing enabled
  • Confirm the scaled sideload request no longer returns a 400 error
  • Verify that other sideload image_sizes (thumbnail, medium, etc.) still work
  • Verify the attachment metadata correctly records original_image and the scaled file dimensions
  • Test with and without the Gutenberg plugin active

Trac ticket: https://core.trac.wordpress.org/ticket/64737

When client-side media processing handles big image scaling,
the client creates a -scaled version and sideloads it back.
The sideload route's image_size enum was missing 'scaled',
causing 400 validation errors.

This adds 'scaled' to the enum, adds handling in sideload_item()
to record the original file and update the attachment to point
to the scaled version, and updates the unique filename filter
regex to recognize the -scaled suffix.
@github-actions
Copy link

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

adamsilverstein and others added 5 commits February 26, 2026 18:15
Add 'scaled' to the image_size enum in wp-api-generated.js to match the
PHP route registration change, fixing the git diff --exit-code CI check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tests for the new 'scaled' image_size enum value in the sideload
endpoint: verifying metadata updates, authentication requirements,
route schema, and unique filename handling for the -scaled suffix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
get_attached_file() can return false when no file is
attached. Add a guard to return a WP_Error before calling
wp_basename() with a falsy value.
The sideload route uses edit_media_item_permissions_check
which returns rest_cannot_edit_image, not rest_forbidden.
/**
* Tests sideloading a scaled image for an existing attachment.
*
* @ticket 63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a TRAC ticket number from another repository?

Is this correct?

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.

2 participants