Make WordPress Core

Ticket #48764: 48764.patch

File 48764.patch, 1.9 KB (added by dkarfa, 5 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

     
    10131013
    10141014                // Post status.
    10151015                if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
    1016                         $status = $this->handle_status_param( $request['status'], $post_type );
     1016                        $status = $this->handle_status_param( $request['status'], $post_type, $request['id'] );
    10171017
    10181018                        if ( is_wp_error( $status ) ) {
    10191019                                return $status;
     
    11471147         *
    11481148         * @param string $post_status Post status.
    11491149         * @param object $post_type   Post type.
     1150         * @param int    $post_id     Post ID.
    11501151         * @return string|WP_Error Post status or WP_Error if lacking the proper permission.
    11511152         */
    1152         protected function handle_status_param( $post_status, $post_type ) {
     1153        protected function handle_status_param( $post_status, $post_type, $post_id ) {
    11531154
    11541155                switch ( $post_status ) {
    11551156                        case 'draft':
     
    11561157                        case 'pending':
    11571158                                break;
    11581159                        case 'private':
    1159                                 if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
     1160                                if ( ! current_user_can( $post_type->cap->publish_posts, $post_id ) ) {
    11601161                                        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() ) );
    11611162                                }
    11621163                                break;
    11631164                        case 'publish':
    11641165                        case 'future':
    1165                                 if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
     1166                                if ( ! current_user_can( $post_type->cap->publish_posts, $post_id ) ) {
    11661167                                        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() ) );
    11671168                                }
    11681169                                break;