WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/13/2016 01:52:49 PM (4 years ago)
Author:
jnylen0
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.

Fixes #38700.

File:
1 edited

Legend:

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

    r39508 r39597  
    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.