WordPress.org

Make WordPress Core

Changeset 24878


Ignore:
Timestamp:
07/29/13 19:06:08 (9 months ago)
Author:
markjaquith
Message:

Delete old autosave if new autosave has same content as the post.

Props nacin. Fixes #7392 for trunk.

File:
1 edited

Legend:

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

    r24840 r24878  
    13211321        $new_autosave['post_author'] = $post_author; 
    13221322 
     1323        // If the new autosave is the same content as the post, delete the old autosave. 
     1324        $post = get_post( $post_id ); 
     1325        $autosave_is_different = false; 
     1326        foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 
     1327            if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) { 
     1328                $autosave_is_different = true; 
     1329                break; 
     1330            } 
     1331        } 
     1332 
     1333        if ( ! $autosave_is_different ) { 
     1334            wp_delete_post_revision( $old_autosave->ID ); 
     1335            return; 
     1336        } 
     1337 
    13231338        return wp_update_post( $new_autosave ); 
    13241339    } 
    13251340 
    13261341    // _wp_put_post_revision() expects unescaped. 
    1327     $_POST = wp_unslash($_POST); 
     1342    $post_data = wp_unslash( $_POST ); 
    13281343 
    13291344    // Otherwise create the new autosave as a special post revision 
    1330     return _wp_put_post_revision( $_POST, true ); 
     1345    return _wp_put_post_revision( $post_data, true ); 
    13311346} 
    13321347 
Note: See TracChangeset for help on using the changeset viewer.