-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
REST API: Add action-delete flag to declare delete_post capability for post objects #335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1981,10 +1981,14 @@ protected function get_available_actions( $post, $request ) { | |
|
||
$post_type = get_post_type_object( $post->post_type ); | ||
|
||
if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) { | ||
if ( 'attachment' !== $this->post_type && current_user_can( 'publish_post', $post->ID ) ) { | ||
$rels[] = 'https://api.w.org/action-publish'; | ||
} | ||
|
||
if ( current_user_can( 'delete_post', $post->ID ) ) { | ||
$rels[] = 'https://api.w.org/action-delete'; | ||
} | ||
|
||
if ( current_user_can( 'unfiltered_html' ) ) { | ||
$rels[] = 'https://api.w.org/action-unfiltered-html'; | ||
} | ||
|
@@ -2462,6 +2466,20 @@ protected function get_schema_links() { | |
); | ||
} | ||
|
||
$links[] = array( | ||
'rel' => 'https://api.w.org/action-delete', | ||
'title' => __( 'The current user can delete this post.' ), | ||
'href' => $href, | ||
'targetSchema' => array( | ||
'type' => 'object', | ||
'properties' => array( | ||
'delete' => array( | ||
'type' => 'boolean', | ||
), | ||
), | ||
Comment on lines
+2475
to
+2479
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. This probably needs to be something else? 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. The idea of the Since a post is deleted by making a So we could drop the |
||
), | ||
); | ||
|
||
$links[] = array( | ||
'rel' => 'https://api.w.org/action-unfiltered-html', | ||
'title' => __( 'The current user can post unfiltered HTML markup and JavaScript.' ), | ||
|
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.
Since this is an action for the specific post we should use the meta cap and pass the post ID to the check. By default this just falls back to
publish_posts
.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.
Is this related to https://core.trac.wordpress.org/ticket/47443?