Make WordPress Core

Opened 4 months ago

Last modified 4 months ago

#63670 new enhancement

Add trashability to REST API posts controller

Reported by: isabel_brison's profile isabel_brison Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords: has-patch
Focuses: Cc:

Description (last modified by isabel_brison)

Would be good to have a trashable property to the posts schema that checks the "rest_{$this->post_type}_trashable" filter and, in the case of attachment post type, the MEDIA_TRASH constant too.

This will be needed to display the correct actions for media items in data views, and also for other post types to which the filter may be applied.

Change History (7)

This ticket was mentioned in PR #9210 on WordPress/wordpress-develop by @isabel_brison.


4 months ago
#1

  • Keywords has-patch added

Adding a trashable property to the attachment schema that checks the MEDIA_TRASH constant.

Will be needed to display the correct actions for media items in data views.

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

@rmccue commented on PR #9210:


4 months ago
#3

For consistency, this should use the same behaviour as delete_item with the same filter:
https://github.com/WordPress/wordpress-develop/blob/cddf5d8e55bdd1b675b58be89b798dfc615f9c7d/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1091-L1109

Given that this isn't directly part of the data, imo it would make most sense to handle this via get_available_actions() and expose it as a self-link, rather than a field in the post.

@isabel_brison commented on PR #9210:


4 months ago
#4

Given that this isn't directly part of the data, imo it would make most sense to handle this via get_available_actions() and expose it as a self-link, rather than a field in the post.

Hmm yeah I wondered about that, but get_available_actions deals more with actions the user has permission for, whereas MEDIA_TRASH and the trashable hook are post type-related settings.

If I'm honest I also don't love the ergonomics of exposing actions as links considering that we're usually looking for a boolean value, and we're having to sort of deduce it from the existence of a link 😅

#5 @spacedmonkey
4 months ago

@isabel_brison When you assign reviewer, can you assign the maintainers of the REST API as well please.

#6 @isabel_brison
4 months ago

@spacedmonkey sorry about that! I've been away from core for some months and guess that was enough to forget procedures :')

Which of the REST API maintainers are active besides Ryan (who has commented already) and yourself? I'd be happy to have your thoughts on the PR btw!

#7 @isabel_brison
4 months ago

  • Description modified (diff)
  • Summary changed from Add trashability to REST API attachment controller to Add trashability to REST API posts controller

Thinking about this more, and on a suggestion by @talldanwp, I'm updating the scope of this ticket to apply not just to the attachment controller, but to the posts controller. The logic is that there are other default post types not trashable by default (such as templates), but the "rest_{$this->post_type}_trashable" could potentially be used to change this for any post type.

Note: See TracTickets for help on using tickets.