Ticket #16215: 16215.5.diff
File 16215.5.diff, 6.7 KB (added by , 12 years ago) |
---|
-
wp-includes/default-filters.php
250 250 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 251 251 add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); 252 252 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); 253 add_action( 'pre_post_update', 'wp_save_post_revision', 10, 2 ); 253 add_action( 'pre_post_update', 'wp_save_post_revision', 10, 1 ); 254 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); 254 255 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); 255 256 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); 256 257 add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); -
wp-includes/post.php
2830 2830 $where = array( 'ID' => $post_ID ); 2831 2831 } 2832 2832 2833 2834 2835 2833 2836 if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 2834 2837 $data['post_name'] = sanitize_title($data['post_title'], $post_ID); 2835 2838 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); … … 2878 2881 2879 2882 if ( $update ) { 2880 2883 do_action('edit_post', $post_ID, $post); 2884 2881 2885 $post_after = get_post($post_ID); 2882 2886 do_action( 'post_updated', $post_ID, $post_after, $post_before); 2883 2887 } -
wp-includes/revision.php
62 62 /** 63 63 * Saves an already existing post as a post revision. 64 64 * 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 66 68 * 67 69 * @package WordPress 68 70 * @subpackage Post_Revisions 69 71 * @since 2.6.0 70 72 * 71 73 * @uses _wp_put_post_revision() 74 * @uses wp_first_revision_matches_current_version() 72 75 * 73 76 * @param int $post_id The ID of the post to save as a revision. 74 77 * @return mixed Null or 0 if error, new revision ID, if success. 75 78 */ 76 function wp_save_post_revision( $post_id, $new_data = null ) { 77 // We do autosaves manually with wp_create_post_autosave() 79 function 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 78 86 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 79 87 return; 80 88 … … 82 90 if ( ! WP_POST_REVISIONS ) 83 91 return; 84 92 85 if ( ! $post = get_post( $post_id, ARRAY_A ) )93 if ( ! $post = get_post( $post_id, ARRAY_A ) ) 86 94 return; 87 95 88 96 if ( 'auto-draft' == $post['post_status'] ) 89 97 return; 90 98 91 if ( ! post_type_supports($post['post_type'], 'revisions') )99 if ( ! post_type_supports( $post['post_type'], 'revisions' ) ) 92 100 return; 93 101 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; 101 124 } 102 125 } 103 //don't save revision if post unchanged104 if( ! $post_has_changed )105 return;106 126 } 107 127 108 128 $return = _wp_put_post_revision( $post ); 109 129 110 130 // 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 ) 112 132 return $return; 113 133 114 134 // all revisions and (possibly) one autosave 115 135 $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); 116 136 117 137 // WP_POST_REVISIONS = (int) (# of autosaves to save) 118 $delete = count( $revisions) - WP_POST_REVISIONS;138 $delete = count( $revisions ) - WP_POST_REVISIONS; 119 139 120 140 if ( $delete < 1 ) 121 141 return $return; … … 123 143 $revisions = array_slice( $revisions, 0, $delete ); 124 144 125 145 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' ) ) 127 147 continue; 128 wp_delete_post_revision( $revisions[ $i]->ID );148 wp_delete_post_revision( $revisions[ $i ]->ID ); 129 149 } 130 150 131 151 return $return; … … 418 438 add_filter('the_preview', '_set_preview'); 419 439 } 420 440 } 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 */ 452 function 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 }