Make WordPress Core

Ticket #7392: 7392-autosave.patch

File 7392-autosave.patch, 1.5 KB (added by azaozz, 12 years ago)
  • wp-admin/includes/post.php

     
    12671267 * @return unknown
    12681268 */
    12691269function wp_create_post_autosave( $post_id ) {
     1270        if ( ! $post = get_post( $post_id ) )
     1271                return;
     1272
    12701273        $translated = _wp_translate_postdata( true );
    12711274        if ( is_wp_error( $translated ) )
    12721275                return $translated;
    12731276
    12741277        $post_author = get_current_user_id();
     1278        $new_data = $_POST;
    12751279
    12761280        // Store one autosave per author. If there is already an autosave, overwrite it.
    12771281        if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) {
    12781282                $new_autosave = _wp_post_revision_fields( $_POST, true );
    12791283                $new_autosave['ID'] = $old_autosave->ID;
    12801284                $new_autosave['post_author'] = $post_author;
    1281                 return wp_update_post( $new_autosave );
     1285
     1286                $new_data = $new_autosave;
    12821287        }
    12831288
     1289        if ( apply_filters( 'wp_save_post_revision_check_for_changes', true, $post, $new_data ) && is_array( $new_data ) ) {
     1290                $post_has_changed = false;
     1291                foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
     1292                        if ( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) {
     1293                                $post_has_changed = true;
     1294                                break;
     1295                        }
     1296                }
     1297                //don't save revision if post unchanged
     1298                if( ! $post_has_changed )
     1299                        return;
     1300        }
     1301
     1302        if ( isset( $new_autosave ) )
     1303                return wp_update_post( $new_autosave );
     1304
    12841305        // _wp_put_post_revision() expects unescaped.
    12851306        $_POST = wp_unslash($_POST);
    12861307