mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Prevent deletion of post revisions.
Allowing the client to delete revisions breaks the "audit trail" functionality. This is not allowed in WordPress and shouldn't be allowed through the API. While not recommended, a plugin may opt-in to the previous behavior by setting a custom 'delete_post' capability for the revisions post type. Props dlh, danielbachhuber, TimothyBlynJacobs, azaozz, kadamwhite. Fixes #43709. git-svn-id: https://develop.svn.wordpress.org/trunk@45812 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -349,6 +349,11 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
||||
return $parent;
|
||||
}
|
||||
|
||||
$parent_post_type = get_post_type_object( $parent->post_type );
|
||||
if ( ! current_user_can( $parent_post_type->cap->delete_post, $parent->ID ) ) {
|
||||
return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
$revision = $this->get_revision( $request['id'] );
|
||||
if ( is_wp_error( $revision ) ) {
|
||||
return $revision;
|
||||
@@ -383,7 +388,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
||||
}
|
||||
|
||||
$post_type = get_post_type_object( 'revision' );
|
||||
return current_user_can( $post_type->cap->delete_post, $revision->ID );
|
||||
|
||||
if ( ! current_user_can( $post_type->cap->delete_post, $revision->ID ) ) {
|
||||
return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this revision.' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user