Skip to content

Commit

Permalink
Ensure that a user can publish_posts before making a post sticky.
Browse files Browse the repository at this point in the history
Props: danielbachhuber, whyisjake, peterwilson, xknown.


git-svn-id: https://develop.svn.wordpress.org/branches/5.3@46897 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
whyisjake committed Dec 12, 2019
1 parent 4c285eb commit 1d1d5be
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function create_item_permissions_check( $request ) {
return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
}

if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
}

Expand Down Expand Up @@ -653,7 +653,7 @@ public function update_item_permissions_check( $request ) {
return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
}

if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
}

Expand Down Expand Up @@ -955,7 +955,7 @@ protected function prepare_date_response( $date_gmt, $date = null ) {
* @return stdClass|WP_Error Post object or WP_Error.
*/
protected function prepare_item_for_database( $request ) {
$prepared_post = new stdClass;
$prepared_post = new stdClass();

// Post ID.
if ( isset( $request['id'] ) ) {
Expand Down

0 comments on commit 1d1d5be

Please sign in to comment.