Make WordPress Core

Changeset 31195


Ignore:
Timestamp:
01/16/2015 02:38:30 AM (10 years ago)
Author:
pento
Message:

Allow comment_post_ID to be passed to wp_update_comment(), so that a comment can be moved to a different post.

Props tyxla, rachelbaker

Fixes #30946

Location:
trunk
Files:
2 edited

Legend:

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

    r31172 r31195  
    22062206        return 0;
    22072207    }
     2208
     2209    // Make sure that the comment post ID is valid (if specified).
     2210    if ( isset( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
     2211        return 0;
     2212    }
     2213
    22082214    // Escape data pulled from DB.
    22092215    $comment = wp_slash($comment);
     
    22402246    $comment_ID = $data['comment_ID'];
    22412247    $comment_post_ID = $data['comment_post_ID'];
    2242     $keys = array( 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id' );
     2248    $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id' );
    22432249    $data = wp_array_slice_assoc( $data, $keys );
    22442250    $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
  • trunk/tests/phpunit/tests/comment.php

    r31172 r31195  
    77    function test_wp_update_comment() {
    88        $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post' ) );
     9        $post2 = $this->factory->post->create_and_get( array( 'post_title' => 'some-post-2', 'post_type' => 'post' ) );
    910        $comments = $this->factory->comment->create_post_comments( $post->ID, 5 );
    1011        $result = wp_update_comment( array( 'comment_ID' => $comments[0], 'comment_parent' => $comments[1] ) );
     
    1415        $result = wp_update_comment( array( 'comment_ID' => $comments[0], 'comment_parent' => $comments[1] ) );
    1516        $this->assertEquals( 0, $result );
     17        $result = wp_update_comment( array( 'comment_ID' => $comments[0], 'comment_post_ID' => $post2->ID ) );
     18        $comment = get_comment( $comments[0] );
     19        $this->assertEquals( $post2->ID, $comment->comment_post_ID );
    1620    }
    1721
Note: See TracChangeset for help on using the changeset viewer.