-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Media / Attachments REST API endpoint: update attachments controller to support flip and to customize attachment fields #10041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
|
I like this change, I think it's going to be really useful to be able to add both For some of the failures, it looks like the
|
|
Ah, it looks like you can update the fixtures by running the PHP tests locally, but specifically the following appears to just run the init tests to regenerate those fixtures: |
Thanks! I had to look up a previous comment of mine to remind myself how to do it 😄 |
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Show resolved
Hide resolved
9b54e33 to
7732842
Compare
andrewserong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing great for me, and the code change looks good!
For testing within a JS context, I opened up the post editor, and did the following:
First, I added an image in the media library and grabbed its id from the URL. Then, opened up the block editor, and called the following in my browser console to grab the full source url (in my case the image id was 27) from media_details.sizes.full.source_url:
wp.apiFetch( { path: '/wp/v2/media/27' } );
Next, I ran the following using the url I copied above for the src param:
wp.apiFetch( { path: '/wp/v2/media/27/edit', method: 'POST', data: { flip: { 'horizontal': true, 'vertical': true }, src: 'http://localhost:8889/wp-content/uploads/2025/09/denver-airport-scaled.jpg' } } );
Then, I opened up the media library, and took a look at the newly created image, and the correct flip had been applied. I also manually tried the above snippet adding other fields (e.g. alt_text, caption, etc), and all worked nicely.
LGTM! I think between the added flip support and the ability to add metadata at the same time, it'll unlock some useful behaviour for future media library / editor explorations, but also should be useful for other kinds of consumers of the endpoint.
|
I'll merge this today. Thanks! |
…d attachments in the REST API. This update introduces the ability to flip images both vertically and horizontally through the REST API. Additionally, it allows for the editing of attachment fields such as title, caption, description, and alt text when creating new attachments. Fixes #64035.
…tication endpoints.
…lean values instead of integers. Update related tests to reflect changes in parameter types and description
…ng unnecessary whitespace at the end of a method.
…nd corresponding test fixture to remove unnecessary details.
7732842 to
73578f1
Compare
|
Committed in r60908 |
What?
This PR is the first step to enhance media editor capabilities as described in #55238 Phase 3: Collaboration > Media Library.
It adds the following functionality:
caption,description, andtitle,postandalt_textfields.Why?
As outlined in WordPress/gutenberg#55238, the extended functionality will allow folks to start experimenting with a redesigned media library.
It will also allow flip controls in the existing image block toolbar.
Testing Instructions
Unit tests
npm run test:php -- --filter WP_Test_REST_Attachments_ControllerManual testing
Check that existing use of the
media/{$id}/editendpoint has no regressions:media/{$id}/edittook place with the correct payload./wp-admin/upload.phpTrac ticket: https://core.trac.wordpress.org/ticket/64035
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.