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
This commit is contained in:
Mark Jaquith 2013-07-29 19:06:08 +00:00
parent 2572ccaf00
commit f1b2c07df3

View File

@ -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 );
}
/**