Revisions: Before saving a new post revision make sure that something has changed in the fields that we are revisioning.

Fixes: #7392 and #9843 props adamsilverstein.


git-svn-id: http://core.svn.wordpress.org/trunk@23414 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Westwood 2013-02-14 11:36:32 +00:00
parent 7a77f47f55
commit 716d48e0cd
2 changed files with 17 additions and 3 deletions

View File

@ -249,7 +249,7 @@ add_action( 'init', 'smilies_init',
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 );
add_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
add_action( 'pre_post_update', 'wp_save_post_revision' );
add_action( 'pre_post_update', 'wp_save_post_revision', 10, 2 );
add_action( 'publish_post', '_publish_post_hook', 5, 1 );
add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 );

View File

@ -2866,7 +2866,7 @@ function wp_insert_post($postarr, $wp_error = false) {
$where = array( 'ID' => $post_ID );
if ( $update ) {
do_action( 'pre_post_update', $post_ID );
do_action( 'pre_post_update', $post_ID, $data );
if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
if ( $wp_error )
return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
@ -4929,7 +4929,7 @@ function _wp_post_revision_fields( $post = null, $autosave = false ) {
* @param int $post_id The ID of the post to save as a revision.
* @return mixed Null or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
function wp_save_post_revision( $post_id, $new_data = null ) {
// We do autosaves manually with wp_create_post_autosave()
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
@ -4947,6 +4947,20 @@ function wp_save_post_revision( $post_id ) {
if ( !post_type_supports($post['post_type'], 'revisions') )
return;
// if new data is supplied, check that it is different from last saved revision
if( is_array( $new_data ) ) {
$post_has_changed = false;
foreach( array_keys( _wp_post_revision_fields() ) as $field ) {
if( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) {
$post_has_changed = true;
break;
}
}
//don't save revision if post unchanged
if( ! $post_has_changed )
return;
}
$return = _wp_put_post_revision( $post );
// WP_POST_REVISIONS = true (default), -1