diff --git a/wp-comments-post.php b/wp-comments-post.php index 6196c36842..0ed359c5bb 100644 --- a/wp-comments-post.php +++ b/wp-comments-post.php @@ -132,7 +132,11 @@ $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_paren $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); $comment_id = wp_new_comment( $commentdata ); -$comment = get_comment($comment_id); +if ( ! $comment_id ) { + wp_die( __( "ERROR: The comment could not be saved. Please try again later." ) ); +} + +$comment = get_comment( $comment_id ); /** * Perform other actions when comment cookies are set. diff --git a/wp-includes/comment.php b/wp-includes/comment.php index eb0e5335dd..9747bf7892 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -1582,7 +1582,7 @@ function wp_get_current_commenter() { * @uses $wpdb * * @param array $commentdata Contains information on the comment. - * @return int The new comment's ID. + * @return int|bool The new comment's ID on success, false on failure. */ function wp_insert_comment( $commentdata ) { global $wpdb; @@ -1607,7 +1607,9 @@ function wp_insert_comment( $commentdata ) { $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); - $wpdb->insert( $wpdb->comments, $compacted ); + if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { + return false; + } $id = (int) $wpdb->insert_id; @@ -1727,7 +1729,7 @@ function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) * * @since 1.5.0 * @param array $commentdata Contains information on the comment. - * @return int The ID of the comment after adding. + * @return int|bool The ID of the comment on success, false on failure. */ function wp_new_comment( $commentdata ) { /** @@ -1760,6 +1762,9 @@ function wp_new_comment( $commentdata ) { $commentdata['comment_approved'] = wp_allow_comment($commentdata); $comment_ID = wp_insert_comment($commentdata); + if ( ! $comment_ID ) { + return false; + } /** * Fires immediately after a comment is inserted into the database.