WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/21/2016 05:12:06 AM (3 years ago)
Author:
pento
Message:

REST API: Allow sending an empty or no-op comment update.

In general, updates that don't actually change anything should succeed. [39371] added tests for other object types, and this commit fixes empty updates for comments and adds the missing test.

Merges [39597] to the 4.7 branch.

Props jnylen0.
Fixes #38700.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

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

    r39566 r39628  
    665665        }
    666666
     667        if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
     668            $post = get_post( $prepared_args['comment_post_ID'] );
     669            if ( empty( $post ) ) {
     670                return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) );
     671            }
     672        }
     673
    667674        if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
    668675            // Only the comment status is being changed.
     
    691698            $updated = wp_update_comment( wp_slash( (array) $prepared_args ) );
    692699
    693             if ( 0 === $updated ) {
     700            if ( false === $updated ) {
    694701                return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) );
    695702            }
Note: See TracChangeset for help on using the changeset viewer.