Make WordPress Core

Ticket #48764: class-wp-rest-posts-controller.php.patch

File class-wp-rest-posts-controller.php.patch, 2.2 KB (added by djzone, 5 years ago)
  • class-wp-rest-posts-controller.php

    old new  
    10091009
    10101010               // Post status.
    10111011               if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
    1012                        $status = $this->handle_status_param( $request['status'], $post_type );
     1012                       $status = $this->handle_status_param( $request['status'], $post_type, $request['id'] );
    10131013
    10141014                       if ( is_wp_error( $status ) ) {
    10151015                               return $status;
     
    11451145        * @param object $post_type   Post type.
    11461146        * @return string|WP_Error Post status or WP_Error if lacking the proper permission.
    11471147        */
    1148        protected function handle_status_param( $post_status, $post_type ) {
     1148       protected function handle_status_param( $post_status, $post_type, $ID ) {
    11491149
    11501150               switch ( $post_status ) {
    11511151                       case 'draft':
    11521152                       case 'pending':
    11531153                               break;
    11541154                       case 'private':
    1155                                if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
     1155                               if ( ! current_user_can( $post_type->cap->publish_posts, $ID ) ) {
    11561156                                       return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) );
    11571157                               }
    11581158                               break;
    11591159                       case 'publish':
    11601160                       case 'future':
    1161                                if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
     1161                               if ( ! current_user_can( $post_type->cap->publish_posts, $ID ) ) {
    11621162                                       return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) );
    11631163                               }
    11641164                               break;