Make WordPress Core

Ticket #36784: 36784.5.diff

File 36784.5.diff, 2.0 KB (added by kraftbj, 8 years ago)

Refresh and add @since

  • src/wp-includes/comment.php

     
    21262126 * Filters the comment and makes sure certain fields are valid before updating.
    21272127 *
    21282128 * @since 2.0.0
     2129 * @since 4.9.0 Add updating comment meta during comment update.
    21292130 *
    21302131 * @global wpdb $wpdb WordPress database abstraction object.
    21312132 *
     
    21992200
    22002201        $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
    22012202
     2203        // If metadata is provided, store it.
     2204        if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) {
     2205                foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) {
     2206                        update_comment_meta( $comment_ID, $meta_key, $meta_value );
     2207                }
     2208        }
     2209
    22022210        clean_comment_cache( $comment_ID );
    22032211        wp_update_comment_count( $comment_post_ID );
    22042212        /**
     
    30053013                 * @param int $comment_post_ID Post ID.
    30063014                 */
    30073015                do_action( 'comment_on_draft', $comment_post_ID );
    3008                
     3016
    30093017                if ( current_user_can( 'read_post', $comment_post_ID ) ) {
    30103018                        return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
    30113019                } else {
  • tests/phpunit/tests/comment.php

     
    5252                $this->assertEquals( 'pingback', $comment->comment_type );
    5353        }
    5454
     55
     56        /**
     57         * @ticket 36784
     58         */
     59        function test_wp_update_comment_updates_comment_meta() {
     60                $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) );
     61                wp_update_comment( array(
     62                        'comment_ID' => $comment_id,
     63                        'comment_meta' => array(
     64                                'food' => 'taco',
     65                                'sauce' => 'fire',
     66                        ),
     67                ) );
     68                $this->assertEquals( 'fire', get_comment_meta( $comment_id, 'sauce', true ) );
     69        }
     70
     71
    5572        /**
    5673         * @ticket 30307
    5774         */