WordPress.org

Make WordPress Core

Ticket #38816: 38816.3.diff

File 38816.3.diff, 1.4 KB (added by rachelbaker, 4 years ago)

restores the ability to create a comment with a post_id of 0

  • src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

     
    385385                        return new WP_Error( 'rest_comment_invalid_status', __( 'Sorry, you are not allowed to set status for comments.' ), array( 'status' => rest_authorization_required_code() ) );
    386386                }
    387387
    388                 if ( empty( $request['post'] ) && ! current_user_can( 'moderate_comments' ) ) {
     388                 if ( empty( $request['post'] ) && ! current_user_can( 'moderate_comments' ) ) {
    389389                        return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => rest_authorization_required_code() ) );
    390390                }
    391391
    392                 if ( ! empty( $request['post'] ) && $post = get_post( (int) $request['post'] ) ) {
     392                if ( ! empty( $request['post'] ) ) {
     393                        $post = get_post( (int) $request['post'] );
     394
     395                        if ( ! $post ) {
     396                                return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) );
     397                        }
     398
    393399                        if ( 'draft' === $post->post_status ) {
    394400                                return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) );
    395401                        }