WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/25/2015 04:40:30 AM (4 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/src/wp-includes/comment-functions.php

    r34524 r34533  
    13781378 *
    13791379 * @since 2.0.0
     1380 * @since 4.4.0 Introduced `$comment_meta` argument.
    13801381 *
    13811382 * @global wpdb $wpdb WordPress database abstraction object.
     
    14021403 *                                            Default empty.
    14031404 *     @type string     $comment_type         Comment type. Default empty.
     1405 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
     1406 *                                            new comment.
    14041407 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
    14051408 * }
     
    14391442    }
    14401443    $comment = get_comment( $id );
     1444
     1445    // If metadata is provided, store it.
     1446    if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) {
     1447        foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) {
     1448            add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true );
     1449        }
     1450    }
    14411451
    14421452    /**
Note: See TracChangeset for help on using the changeset viewer.