WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 4 months ago

Last modified 3 months ago

#44405 closed feature request (fixed)

Updating/Cropping Images via Rest API

Reported by: apermo Owned by: TimothyBlynJacobs
Milestone: 5.5 Priority: normal
Severity: normal Version: 4.9.6
Component: REST API Keywords: has-patch has-unit-tests has-dev-note
Focuses: Cc:

Description

At the current moment it is not possible to update an attachment via the rest API, so if using the WordPress Crop Image functionality, there is no way to update the existing media.

I discussed this at WCEU in Belgrade with Mike Schroder. This was obviously simply forgotten.

Change History (17)

This ticket was mentioned in Slack in #core-media by apermo. View the logs.


2 years ago

#2 @joemcgill
2 years ago

I'd like to see these actions be supported by the REST API. The functionality can mirror wp_ajax_image_editor(), generally and would allow us to build new interfaces on top of the REST API rather than AJAX callbacks, and extend that ability to other clients.

This ticket was mentioned in Slack in #core-restapi by apermo. View the logs.


2 years ago

This ticket was mentioned in Slack in #core-editor by joemcgill. View the logs.


9 months ago

This ticket was mentioned in Slack in #core-restapi by joemcgill. View the logs.


9 months ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


5 months ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-restapi by azaozz. View the logs.


4 months ago

#9 @azaozz
4 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.5

https://github.com/WordPress/gutenberg/blob/master/lib/class-wp-rest-image-editor-controller.php is ready for adding to trunk. Works with the current image editor in the block editor (the JS for it is already in).

This ticket was mentioned in PR #388 on WordPress/wordpress-develop by TimothyBJacobs.


4 months ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

Porting the edit image endpoint from [Gutenberg](https://github.com/WordPress/gutenberg/blob/21709e3c533e78f9e63c583b6109caadc7cdf7be/lib/class-wp-rest-image-editor-controller.php).

This is a WIP, working on adding tests. One question I had was the descriptions of the request args, I did my best to add them based on my understanding of how the endpoint works, but that might not be accurate.

Cc: @ajlende.

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

#11 @prbot
4 months ago

azaozz commented on PR #388:

Looks good, just one small nitpick :)

Will also need to verify that $image_meta is actually for the same image as it is retrieved by using the attachment ID that is hard-coded in post_content. (Can patch that in trunk. There is another patch that needs the same and will have to make a new function.)

#12 @prbot
4 months ago

TimothyBJacobs commented on PR #388:

Should we be checking against upload_is_user_over_quota @azaozz?

#13 @prbot
4 months ago

azaozz commented on PR #388:

Should we be checking against upload_is_user_over_quota

Possibly, but seems better to let the user edit the image, and decide if they should delete the parent image? Users can get over the quota even when uploading a large image that creates many sub-sizes...

#14 @prbot
4 months ago

TimothyBJacobs commented on PR #388:

Possibly, but seems better to let the user edit the image, and decide if they should delete the parent image? Users can get over the quota even when uploading a large image that creates many sub-sizes...

Gotcha. I'll leave it alone for now then.

This works for me testing against the latest Gutenberg. It still doesn't work alone on trunk since the JS in trunk is still expecting the old endpoint.

#15 @TimothyBlynJacobs
4 months ago

  • Owner set to TimothyBlynJacobs
  • Resolution set to fixed
  • Status changed from new to closed

In 48291:

REST API: Introduce endpoint for editing images.

To facilitate inline image editing in Gutenberg, a new endpoint at wp/v2/media/<id>/edit has been introduced. This is functionally similar to the existing ajax image editor, however the REST API editor creates a new attachment record instead of updating an existing attachment.

Fixes #44405.
Props ajlende, ellatrix, spacedmonkey, azaozz.

#16 @azaozz
3 months ago

In 48518:

REST API, Media: Fix/improve the inline docs and name of the new wp_edited_image_metadata filter.

Props desrosj, azaozz.

See #44405.

Note: See TracTickets for help on using tickets.