Changeset 24790 for trunk/wp-admin/includes/revision.php
- Timestamp:
- 07/24/2013 06:08:14 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/revision.php
r24761 r24790 33 33 34 34 // If comparing revisions, make sure we're dealing with the right post parent. 35 if ( $compare_from && $compare_from->post_parent !== $post->ID ) 36 return false; 37 if ( $compare_to->post_parent !== $post->ID ) 35 // The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. 36 if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) 37 return false; 38 if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) 38 39 return false; 39 40 … … 92 93 $now_gmt = time(); 93 94 94 $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) ); 95 $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); 96 // If revisions are disabled, we only want autosaves and the current post. 97 if ( ! wp_revisions_enabled( $post ) ) { 98 foreach ( $revisions as $revision_id => $revision ) { 99 if ( ! wp_is_post_autosave( $revision ) ) 100 unset( $revisions[ $revision_id ] ); 101 } 102 $revisions = array( $post->ID => $post ) + $revisions; 103 } 104 95 105 $show_avatars = get_option( 'show_avatars' ); 96 106 97 107 cache_users( wp_list_pluck( $revisions, 'post_author' ) ); 108 109 $can_restore = current_user_can( 'edit_post', $post->ID ); 98 110 99 111 foreach ( $revisions as $revision ) { 100 112 $modified = strtotime( $revision->post_modified ); 101 113 $modified_gmt = strtotime( $revision->post_modified_gmt ); 102 $restore_link = str_replace( '&', '&', wp_nonce_url( 103 add_query_arg( 104 array( 'revision' => $revision->ID, 105 'action' => 'restore' ), 106 admin_url( 'revision.php' ) 107 ), 108 "restore-post_{$revision->ID}" 109 ) ); 114 if ( $can_restore ) { 115 $restore_link = str_replace( '&', '&', wp_nonce_url( 116 add_query_arg( 117 array( 'revision' => $revision->ID, 118 'action' => 'restore' ), 119 admin_url( 'revision.php' ) 120 ), 121 "restore-post_{$revision->ID}" 122 ) ); 123 } 110 124 111 125 if ( ! isset( $authors[ $revision->post_author ] ) ) { … … 117 131 } 118 132 119 $autosave = wp_is_post_autosave( $revision );133 $autosave = (bool) wp_is_post_autosave( $revision ); 120 134 $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; 121 135 if ( $current && ! empty( $current_id ) ) { 136 // If multiple revisions have the same post_modified_gmt, highest ID is current. 122 137 if ( $current_id < $revision->ID ) { 123 138 $revisions[ $current_id ]['current'] = false; … … 139 154 'autosave' => $autosave, 140 155 'current' => $current, 141 'restoreUrl' => urldecode( $restore_link ),156 'restoreUrl' => $can_restore ? $restore_link : false, 142 157 ); 143 158 } … … 145 160 // If a post has been saved since the last revision (no revisioned fields were changed) 146 161 // we may not have a "current" revision. Mark the latest revision as "current". 147 if ( empty( $current_id ) ) 148 $revisions[ $revision->ID ]['current'] = true; 162 if ( empty( $current_id ) ) { 163 if ( $revisions[ $revision->ID ]['autosave'] ) { 164 $revision = end( $revisions ); 165 while ( $revision['autosave'] ) { 166 $revision = prev( $revisions ); 167 } 168 $current_id = $revision['id']; 169 } else { 170 $current_id = $revision->ID; 171 } 172 $revisions[ $current_id ]['current'] = true; 173 } 149 174 150 175 // Now, grab the initial diff
Note: See TracChangeset
for help on using the changeset viewer.