Make WordPress Core


Ignore:
Timestamp:
11/14/2014 09:33:50 PM (12 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r30202 r30346  
    178178 */
    179179function edit_post( $post_data = null ) {
     180        global $wpdb;
    180181
    181182        if ( empty($post_data) )
     
    318319        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    319320
    320         wp_update_post( $post_data );
     321        $success = wp_update_post( $post_data );
     322        // If the save failed, see if we can sanity check the main fields and try again
     323        if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
     324                $fields = array( 'post_title', 'post_content', 'post_excerpt' );
     325
     326                foreach( $fields as $field ) {
     327                        if ( isset( $post_data[ $field ] ) ) {
     328                                $post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] );
     329                        }
     330                }
     331
     332                wp_update_post( $post_data );
     333        }
    321334
    322335        // Now that we have an ID we can fix any attachment anchor hrefs
Note: See TracChangeset for help on using the changeset viewer.