From 6995731f12e2ba40d2c9ecb2ce5a50a3e015a1f5 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 1 Jul 2017 13:36:41 +0000 Subject: [PATCH] Allow metadata to be updated via `wp_update_comment()`. Passing an array of `comment_meta` into `wp_update_comment()` will now update corresponding metadata. Similar functionality already exists in `wp_insert_comment()`. Props dshanske, kraftbj. Fixes #36784. Built from https://develop.svn.wordpress.org/trunk@40981 git-svn-id: http://core.svn.wordpress.org/trunk@40831 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index f098910ea5..7055db763f 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2126,6 +2126,7 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) * Filters the comment and makes sure certain fields are valid before updating. * * @since 2.0.0 + * @since 4.9.0 Add updating comment meta during comment update. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -2199,6 +2200,13 @@ function wp_update_comment($commentarr) { $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); + // If metadata is provided, store it. + if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) { + foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) { + update_comment_meta( $comment_ID, $meta_key, $meta_value ); + } + } + clean_comment_cache( $comment_ID ); wp_update_comment_count( $comment_post_ID ); /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 382235f1a3..079000e585 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-40980'; +$wp_version = '4.9-alpha-40981'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.