Ticket #23665: 23665.patch
File 23665.patch, 6.3 KB (added by , 12 years ago) |
---|
-
wp-admin/edit-form-advanced.php
168 168 add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); 169 169 } 170 170 171 // TODO review this count() - why do we need to add it? 172 if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && count ( wp_get_post_revisions( $post_ID ) ) > 1 ) 171 if ( post_type_supports($post_type, 'revisions') ) 173 172 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); 174 173 175 174 do_action('add_meta_boxes', $post_type, $post); -
wp-admin/includes/ajax-actions.php
1038 1038 $do_autosave = (bool) $_POST['autosave']; 1039 1039 $do_lock = true; 1040 1040 1041 if ( ! $user_id = get_current_user_id() ) 1042 wp_die('-1'); 1043 1041 1044 $data = $alert = ''; 1042 1045 /* translators: draft saved date format, see http://php.net/date */ 1043 1046 $draft_saved_date_format = __('g:i:s a'); … … 1057 1060 $_POST['post_status'] = 'draft'; 1058 1061 1059 1062 if ( $last = wp_check_post_lock( $post->ID ) ) { 1060 $do_ autosave = $do_lock = false;1063 $do_lock = false; 1061 1064 1062 1065 $last_user = get_userdata( $last ); 1063 1066 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 1064 $data = __( 'Autosave disabled.' );1065 1066 $supplemental['disable_autosave'] = 'disable';1067 1067 $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) ); 1068 1068 } 1069 1069 … … 1076 1076 } 1077 1077 1078 1078 if ( $do_autosave ) { 1079 // Drafts and auto-drafts are just overwritten by autosave 1080 if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status) {1079 // Drafts and auto-drafts are just overwritten by autosave for the same user 1080 if ( $user_id == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { 1081 1081 $id = edit_post(); 1082 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision .1082 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision for each user. 1083 1083 $revision_id = wp_create_post_autosave( $post->ID ); 1084 1084 if ( is_wp_error($revision_id) ) 1085 1085 $id = $revision_id; -
wp-admin/includes/post.php
1236 1236 if ( is_wp_error( $translated ) ) 1237 1237 return $translated; 1238 1238 1239 // Only store one autosave. If there is already an autosave, overwrite it. 1240 if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { 1239 $post_author = get_current_user_id(); 1240 1241 // Store one autosave per author. If there is already an autosave, overwrite it. 1242 if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { 1241 1243 $new_autosave = _wp_post_revision_fields( $_POST, true ); 1242 1244 $new_autosave['ID'] = $old_autosave->ID; 1243 $new_autosave['post_author'] = get_current_user_id();1245 $new_autosave['post_author'] = $post_author; 1244 1246 return wp_update_post( $new_autosave ); 1245 1247 } 1246 1248 -
wp-admin/post.php
169 169 add_action('admin_notices', '_admin_notice_post_locked' ); 170 170 } else { 171 171 $active_post_lock = wp_set_post_lock( $post->ID ); 172 173 if ( 'attachment' !== $post_type )174 wp_enqueue_script('autosave');175 172 } 176 173 174 if ( 'attachment' !== $post_type ) 175 wp_enqueue_script('autosave'); 176 177 177 $title = $post_type_object->labels->edit_item; 178 178 $post = get_post($post_id, OBJECT, 'edit'); 179 179 -
wp-includes/revision.php
135 135 * Retrieve the autosaved data of the specified post. 136 136 * 137 137 * Returns a post object containing the information that was autosaved for the 138 * specified post. 138 * specified post. If the optional $user_id is passed, returns the autosave for that user 139 * otherwise returns the latest autosave. 139 140 * 140 141 * @package WordPress 141 142 * @subpackage Post_Revisions 142 143 * @since 2.6.0 143 144 * 144 145 * @param int $post_id The post ID. 146 * @param int $user_id optional The post author ID. 145 147 * @return object|bool The autosaved data or false on failure or when no autosave exists. 146 148 */ 147 function wp_get_post_autosave( $post_id ) { 149 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 150 $revisions = wp_get_post_revisions($post_id); 148 151 149 if ( !$post = get_post( $post_id ) ) 150 return false; 152 foreach ( $revisions as $revision ) { 153 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { 154 if ( $user_id && $user_id != $revision->post_author ) 155 continue; 151 156 152 $q = array( 153 'name' => "{$post->ID}-autosave", 154 'post_parent' => $post->ID, 155 'post_type' => 'revision', 156 'post_status' => 'inherit' 157 ); 157 return $revision; 158 break; 159 } 160 } 158 161 159 // Use WP_Query so that the result gets cached160 $autosave_query = new WP_Query;161 162 add_action( 'parse_query', '_wp_get_post_autosave_hack' );163 $autosave = $autosave_query->query( $q );164 remove_action( 'parse_query', '_wp_get_post_autosave_hack' );165 166 if ( $autosave && is_array($autosave) && is_object($autosave[0]) )167 return $autosave[0];168 169 162 return false; 170 163 } 171 164 172 165 /** 173 * Internally used to hack WP_Query into submission.174 *175 * @package WordPress176 * @subpackage Post_Revisions177 * @since 2.6.0178 *179 * @param object $query WP_Query object180 */181 function _wp_get_post_autosave_hack( $query ) {182 $query->is_single = false;183 }184 185 /**186 166 * Determines if the specified post is a revision. 187 167 * 188 168 * @package WordPress … … 211 191 function wp_is_post_autosave( $post ) { 212 192 if ( !$post = wp_get_post_revision( $post ) ) 213 193 return false; 214 if ( "{$post->post_parent}-autosave" !== $post->post_name ) 215 return false; 216 return (int) $post->post_parent; 194 195 if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) 196 return (int) $post->post_parent; 197 198 return false; 217 199 } 218 200 219 201 /**