| 1 | Index: wp-includes/default-filters.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/default-filters.php (revision 23340) |
|---|
| 4 | +++ wp-includes/default-filters.php (working copy) |
|---|
| 5 | @@ -123,6 +123,9 @@ |
|---|
| 6 | add_filter( $filter, 'convert_chars' ); |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | +// Pre save Revision Version |
|---|
| 10 | +add_filter( 'wp_insert_post_data', '_wp_insert_post_data_revision_version', 10, 2 ); |
|---|
| 11 | + |
|---|
| 12 | // Pre save hierarchy |
|---|
| 13 | add_filter( 'wp_insert_post_parent', 'wp_check_post_hierarchy_for_loops', 10, 2 ); |
|---|
| 14 | add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 ); |
|---|
| 15 | @@ -249,7 +252,7 @@ |
|---|
| 16 | add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); |
|---|
| 17 | add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); |
|---|
| 18 | add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); |
|---|
| 19 | -add_action( 'pre_post_update', 'wp_save_post_revision' ); |
|---|
| 20 | +add_action( 'pre_post_update', 'wp_save_post_revision', 10, 2 ); |
|---|
| 21 | add_action( 'publish_post', '_publish_post_hook', 5, 1 ); |
|---|
| 22 | add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); |
|---|
| 23 | add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); |
|---|
| 24 | Index: wp-includes/post-template.php |
|---|
| 25 | =================================================================== |
|---|
| 26 | --- wp-includes/post-template.php (revision 23340) |
|---|
| 27 | +++ wp-includes/post-template.php (working copy) |
|---|
| 28 | @@ -1375,18 +1375,28 @@ |
|---|
| 29 | |
|---|
| 30 | if ( $parent ) |
|---|
| 31 | array_unshift( $revisions, $post ); |
|---|
| 32 | + |
|---|
| 33 | + if ( ! array_pop( $revisions ) ) |
|---|
| 34 | + return; |
|---|
| 35 | |
|---|
| 36 | $rows = $right_checked = ''; |
|---|
| 37 | $class = false; |
|---|
| 38 | $can_edit_post = current_user_can( 'edit_post', $post->ID ); |
|---|
| 39 | + |
|---|
| 40 | foreach ( $revisions as $revision ) { |
|---|
| 41 | + |
|---|
| 42 | if ( !current_user_can( 'read_post', $revision->ID ) ) |
|---|
| 43 | continue; |
|---|
| 44 | if ( 'revision' === $type && wp_is_post_autosave( $revision ) ) |
|---|
| 45 | continue; |
|---|
| 46 | |
|---|
| 47 | $date = wp_post_revision_title( $revision ); |
|---|
| 48 | - $name = get_the_author_meta( 'display_name', $revision->post_author ); |
|---|
| 49 | + if ( wp_is_post_revision( $revision ) ) { |
|---|
| 50 | + $revision_author_id = $revision->post_author; |
|---|
| 51 | + } elseif ( !$revision_author_id = get_post_meta( $revision->ID, '_edit_last', true ) ) { |
|---|
| 52 | + $revision_author_id = $revision->post_author; |
|---|
| 53 | + } |
|---|
| 54 | + $name = get_the_author_meta( 'display_name', $revision_author_id ); |
|---|
| 55 | |
|---|
| 56 | if ( 'form-table' == $format ) { |
|---|
| 57 | if ( $left ) |
|---|
| 58 | Index: wp-includes/post.php |
|---|
| 59 | =================================================================== |
|---|
| 60 | --- wp-includes/post.php (revision 23340) |
|---|
| 61 | +++ wp-includes/post.php (working copy) |
|---|
| 62 | @@ -2866,7 +2866,7 @@ |
|---|
| 63 | $where = array( 'ID' => $post_ID ); |
|---|
| 64 | |
|---|
| 65 | if ( $update ) { |
|---|
| 66 | - do_action( 'pre_post_update', $post_ID ); |
|---|
| 67 | + do_action( 'pre_post_update', $post_ID, $data ); |
|---|
| 68 | if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { |
|---|
| 69 | if ( $wp_error ) |
|---|
| 70 | return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); |
|---|
| 71 | @@ -2900,6 +2900,8 @@ |
|---|
| 72 | $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | + update_post_meta( $post_ID, '_edit_last', $user_ID ); |
|---|
| 76 | + |
|---|
| 77 | if ( is_object_in_taxonomy($post_type, 'category') ) |
|---|
| 78 | wp_set_post_categories( $post_ID, $post_category ); |
|---|
| 79 | |
|---|
| 80 | @@ -4920,9 +4922,24 @@ |
|---|
| 81 | $return['post_date'] = isset($post['post_modified']) ? $post['post_modified'] : ''; |
|---|
| 82 | $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : ''; |
|---|
| 83 | |
|---|
| 84 | + $return['post_author'] = get_post_meta( $post['ID'], '_edit_last', true ); |
|---|
| 85 | + $return['comment_count'] = 1; // The comment_count field stores the revisioning system version |
|---|
| 86 | + |
|---|
| 87 | return $return; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | +function _wp_insert_post_data_revision_version( $data, $post_array ) { |
|---|
| 91 | + if ( 'revision' != $data['post_type'] ) { |
|---|
| 92 | + return $data; |
|---|
| 93 | + } |
|---|
| 94 | + |
|---|
| 95 | + if ( isset( $post_array['comment_count'] ) ) { |
|---|
| 96 | + $data['comment_count'] = (int) $post_array['comment_count']; |
|---|
| 97 | + } |
|---|
| 98 | + |
|---|
| 99 | + return $data; |
|---|
| 100 | +} |
|---|
| 101 | + |
|---|
| 102 | /** |
|---|
| 103 | * Saves an already existing post as a post revision. |
|---|
| 104 | * |
|---|
| 105 | @@ -4937,7 +4954,7 @@ |
|---|
| 106 | * @param int $post_id The ID of the post to save as a revision. |
|---|
| 107 | * @return mixed Null or 0 if error, new revision ID, if success. |
|---|
| 108 | */ |
|---|
| 109 | -function wp_save_post_revision( $post_id ) { |
|---|
| 110 | +function wp_save_post_revision( $post_id, $new_data = null ) { |
|---|
| 111 | // We do autosaves manually with wp_create_post_autosave() |
|---|
| 112 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|---|
| 113 | return; |
|---|
| 114 | @@ -4955,6 +4972,21 @@ |
|---|
| 115 | if ( !post_type_supports($post['post_type'], 'revisions') ) |
|---|
| 116 | return; |
|---|
| 117 | |
|---|
| 118 | + // if new data is supplied, check that it is different from last saved revision |
|---|
| 119 | + if( is_array( $new_data ) ) { |
|---|
| 120 | + $post_has_changed = false; |
|---|
| 121 | + foreach( array_keys( _wp_post_revision_fields() ) as $field ) { |
|---|
| 122 | + if( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[$field] ) ) { |
|---|
| 123 | + error_log( 'post changed' ); |
|---|
| 124 | + $post_has_changed = true; |
|---|
| 125 | + break; |
|---|
| 126 | + } |
|---|
| 127 | + } |
|---|
| 128 | + //don't save revision if post unchanged |
|---|
| 129 | + if( ! $post_has_changed ) |
|---|
| 130 | + return; |
|---|
| 131 | + } |
|---|
| 132 | + |
|---|
| 133 | $return = _wp_put_post_revision( $post ); |
|---|
| 134 | |
|---|
| 135 | // WP_POST_REVISIONS = true (default), -1 |
|---|
| 136 | @@ -5235,9 +5267,60 @@ |
|---|
| 137 | |
|---|
| 138 | if ( !$revisions = get_children( $args ) ) |
|---|
| 139 | return array(); |
|---|
| 140 | + |
|---|
| 141 | + $revisions = wp_fix_post_revision_authors( $revisions, $args ); |
|---|
| 142 | return $revisions; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | +function wp_fix_post_revision_authors( $revisions, $args ) { |
|---|
| 146 | + $keys = array_keys( $revisions ); |
|---|
| 147 | + if ( 'DESC' == strtoupper( $args['order'] ) ) { |
|---|
| 148 | + $keys = array_reverse( $keys ); |
|---|
| 149 | + } |
|---|
| 150 | + |
|---|
| 151 | + $previous_author = false; |
|---|
| 152 | + foreach ( $keys as $key ) { |
|---|
| 153 | + if ( is_array( $revisions[$key] ) && isset( $revisions[$key]['comment_count'] ) ) { |
|---|
| 154 | + $revision_version = $revisions[$key]['comment_count']; |
|---|
| 155 | + $is_array = true; |
|---|
| 156 | + } elseif ( is_object( $revisions[$key] ) && isset( $revisions[$key]->comment_count ) ) { |
|---|
| 157 | + $revision_version = $revisions[$key]->comment_count; |
|---|
| 158 | + $is_array = false; |
|---|
| 159 | + } else { |
|---|
| 160 | + continue; |
|---|
| 161 | + } |
|---|
| 162 | + |
|---|
| 163 | + if ( 1 == $revision_version ) { |
|---|
| 164 | + $post_author_name = get_the_author_meta( 'display_name', $revisions[$key]->post_author ); |
|---|
| 165 | + continue; |
|---|
| 166 | + } |
|---|
| 167 | + |
|---|
| 168 | + if ( $is_array ) { |
|---|
| 169 | + // swap |
|---|
| 170 | + list( |
|---|
| 171 | + $previous_author, |
|---|
| 172 | + $revisions[$key]['post_author'] |
|---|
| 173 | + ) = array( |
|---|
| 174 | + $revisions[$key]['post_author'], |
|---|
| 175 | + false === $previous_author ? $revisions[$key]['post_author'] : $previous_author |
|---|
| 176 | + ); |
|---|
| 177 | + $revisions[$key]['comment_count'] = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author |
|---|
| 178 | + } else { |
|---|
| 179 | + // swap |
|---|
| 180 | + list( |
|---|
| 181 | + $previous_author, |
|---|
| 182 | + $revisions[$key]->post_author |
|---|
| 183 | + ) = array( |
|---|
| 184 | + $revisions[$key]->post_author, |
|---|
| 185 | + false === $previous_author ? $revisions[$key]->post_author : $previous_author |
|---|
| 186 | + ); |
|---|
| 187 | + $revisions[$key]->comment_count = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author |
|---|
| 188 | + } |
|---|
| 189 | + } |
|---|
| 190 | + |
|---|
| 191 | + return $revisions; |
|---|
| 192 | +} |
|---|
| 193 | + |
|---|
| 194 | function _set_preview($post) { |
|---|
| 195 | |
|---|
| 196 | if ( ! is_object($post) ) |
|---|
| 197 | Index: wp-includes/comment.php |
|---|
| 198 | =================================================================== |
|---|
| 199 | --- wp-includes/comment.php (revision 23340) |
|---|
| 200 | +++ wp-includes/comment.php (working copy) |
|---|
| 201 | @@ -1615,6 +1615,8 @@ |
|---|
| 202 | return false; |
|---|
| 203 | if ( !$post = get_post($post_id) ) |
|---|
| 204 | return false; |
|---|
| 205 | + if ( 'revision' == $post->post_type ) |
|---|
| 206 | + return false; |
|---|
| 207 | |
|---|
| 208 | $old = (int) $post->comment_count; |
|---|
| 209 | $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) ); |
|---|
| 210 | Index: wp-admin/includes/post.php |
|---|
| 211 | =================================================================== |
|---|
| 212 | --- wp-admin/includes/post.php (revision 23340) |
|---|
| 213 | +++ wp-admin/includes/post.php (working copy) |
|---|
| 214 | @@ -241,8 +241,6 @@ |
|---|
| 215 | |
|---|
| 216 | add_meta( $post_ID ); |
|---|
| 217 | |
|---|
| 218 | - update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); |
|---|
| 219 | - |
|---|
| 220 | wp_update_post( $post_data ); |
|---|
| 221 | |
|---|
| 222 | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 223 | @@ -568,8 +566,6 @@ |
|---|
| 224 | |
|---|
| 225 | add_meta( $post_ID ); |
|---|
| 226 | |
|---|
| 227 | - add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); |
|---|
| 228 | - |
|---|
| 229 | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 230 | _fix_attachment_links( $post_ID ); |
|---|
| 231 | |
|---|
| 232 | Index: wp-admin/includes/meta-boxes.php |
|---|
| 233 | =================================================================== |
|---|
| 234 | --- wp-admin/includes/meta-boxes.php (revision 23340) |
|---|
| 235 | +++ wp-admin/includes/meta-boxes.php (working copy) |
|---|
| 236 | @@ -603,7 +603,8 @@ |
|---|
| 237 | * @param object $post |
|---|
| 238 | */ |
|---|
| 239 | function post_revisions_meta_box($post) { |
|---|
| 240 | - wp_list_post_revisions(); |
|---|
| 241 | + $args = array( 'parent' => true ); |
|---|
| 242 | + wp_list_post_revisions( $post, $args ); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | // -- Page related Meta Boxes |
|---|