From e61bebdbfc6b4f2af877b4da3e331b8e7bab5ad7 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 14 Nov 2014 21:34:22 +0000 Subject: [PATCH] If a saving a post fails, remove any invalid characters (such as emoji) from the primary text fields, then try to save it again. See #21212. Built from https://develop.svn.wordpress.org/trunk@30346 git-svn-id: http://core.svn.wordpress.org/trunk@30345 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 15 ++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 142752dbc8..ec96749f46 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -177,6 +177,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { * @return int Post ID. */ function edit_post( $post_data = null ) { + global $wpdb; if ( empty($post_data) ) $post_data = &$_POST; @@ -317,7 +318,19 @@ function edit_post( $post_data = null ) { update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); - wp_update_post( $post_data ); + $success = wp_update_post( $post_data ); + // If the save failed, see if we can sanity check the main fields and try again + if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { + $fields = array( 'post_title', 'post_content', 'post_excerpt' ); + + foreach( $fields as $field ) { + if ( isset( $post_data[ $field ] ) ) { + $post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] ); + } + } + + wp_update_post( $post_data ); + } // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); diff --git a/wp-includes/version.php b/wp-includes/version.php index d90898c479..3280838ad4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30345'; +$wp_version = '4.1-alpha-30346'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.