From 8196266d26050eeb83575b528824cef2a2a1bcce Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 21 Jan 2015 23:04:23 +0000 Subject: [PATCH] Comments: When a comment fails to insert, remove any invalid characters and try again. See #21212 Built from https://develop.svn.wordpress.org/trunk@31263 git-svn-id: http://core.svn.wordpress.org/trunk@31244 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 12 +++++++++++- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index a4f104f41b..693af2e9e6 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -1925,7 +1925,17 @@ function wp_insert_comment( $commentdata ) { $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' ); if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { - return false; + $fields = array( 'comment_author', 'comment_content' ); + + foreach( $fields as $field ) { + if ( isset( $compacted[ $field ] ) ) { + $post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $compacted[ $field ] ); + } + } + + if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { + return false; + } } $id = (int) $wpdb->insert_id; diff --git a/wp-includes/version.php b/wp-includes/version.php index 2f70c6f0ee..81aa9d66ed 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31262'; +$wp_version = '4.2-alpha-31263'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.