From 726b1f664c093fa1ab7e45cb180a29f7be532ece Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 29 Jun 2020 23:04:17 +0000 Subject: [PATCH] Comments: Make `wp_update_comment()` return a `WP_Error` object on database error, if `$wp_error` parameter is true. Follow-up to [48154], [48215]. See #39732. git-svn-id: https://develop.svn.wordpress.org/trunk@48216 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index c1165d9198..a8cc4dda29 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -2513,6 +2513,14 @@ function wp_update_comment( $commentarr, $wp_error = false ) { $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); + if ( false === $rval ) { + if ( $wp_error ) { + return new WP_Error( 'db_update_error', __( 'Could not update comment in the database.' ), $wpdb->last_error ); + } else { + return false; + } + } + // 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 ) {