Ticket #16215: 16215.6.diff

File 16215.6.diff, 6.0 KB (added by adamsilverstein, 2 months ago)

clean up white space, diff against current trunk

  • wp-includes/default-filters.php

     
    250250add_action( 'plugins_loaded',             'wp_maybe_load_widgets',                    0    ); 
    251251add_action( 'plugins_loaded',             'wp_maybe_load_embeds',                     0    ); 
    252252add_action( 'shutdown',                   'wp_ob_end_flush_all',                      1    ); 
    253 add_action( 'pre_post_update',            'wp_save_post_revision',                   10, 2 ); 
     253add_action( 'pre_post_update',            'wp_save_post_revision',                   10, 1 ); 
     254add_action( 'post_updated',               'wp_save_post_revision',                   10, 1 ); 
    254255add_action( 'publish_post',               '_publish_post_hook',                       5, 1 ); 
    255256add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 ); 
    256257add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 ); 
  • wp-includes/revision.php

     
    6262/** 
    6363 * Saves an already existing post as a post revision. 
    6464 * 
    65  * Typically used immediately prior to post updates. 
     65 * Typically used immediately prior and after post updates. 
     66 * Prior to update checks for old revision data (latest revision != current post before update) and adds a copy of the current post as a revision if missing 
     67 * After update adds a copy of the current post as a revision, so latest revision always matches current post 
    6668 * 
    6769 * @package WordPress 
    6870 * @subpackage Post_Revisions 
    6971 * @since 2.6.0 
    7072 * 
    7173 * @uses _wp_put_post_revision() 
     74 * @uses wp_first_revision_matches_current_version() 
    7275 * 
    7376 * @param int $post_id The ID of the post to save as a revision. 
    7477 * @return mixed Null or 0 if error, new revision ID, if success. 
    7578 */ 
    76 function wp_save_post_revision( $post_id, $new_data = null ) { 
    77         // We do autosaves manually with wp_create_post_autosave() 
     79function wp_save_post_revision( $post_id ) { 
     80        //check to see if the post's first revision already matches the post data 
     81        //should be true before post update, _except_ for old data which 
     82        //doesn't include a copy of the current post data in revisions 
     83        if ( wp_first_revision_matches_current_version( $post_id ) ) 
     84                return; 
     85 
    7886        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
    7987                return; 
    8088 
     
    8290        if ( ! WP_POST_REVISIONS ) 
    8391                return; 
    8492 
    85         if ( !$post = get_post( $post_id, ARRAY_A ) ) 
     93        if ( ! $post = get_post( $post_id, ARRAY_A ) ) 
    8694                return; 
    8795 
    8896        if ( 'auto-draft' == $post['post_status'] ) 
    8997                return; 
    9098 
    91         if ( !post_type_supports($post['post_type'], 'revisions') ) 
     99        if ( ! post_type_supports( $post['post_type'], 'revisions' ) ) 
    92100                return; 
    93101 
    94         // if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless 
    95         if ( apply_filters( 'wp_save_post_revision_check_for_changes', true, $post, $new_data ) && is_array( $new_data ) ) { 
    96                 $post_has_changed = false; 
    97                 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 
    98                         if ( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) { 
    99                                 $post_has_changed = true; 
    100                                 break; 
     102        // compare the proposed update with the last stored revision, verify 
     103        // different, unless a plugin tells us to always save regardless 
     104        if ( $revisions = wp_get_post_revisions( $post_id ) ) { // grab the last revision 
     105                $last_revision = array_shift( $revisions ); 
     106 
     107                if ( $last_revision_array = get_post( $last_revision->ID, ARRAY_A ) ) { //if no previous revisions, save one for sure 
     108 
     109                        if ( apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision_array, $post ) && is_array( $post ) ) { 
     110                                $post_has_changed = false; 
     111 
     112                                foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 
     113 
     114                                        if ( normalize_whitespace( $post[ $field ] ) != normalize_whitespace( $last_revision_array[ $field ] ) ) { 
     115                                                $post_has_changed = true; 
     116                                                break; 
     117 
     118                                        } 
     119                                } 
     120 
     121                                //don't save revision if post unchanged 
     122                                if( ! $post_has_changed ) 
     123                                        return; 
    101124                        } 
    102125                } 
    103                 //don't save revision if post unchanged 
    104                 if( ! $post_has_changed ) 
    105                         return; 
    106126        } 
    107127 
    108128        $return = _wp_put_post_revision( $post ); 
    109129 
    110130        // WP_POST_REVISIONS = true (default), -1 
    111         if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 ) 
     131        if ( ! is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 ) 
    112132                return $return; 
    113133 
    114134        // all revisions and (possibly) one autosave 
    115135        $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); 
    116136 
    117137        // WP_POST_REVISIONS = (int) (# of autosaves to save) 
    118         $delete = count($revisions) - WP_POST_REVISIONS; 
     138        $delete = count( $revisions ) - WP_POST_REVISIONS; 
    119139 
    120140        if ( $delete < 1 ) 
    121141                return $return; 
     
    123143        $revisions = array_slice( $revisions, 0, $delete ); 
    124144 
    125145        for ( $i = 0; isset($revisions[$i]); $i++ ) { 
    126                 if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) ) 
     146                if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) 
    127147                        continue; 
    128                 wp_delete_post_revision( $revisions[$i]->ID ); 
     148                wp_delete_post_revision( $revisions[ $i ]->ID ); 
    129149        } 
    130150 
    131151        return $return; 
     
    418438                add_filter('the_preview', '_set_preview'); 
    419439        } 
    420440} 
     441 
     442/** 
     443 * Determines if the specified post's most recent revision matches the post (by checking post_modified). 
     444 * 
     445 * @package WordPress 
     446 * @subpackage Post_Revisions 
     447 * @since 3.6.0 
     448 * 
     449 * @param int|object $post Post ID or post object. 
     450 * @return bool false if not a match, otherwise true. 
     451 */ 
     452function wp_first_revision_matches_current_version( $post ) { 
     453 
     454        if ( ! $post = get_post( $post ) ) 
     455                return false; 
     456 
     457        if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 
     458                return false; 
     459 
     460        $last_revision = array_shift( $revisions ); 
     461 
     462        if ( ! ($last_revision->post_modified == $post->post_modified ) ) 
     463                return false; 
     464 
     465        return true; 
     466}