WordPress.org

Make WordPress Core

Changeset 35853


Ignore:
Timestamp:
12/10/2015 03:16:51 PM (4 years ago)
Author:
rachelbaker
Message:

Comments: Comments don’t need no Post ID when created, so they don’t be needing one to be edited.

In wp_update_comment() only check if the given comment_post_ID is valid if it isn’t 0. This allows comments that were created programmatically via wp_insert_comment() without the (optional) comment_post_ID parameter to be edited.

Props subharanjan for the initial patch.
Fixes #34954

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r35745 r35853  
    19051905
    19061906    // Make sure that the comment post ID is valid (if specified).
    1907     if ( isset( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
     1907    if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
    19081908        return 0;
    19091909    }
  • trunk/tests/phpunit/tests/comment.php

    r35475 r35853  
    7171    }
    7272
     73    /**
     74     * @ticket 34954
     75     */
     76    function test_wp_update_comment_with_no_post_id() {
     77        $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => 0 ) );
     78
     79        $updated_comment_text = 'I should be able to update a comment with a Post ID of zero';
     80
     81        $update = wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_content' => $updated_comment_text, 'comment_post_ID' => 0 ) );
     82        $this->assertSame( 1, $update );
     83
     84        $comment = get_comment( $comment_id );
     85        $this->assertEquals( $updated_comment_text, $comment->comment_content );
     86    }
     87
    7388    public function test_get_approved_comments() {
    7489        $ca1 = self::factory()->comment->create( array(
Note: See TracChangeset for help on using the changeset viewer.