Make WordPress Core

Changeset 23414


Ignore:
Timestamp:
02/14/2013 11:36:32 AM (12 years ago)
Author:
westi
Message:

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.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-filters.php

    r23355 r23414  
    250250add_action( 'plugins_loaded',             'wp_maybe_load_embeds',                     0    );
    251251add_action( 'shutdown',                   'wp_ob_end_flush_all',                      1    );
    252 add_action( 'pre_post_update',            'wp_save_post_revision'                          );
     252add_action( 'pre_post_update',            'wp_save_post_revision',                   10, 2 );
    253253add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    254254add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
  • trunk/wp-includes/post.php

    r23401 r23414  
    28672867
    28682868    if ( $update ) {
    2869         do_action( 'pre_post_update', $post_ID );
     2869        do_action( 'pre_post_update', $post_ID, $data );
    28702870        if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
    28712871            if ( $wp_error )
     
    49304930 * @return mixed Null or 0 if error, new revision ID, if success.
    49314931 */
    4932 function wp_save_post_revision( $post_id ) {
     4932function wp_save_post_revision( $post_id, $new_data = null ) {
    49334933    // We do autosaves manually with wp_create_post_autosave()
    49344934    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
     
    49474947    if ( !post_type_supports($post['post_type'], 'revisions') )
    49484948        return;
     4949
     4950    // if new data is supplied, check that it is different from last saved revision
     4951    if( is_array( $new_data ) ) {
     4952        $post_has_changed = false;
     4953        foreach( array_keys( _wp_post_revision_fields() ) as $field ) {
     4954            if( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) {
     4955                $post_has_changed = true;
     4956                break;
     4957            }
     4958        }
     4959        //don't save revision if post unchanged
     4960        if( ! $post_has_changed )
     4961            return;
     4962    }
    49494963
    49504964    $return = _wp_put_post_revision( $post );
Note: See TracChangeset for help on using the changeset viewer.