Repository navigation
REST API: Add the 'action-trash' link to posts and comments #14033
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,9 +455,8 @@ static function ( $format ) { | |
| add_filter( 'post_password_required', array( $this, 'check_password_required' ), 10, 2 ); | ||
| } | ||
|
|
||
| $posts = array(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| if ( ! $is_head_request ) { | ||
| $posts = array(); | ||
|
|
||
| update_post_author_caches( $query_result ); | ||
| update_post_parent_caches( $query_result ); | ||
|
|
||
|
|
@@ -2334,6 +2333,7 @@ protected function prepare_links( $post ) { | |
| * Gets the link relations available for the post and current user. | ||
| * | ||
| * @since 4.9.8 | ||
| * @since 7.2.0 Added the `action-trash` link relation. | ||
| * | ||
| * @param WP_Post $post Post object. | ||
| * @param WP_REST_Request $request Request object. | ||
|
|
@@ -2369,6 +2369,19 @@ protected function get_available_actions( $post, $request ) { | |
| } | ||
| } | ||
|
|
||
| if ( 'trash' !== $post->post_status && $this->check_delete_permission( $post ) ) { | ||
| $supports_trash = ( EMPTY_TRASH_DAYS > 0 ); | ||
|
|
||
| if ( 'attachment' === $post->post_type ) { | ||
| $supports_trash = $supports_trash && MEDIA_TRASH; | ||
| } | ||
|
|
||
| /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ | ||
| if ( apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post ) ) { | ||
| $rels[] = 'https://api.w.org/action-trash'; | ||
| } | ||
| } | ||
|
|
||
| $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); | ||
|
|
||
| foreach ( $taxonomies as $tax ) { | ||
|
|
@@ -2840,6 +2853,7 @@ public function get_item_schema() { | |
| * Retrieves Link Description Objects that should be added to the Schema for the posts collection. | ||
| * | ||
| * @since 4.9.8 | ||
| * @since 7.2.0 Added the `action-trash` link relation. | ||
| * | ||
| * @return array | ||
| */ | ||
|
|
@@ -2914,6 +2928,12 @@ protected function get_schema_links() { | |
| ); | ||
| } | ||
|
|
||
| $links[] = array( | ||
| 'rel' => 'https://api.w.org/action-trash', | ||
| 'title' => __( 'The current user can move this post to the trash.' ), | ||
| 'href' => $href, | ||
| ); | ||
|
|
||
| $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); | ||
|
|
||
| foreach ( $taxonomies as $tax ) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a minor fix to satisfy static checks.