Opened 11 hours ago
Last modified 98 minutes ago
#66027 new enhancement
REST API: let the media create endpoint record the attachment an upload was edited from
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | REST API | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | rest-api |
Description
Claude Code drafted this ticket from the Gutenberg change, forwarded along:
With client-side media processing, Gutenberg is moving image edits (crop, rotate, flip) from the server
media/<id>/editendpoint into the browser: the edit is applied with libvips and the result is uploaded throughPOST /wp/v2/mediaas a new attachment, the same way the editor has always created edited images. See https://github.com/WordPress/gutenberg/pull/82362 (fixes https://github.com/WordPress/gutenberg/issues/82295, where server-side edits strip the gain map from HDR JPEGs).
One thing the
/editendpoint does that the upload endpoint cannot is record where the new image came from: it stores aparent_imageentry (attachment_idand the source's relativefilepath) in the new attachment's metadata, copies the source's EXIFimage_metafor any field the new file lacks, and resets the orientation to 1. Edits made in the browser should relate to their source the same way.
Proposed change: add an optional
parent_imageinteger parameter to the media create endpoint. When set, it must reference an existing image attachment the current user can edit (matching the/editpermission check), and after the upload the new attachment's metadata gets the sameparent_imageentry and EXIF carry-over thatedit_media_item()writes. Without the parameter nothing changes.
Related: #65367 (client-side media processing endpoints).
Patch incoming.
Change History (2)
This ticket was mentioned in PR #13372 on WordPress/wordpress-develop by @adamsilverstein.
11 hours ago
#1
@ugyensupport commented on PR #13372:
98 minutes ago
#2
Manually tested against a local WP 7.1-trunk install (Studio site, real DB/uploads, no git checkout available so I hand-applied this diff — context matched cleanly).
Ran the PR's own scenarios via wp eval-file directly through the REST dispatcher (rest_get_server()->dispatch()), same as the added PHPUnit tests:
| Scenario | Result |
|---|---|
Upload with parent_image set → metadata + response carry parent_image, EXIF credit copied from source, orientation reset to 1 | ✅ 201 |
Upload with no parent_image → nothing recorded | ✅ 201, key absent |
parent_image points at a non-image post | ✅ 400 rest_invalid_param
|
parent_image points at another user's attachment the current user can't edit | ✅ 403 rest_cannot_edit_image
|
Schema exposes parent_image (type: integer, minimum: 1) in CREATABLE args | ✅ |
All 5 passed. php -l clean. Behavior matches the ticket description and mirrors edit_media_item()'s handling faithfully.
🤖 Generated with Claude Code
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Companion to https://github.com/WordPress/gutenberg/pull/82362.
_Claude Code wrote this up from the Gutenberg change:_
## AI Use
Code and description both written with 🤖 Claude Code. I will review and test.