Make WordPress Core


Ignore:
Timestamp:
09/25/2015 04:40:30 AM (9 years ago)
Author:
boonebgorges
Message:

Allow metadata to be attached to comment at time of creation.

The new $comment_meta parameter of wp_insert_comment() allows an array of
key/value pairs to be passed when creating a comment. These pairs are then
stored as commentmeta when the comment has been created.

Props tellyworth, wonderboymusic.
Fixes #12431.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r34250 r34533  
    274274        $this->assertFalse( $sent );
    275275    }
     276
     277    /**
     278     * @ticket 12431
     279     */
     280    public function test_wp_new_comment_with_meta() {
     281        $c = $this->factory->comment->create( array(
     282            'comment_approved' => '1',
     283            'comment_meta' => array(
     284                'food' => 'taco',
     285                'sauce' => 'fire'
     286            )
     287        ) );
     288
     289        $this->assertEquals( 'fire', get_comment_meta( $c, 'sauce', true ) );
     290    }
    276291}
Note: See TracChangeset for help on using the changeset viewer.