Make WordPress Core

Ticket #36784: 36784.4.diff

File 36784.4.diff, 1.5 KB (added by boonebgorges, 9 years ago)
  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index ef4b553..0701119 100644
    function wp_update_comment($commentarr) { 
    20272027        $data = wp_array_slice_assoc( $data, $keys );
    20282028        $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
    20292029
     2030        // If metadata is provided, store it.
     2031        if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) {
     2032                foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) {
     2033                        update_comment_meta( $comment_ID, $meta_key, $meta_value );
     2034                }
     2035        }
     2036
    20302037        clean_comment_cache( $comment_ID );
    20312038        wp_update_comment_count( $comment_post_ID );
    20322039        /**
  • tests/phpunit/tests/comment.php

    diff --git tests/phpunit/tests/comment.php tests/phpunit/tests/comment.php
    index c2fc51b..a362f5d 100644
    class Tests_Comment extends WP_UnitTestCase { 
    5858                $this->assertEquals( 'pingback', $comment->comment_type );
    5959        }
    6060
     61
     62        /**
     63         * @ticket 36784
     64         */
     65        function test_wp_update_comment_updates_comment_meta() {
     66                $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) );
     67                wp_update_comment( array(
     68                        'comment_ID' => $comment_id,
     69                        'comment_meta' => array(
     70                                'food' => 'taco',
     71                                'sauce' => 'fire',
     72                        ),
     73                ) );
     74                $this->assertEquals( 'fire', get_comment_meta( $comment_id, 'sauce', true ) );
     75        }
     76
     77
    6178        /**
    6279         * @ticket 30307
    6380         */