Ticket #23314: 23314.diff
File 23314.diff, 12.6 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
5245 5245 5246 5246 $preview = wp_get_post_autosave($post->ID); 5247 5247 5248 $preview_id = (int) $_GET['preview_id']; 5249 if ( $preview->ID != $preview_id ) { 5250 $actual_preview = get_post( $preview_id ); 5251 if ( 'revision' == $actual_preview->post_type ) 5252 $preview = $actual_preview; 5253 } 5254 5248 5255 if ( ! is_object($preview) ) 5249 5256 return $post; 5250 5257 -
wp-admin/includes/post.php
243 243 244 244 update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); 245 245 246 wp_update_post( $post_data ); 246 if ( ! empty( $_POST['save-as-draft'] ) ) { 247 unset( $post_data['post_ID'], $post_data['ID'] ); 248 $post_data['post_type'] = 'revision'; 249 $post_data['post_parent'] = $post_ID; 250 $post_data['post_status'] = 'draft'; 251 } 247 252 253 if ( ! empty( $_POST['publish'] ) && 'revision' == $post->post_type && current_user_can( 'publish_posts' ) ) { 254 $parent = get_post( $post->post_parent ); 255 if ( ! current_user_can( 'edit_post', $parent->ID ) ) 256 wp_die( __( 'You are not allowed to edit this post.' ) ); 257 258 unset( $post_data['post_parent'] ); 259 $post_data['post_type'] = $parent->post_type; 260 $post_data['post_status'] = $parent->post_status; 261 $post_data['post_ID'] = $parent->ID; 262 $post_data['ID'] = $parent->ID; 263 264 // Discard the draft 265 wp_delete_post( $post->ID, true ); 266 } 267 268 if ( ! empty( $post_data['post_ID'] ) ) 269 $post_ID = wp_update_post( $post_data ); 270 else 271 $post_ID = wp_insert_post( $post_data ); 272 248 273 // Now that we have an ID we can fix any attachment anchor hrefs 249 274 _fix_attachment_links( $post_ID ); 250 275 … … 1298 1323 if ( is_wp_error($id) ) 1299 1324 wp_die( $id->get_error_message() ); 1300 1325 1301 if ( $_POST['post_status'] == 'draft' ) { 1326 $post_status = $_POST['post_status']; 1327 $preview_id = $id; 1328 1329 if ( 'revision' == $post->post_type ) { 1330 $parent = get_post( $post->post_parent ); 1331 $post_status = $parent->post_status; 1332 $id = $parent->ID; 1333 $preview_id = $post->ID; 1334 } 1335 1336 if ( $post_status == 'draft' ) { 1302 1337 $url = add_query_arg( 'preview', 'true', get_permalink($id) ); 1303 1338 } else { 1304 $nonce = wp_create_nonce('post_preview_' . $ id);1305 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $ id, 'preview_nonce' => $nonce ), get_permalink($id) );1339 $nonce = wp_create_nonce('post_preview_' . $preview_id); 1340 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $preview_id, 'preview_nonce' => $nonce ), get_permalink($id) ); 1306 1341 } 1307 1342 1308 1343 return $url; -
wp-admin/includes/meta-boxes.php
13 13 global $action; 14 14 15 15 $post_type = $post->post_type; 16 17 if ( 'revision' == $post_type ) { 18 $parent = get_post( $post->post_parent ); 19 $post_type = $parent->post_type; 20 } 21 16 22 $post_type_object = get_post_type_object($post_type); 17 23 $can_publish = current_user_can($post_type_object->cap->publish_posts); 24 25 $revision = null; 26 if ( 'publish' == $post->post_status ) { 27 $revisions = get_posts( array( 28 'post_parent' => $post->ID, 29 'post_type' => 'revision', 30 'post_status' => array( 'draft' ), 31 'posts_per_page' => 1, 32 ) ); 33 34 if ( ! empty( $revisions ) && is_array( $revisions ) ) { 35 $revision = $revisions[0]; 36 $edit_revision_link = add_query_arg( 'post', $revision->ID, get_edit_post_link( $post->ID ) ); 37 } 38 } 18 39 ?> 19 40 <div class="submitbox" id="submitpost"> 20 41 … … 31 52 <input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" /> 32 53 <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 33 54 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> 55 <?php } elseif ( 'publish' == $post->post_status && ( ! $revision || ! current_user_can( 'edit_post', $revision ) ) ) { ?> 56 <input type="submit" name="save-as-draft" id="save-post" value="<?php esc_attr_e('Save as Draft'); ?>" class="button" /> 34 57 <?php } ?> 35 58 <span class="spinner"></span> 36 59 </div> … … 45 68 $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) ); 46 69 $preview_button = __( 'Preview' ); 47 70 } 71 72 if ( 'revision' == $post->post_type ) 73 $preview_button = __( 'Preview Changes' ); 48 74 ?> 49 75 <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview" id="post-preview"><?php echo $preview_button; ?></a> 50 76 <input type="hidden" name="wp-preview" id="wp-preview" value="" /> … … 55 81 56 82 <div id="misc-publishing-actions"> 57 83 84 <?php if ( 'revision' == $post->post_type ) : ?> 85 <?php else : ?> 58 86 <div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label> 59 87 <span id="post-status-display"> 60 88 <?php … … 180 208 </div><?php // /misc-pub-section ?> 181 209 <?php endif; ?> 182 210 211 <?php endif; // !revision ?> 212 183 213 <?php do_action('post_submitbox_misc_actions'); ?> 184 214 </div> 185 215 <div class="clear"></div> … … 194 224 $delete_text = __('Delete Permanently'); 195 225 else 196 226 $delete_text = __('Move to Trash'); 227 228 $delete_link = get_delete_post_link( $post->ID ); 229 if ( 'revision' == $post->post_type ) { 230 $delete_text = __( 'Discard Changes' ); 231 $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) ); 232 $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" ); 233 } 197 234 ?> 198 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php235 <a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo $delete_text; ?></a><?php 199 236 } ?> 200 237 </div> 201 238 … … 208 245 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> 209 246 <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 210 247 <?php else : ?> 248 <?php $publish_label = ( 'revision' == $post->post_type ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?> 249 <?php if ( 'revision' == $post->post_type ) : ?> 250 <input type="hidden" name="publish-revision" value="1" /> 251 <?php endif; ?> 211 252 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> 212 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>253 <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 213 254 <?php endif; 214 255 else : ?> 215 256 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" /> -
wp-admin/post.php
31 31 if ( $post ) { 32 32 $post_type = $post->post_type; 33 33 $post_type_object = get_post_type_object( $post_type ); 34 35 $revisions = get_posts( array( 36 'post_parent' => $post->ID, 37 'post_type' => 'revision', 38 'post_status' => array( 'draft' ), 39 ) ); 40 41 if ( ! empty( $revisions ) && is_array( $revisions ) ) { 42 $revision = $revisions[0]; 43 if ( current_user_can( 'edit_post', $revision->ID ) ) { 44 redirect_post( $revision->ID ); 45 } 46 } 34 47 } 35 48 36 49 /** … … 39 52 * @param int $post_id Optional. Post ID. 40 53 */ 41 54 function redirect_post($post_id = '') { 55 56 $post = get_post( $post_id ); 57 if ( 'revision' == $post->post_type ) 58 $post_id = $post->post_parent; 59 42 60 if ( isset($_POST['save']) || isset($_POST['publish']) ) { 43 61 $status = get_post_status( $post_id ); 44 62 … … 53 71 default: 54 72 $message = 6; 55 73 } 74 75 if ( ! empty( $_POST['publish-revision'] ) ) 76 $message = 12; 56 77 } else { 57 78 $message = 'draft' == $status ? 10 : 1; 58 79 } … … 72 93 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 73 94 } 74 95 96 if ( 'revision' == $post->post_type ) { 97 $post_id = $post->ID; 98 $location = add_query_arg( 'post', $post->ID, $location ); 99 100 if ( ! empty( $_POST['save-as-draft'] ) || ! empty( $_POST['save'] ) ) 101 $location = add_query_arg( 'message', 13, $location ); 102 else 103 $location = remove_query_arg( 'message', $location ); 104 } 105 75 106 wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); 76 107 exit; 77 108 } … … 135 166 136 167 $p = $post_id; 137 168 169 $post_type = $post->post_type; 170 if ( 'revision' == $post_type && ! empty( $post->post_parent ) ) { 171 $parent = get_post( $post->post_parent ); 172 $post_type = $parent->post_type; 173 $post_type_object = get_post_type_object( $post_type ); 174 } 175 138 176 if ( empty($post->ID) ) 139 177 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') ); 140 178 … … 147 185 if ( 'trash' == $post->post_status ) 148 186 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 149 187 150 $post_type = $post->post_type;151 188 if ( 'post' == $post_type ) { 152 189 $parent_file = "edit.php"; 153 190 $submenu_file = "edit.php"; … … 182 219 enqueue_comment_hotkeys_js(); 183 220 } 184 221 222 set_current_screen( $post_type ); 223 185 224 include('./edit-form-advanced.php'); 186 225 187 226 break; … … 243 282 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 244 283 wp_die( __('You are not allowed to delete this item.') ); 245 284 285 if ( 'revision' == $post->post_type ) { 286 $sendback = add_query_arg( 'message', 11, get_edit_post_link( $post->post_parent, 'raw' ) ); 287 } 288 246 289 $force = !EMPTY_TRASH_DAYS; 247 290 if ( $post->post_type == 'attachment' ) { 248 291 $force = ( $force || !MEDIA_TRASH ); … … 259 302 260 303 case 'preview': 261 304 check_admin_referer( 'autosave', 'autosavenonce' ); 262 263 305 $url = post_preview(); 264 306 265 307 wp_redirect($url); -
wp-admin/edit-form-advanced.php
45 45 // translators: Publish box date format, see http://php.net/date 46 46 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 47 47 10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 48 11 => __( 'Your changes have been discarded.' ), 49 12 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ), 50 13 => __( 'Your changes have been saved, but not published.' ), 48 51 ); 49 52 $messages['page'] = array( 50 53 0 => '', // Unused. Messages start at index 1. … … 296 299 <?php if ( $message ) : ?> 297 300 <div id="message" class="updated"><p><?php echo $message; ?></p></div> 298 301 <?php endif; ?> 302 <?php 303 $revision = null; 304 $revisions = get_posts( array( 305 'post_parent' => $post->ID, 306 'post_type' => 'revision', 307 'post_status' => array( 'draft' ), 308 ) ); 309 310 if ( ! empty( $revisions ) && is_array( $revisions ) ) { 311 $revision = $revisions[0]; 312 $edit_revision_link = add_query_arg( 'post', $revision->ID, get_edit_post_link( $post->ID ) ); 313 } 314 ?> 315 <?php if ( 'revision' == $post->post_type ) : ?> 316 <div class="updated"> 317 <p>These changes are not published. <a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>">View published post</a>.</p> 318 </div> 319 <?php endif; ?> 299 320 <form name="post" action="post.php" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>> 300 321 <?php wp_nonce_field($nonce_action); ?> 301 322 <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" /> … … 336 357 if ( !empty($shortlink) ) 337 358 $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt('URL:', jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>'; 338 359 339 if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>360 if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) && 'revision' != $post->post_type ) { ?> 340 361 <div id="edit-slug-box" class="hide-if-no-js"> 341 362 <?php 342 363 if ( $sample_permalink_html && 'auto-draft' != $post->post_status )