Make WordPress Core


Ignore:
Timestamp:
11/10/2016 03:34:30 AM (9 years ago)
Author:
joehoyle
Message:

REST API: Allow updating a comment without the content present.

For all resources in the REST API, sending partial updates is supported. This fixes needing to _always_ specify comment content.

Props jnylen.
Fixes #38720.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r39179 r39196  
    432432
    433433        /*
    434          * Do not allow a comment to be created with an empty string for
     434         * Do not allow a comment to be created with missing or empty
    435435         * comment_content. See wp_handle_comment_submission().
    436436         */
    437         if ( '' === $prepared_comment['comment_content'] ) {
     437        if ( empty( $prepared_comment['comment_content'] ) ) {
    438438            return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) );
    439439        }
     
    635635            if ( is_wp_error( $prepared_args ) ) {
    636636                return $prepared_args;
     637            }
     638
     639            if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) {
     640                return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) );
    637641            }
    638642
     
    10631067                list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data;
    10641068            }
    1065         }
    1066 
    1067         // Require 'comment_content' unless only the 'comment_status' is being updated.
    1068         if ( ! empty( $prepared_comment ) && ! isset( $prepared_comment['comment_content'] ) ) {
    1069             return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) );
    10701069        }
    10711070
Note: See TracChangeset for help on using the changeset viewer.