Skip to content

Try adding attachment trashable status to REST API - #9210

Closed
tellthemachines wants to merge 2 commits into
WordPress:trunkfrom
tellthemachines:try/media-trashable-status-in-REST-API
Closed

tellthemachines wants to merge 2 commits into
WordPress:trunkfrom
tellthemachines:try/media-trashable-status-in-REST-API

Conversation

@tellthemachines

@tellthemachines tellthemachines commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor

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


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.

@github-actions

github-actions Bot commented Jul 8, 2025

Copy link
Copy Markdown

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@mukeshpanchal27

Copy link
Copy Markdown
Member

The unit tests getting failed. Needs some updates in

public function test_get_item_schema() {

@rmccue

rmccue commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

For consistency, this should use the same behaviour as delete_item with the same filter:

/**
* Filters whether a post is trashable.
*
* The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
*
* Possible hook names include:
*
* - `rest_post_trashable`
* - `rest_page_trashable`
* - `rest_attachment_trashable`
*
* Pass false to disable Trash support for the post.
*
* @since 4.7.0
*
* @param bool $supports_trash Whether the post type support trashing.
* @param WP_Post $post The Post object being considered for trashing support.
*/
$supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post );

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.

@tellthemachines

Copy link
Copy Markdown
Contributor Author

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 😅

@Mamaduka

Mamaduka commented Oct 6, 2026

Copy link
Copy Markdown
Member

Came across this PR while searching for existing tickets. Here's an alternative using action links: #14033.

@tellthemachines

Copy link
Copy Markdown
Contributor Author

Closing in favour of #14033.

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.

4 participants