From f1b2c07df320ad3e3e97d00c7b73d691726f6468 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Mon, 29 Jul 2013 19:06:08 +0000 Subject: [PATCH] Delete old autosave if new autosave has same content as the post. Props nacin. Fixes #7392 for trunk. git-svn-id: http://core.svn.wordpress.org/trunk@24878 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 55e10ce2fd..9d9ddfd4a3 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1320,14 +1320,29 @@ function wp_create_post_autosave( $post_id ) { $new_autosave['ID'] = $old_autosave->ID; $new_autosave['post_author'] = $post_author; + // If the new autosave is the same content as the post, delete the old autosave. + $post = get_post( $post_id ); + $autosave_is_different = false; + foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { + if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) { + $autosave_is_different = true; + break; + } + } + + if ( ! $autosave_is_different ) { + wp_delete_post_revision( $old_autosave->ID ); + return; + } + return wp_update_post( $new_autosave ); } // _wp_put_post_revision() expects unescaped. - $_POST = wp_unslash($_POST); + $post_data = wp_unslash( $_POST ); // Otherwise create the new autosave as a special post revision - return _wp_put_post_revision( $_POST, true ); + return _wp_put_post_revision( $post_data, true ); } /**