WordPress.org

Make WordPress Core

Ticket #29920: 29920.3.diff

File 29920.3.diff, 1.6 KB (added by mattheu, 6 years ago)

Filters for triggering autosave.

  • src/wp-admin/edit-form-advanced.php

    diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php
    index ebda7a3..e81bfb9 100644
    a b if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql 
    134134                }
    135135        }
    136136        // If this autosave isn't different from the current post, begone.
    137         if ( ! $notice )
     137        if ( ! apply_filters( 'autosave_is_different_notice', $notice, $autosave, $post ) ) {
    138138                wp_delete_post_revision( $autosave->ID );
     139        }
    139140        unset($autosave_field, $_autosave_field);
    140141}
    141142
  • src/wp-admin/includes/post.php

    diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
    index d230667..bbb7952 100644
    a b function wp_create_post_autosave( $post_data ) { 
    15301530                $new_autosave['post_author'] = $post_author;
    15311531
    15321532                // If the new autosave has the same content as the post, delete the autosave.
    1533                 $post = get_post( $post_id );
     1533                $post = get_post( $post_id, ARRAY_A );
    15341534                $autosave_is_different = false;
    15351535                foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields() ) ) as $field ) {
    1536                         if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) {
     1536                        if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) {
    15371537                                $autosave_is_different = true;
    15381538                                break;
    15391539                        }
    15401540                }
    15411541
    1542                 if ( ! $autosave_is_different ) {
     1542                if ( ! apply_filters( 'autosave_is_different', $autosave_is_different, $new_autosave, $post ) ) {
    15431543                        wp_delete_post_revision( $old_autosave->ID );
    15441544                        return 0;
    15451545                }