Ticket #23314: 23314.4.diff
File 23314.4.diff, 16.8 KB (added by , 10 years ago) |
---|
-
wp-admin/edit-form-advanced.php
45 45 $user_ID = isset($user_ID) ? (int) $user_ID : 0; 46 46 $action = isset($action) ? $action : ''; 47 47 48 $parent = null; 49 $is_advanced_revision = false; 50 if ( 'revision' == $post->post_type ) { 51 $parent = get_post( $post->post_parent ); 52 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 53 $is_advanced_revision = true; 54 } 55 48 56 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ); 49 57 if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) { 50 58 if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) { … … 86 94 /* translators: Publish box date format, see http://php.net/date */ 87 95 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ), 88 96 10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), 97 11 => __( 'A new version of this post has been created, but not published.' ), 98 12 => __( 'Your changes have been saved, but not published.' ), 99 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ), 100 14 => __( 'Your changes have been discarded.' ), 89 101 ); 90 102 $messages['page'] = array( 91 103 0 => '', // Unused. Messages start at index 1. … … 99 111 8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), 100 112 9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ), 101 113 10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ), 114 11 => __( 'A new version of this page has been created, but not published.' ), 115 12 => __( 'Your changes have been saved, but not published.' ), 116 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View page</a>' ), esc_url( get_permalink( $post_ID ) ) ), 117 14 => __( 'Your changes have been discarded.' ), 102 118 ); 103 119 $messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now. 104 120 … … 205 221 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) 206 222 add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 207 223 208 if ( post_type_supports($post_type, 'excerpt') )224 if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) ) 209 225 add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); 210 226 211 227 if ( post_type_supports($post_type, 'trackbacks') ) … … 230 246 if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') ) 231 247 add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); 232 248 233 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )249 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision ) 234 250 add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); 235 251 236 if ( post_type_supports($post_type, 'author') ) {252 if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) { 237 253 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) 238 254 add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); 239 255 } … … 459 475 <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> 460 476 <div id="post-body-content"> 461 477 462 <?php if ( post_type_supports( $post_type, 'title') ) { ?>478 <?php if ( post_type_supports( $post_type, 'title' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'title' ) ) ) { ?> 463 479 <div id="titlediv"> 464 480 <div id="titlewrap"> 465 481 <?php … … 522 538 */ 523 539 do_action( 'edit_form_after_title', $post ); 524 540 525 if ( post_type_supports( $post_type, 'editor') ) {541 if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) { 526 542 ?> 527 543 <div id="postdivrich" class="postarea<?php if ( $_wp_editor_expand ) { echo ' wp-editor-expand'; } ?>"> 528 544 -
wp-admin/includes/meta-boxes.php
15 15 $post_type = $post->post_type; 16 16 $post_type_object = get_post_type_object($post_type); 17 17 $can_publish = current_user_can($post_type_object->cap->publish_posts); 18 19 $parent = null; 20 $is_advanced_revision = false; 21 if ( 'revision' == $post->post_type && $post->post_parent ) { 22 $parent = get_post( $post->post_parent ); 23 $is_advanced_revision = post_type_supports( $parent->post_type, 'advanced-revisions' ); 24 } 18 25 ?> 19 26 <div class="submitbox" id="submitpost"> 20 27 … … 27 34 28 35 <div id="minor-publishing-actions"> 29 36 <div id="save-action"> 30 <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 37 <?php if ( $is_advanced_revision ) { ?> 38 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Changes' ); ?>" class="button" /> 39 <?php } elseif ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 31 40 <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 41 <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 33 42 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> 43 <?php } elseif ( 'publish' == $post->post_status && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { ?> 44 <input type="submit" name="save-version" id="save-post" value="<?php esc_attr_e( 'Save a Version' ); ?>" class="button" /> 34 45 <?php } ?> 35 46 <span class="spinner"></span> 36 47 </div> 37 <?php if ( $post_type_object->public ) : ?>48 <?php if ( $post_type_object->public || $is_advanced_revision ) : ?> 38 49 <div id="preview-action"> 39 50 <?php 40 51 if ( 'publish' == $post->post_status ) { … … 53 64 * @param WP_Post $post Post object. 54 65 */ 55 66 $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post ) ); 56 $preview_button = __( 'Preview' );67 $preview_button = ( $is_advanced_revision ) ? __( 'Preview Changes' ) : __( 'Preview' ); 57 68 } 58 69 ?> 59 70 <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview-<?php echo (int) $post->ID; ?>" id="post-preview"><?php echo $preview_button; ?></a> … … 64 75 </div><!-- #minor-publishing-actions --> 65 76 66 77 <div id="misc-publishing-actions"> 78 <?php if ( $is_advanced_revision ) : ?> 79 <?php else: ?> 67 80 68 81 <div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e('Status:') ?></label> 69 82 <span id="post-status-display"> … … 216 229 */ 217 230 do_action( 'post_submitbox_misc_actions' ); 218 231 ?> 219 </div> 232 <?php endif; // $is_advanced_revision ?> 233 </div><!-- #misc-publishing-actions --> 220 234 <div class="clear"></div> 221 235 </div> 222 236 … … 236 250 $delete_text = __('Delete Permanently'); 237 251 else 238 252 $delete_text = __('Move to Trash'); 253 254 $delete_link = get_delete_post_link( $post->ID ); 255 if ( $is_advanced_revision ) { 256 $delete_text = __( 'Discard Changes' ); 257 $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) ); 258 $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" ); 259 } 239 260 ?> 240 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php261 <a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php 241 262 } ?> 242 263 </div> 243 264 … … 250 271 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> 251 272 <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false ); ?> 252 273 <?php else : ?> 274 <?php $publish_label = ( $is_advanced_revision ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?> 275 <?php if ( $is_advanced_revision ) : ?> 276 <input name="publish_revision" type="hidden" value="1" /> 277 <?php endif; ?> 253 278 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> 254 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false); ?>279 <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 255 280 <?php endif; 256 281 else : ?> 257 282 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" /> -
wp-admin/includes/post.php
198 198 } 199 199 } 200 200 201 $parent = null; 202 $is_advanced_revision = false; 203 if ( 'revision' == $post->post_type ) { 204 $parent = get_post( $post->post_parent ); 205 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 206 $is_advanced_revision = true; 207 } 208 201 209 $ptype = get_post_type_object($post_data['post_type']); 202 210 if ( !current_user_can( 'edit_post', $post_ID ) ) { 203 211 if ( 'page' == $post_data['post_type'] ) … … 364 372 365 373 update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); 366 374 367 $success = wp_update_post( $post_data ); 375 if ( ! empty( $_POST['save-version'] ) && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { 376 unset( $post_data['post_ID'], $post_data['ID'] ); 377 $post_data['post_type'] = 'revision'; 378 $post_data['post_parent'] = $post_ID; 379 $post_data['post_status'] = 'draft'; 380 } 381 382 if ( ! empty( $_POST['publish'] ) && $is_advanced_revision ) { 383 if ( ! current_user_can( 'edit_post', $parent->ID ) ) 384 wp_die( __( 'You are not allowed to edit this post.' ) ); 385 386 unset( $post_data['post_parent'] ); 387 $post_data['post_type'] = $parent->post_type; 388 $post_data['post_status'] = $parent->post_status; 389 $post_data['ID'] = $parent->ID; 390 $post_data['post_ID'] = $parent->ID; 391 392 // Discard the revision 393 wp_delete_post( $post->ID, true ); 394 } 395 396 $post_ID = ( ! empty( $post_data['ID'] ) ) ? wp_update_post( $post_data ) : wp_insert_post( $post_data ); 397 398 368 399 // If the save failed, see if we can sanity check the main fields and try again 369 if ( ! $success&& is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {400 if ( ( ! $post_ID || 0 === $post_ID ) && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { 370 401 $fields = array( 'post_title', 'post_content', 'post_excerpt' ); 371 402 372 403 foreach( $fields as $field ) { … … 1649 1680 $post_ID = (int) $_POST['post_ID']; 1650 1681 $_POST['ID'] = $post_ID; 1651 1682 1683 $parent = null; 1684 $is_advanced_revision = null; 1652 1685 if ( ! $post = get_post( $post_ID ) ) { 1653 1686 wp_die( __( 'You are not allowed to edit this post.' ) ); 1654 1687 } … … 1657 1690 wp_die( __( 'You are not allowed to edit this post.' ) ); 1658 1691 } 1659 1692 1693 if ( 'revision' == $post->post_type ) { 1694 $parent = get_post( $post->post_parent ); 1695 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 1696 $is_advanced_revision = true; 1697 } 1698 1660 1699 $is_autosave = false; 1661 1700 1701 if ( $is_advanced_revision ) { 1702 $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); 1703 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), get_permalink( $parent->ID ) ); 1704 return apply_filters( 'preview_post_link', $url, $post ); 1705 } 1706 1662 1707 if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) { 1663 1708 $saved_post_id = edit_post(); 1664 1709 } else { -
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 if ( post_type_supports( $post_type, 'advanced-revisions' ) ) { 36 $revisions = get_posts( array( 37 'post_parent' => $post->ID, 38 'post_type' => 'revision', 39 'post_status' => array( 'draft' ), 40 ) ); 41 42 if ( ! empty( $revisions ) && is_array( $revisions ) ) { 43 $revision = $revisions[0]; 44 if ( current_user_can( 'edit_post', $revision->ID ) ) 45 redirect_post( $revision->ID ); 46 } 47 } 34 48 } 35 49 36 50 /** … … 39 53 * @param int $post_id Optional. Post ID. 40 54 */ 41 55 function redirect_post($post_id = '') { 42 if ( isset($_POST['save']) || isset($_POST['publish']) ) { 56 $post = get_post( $post_id ); 57 58 $parent = null; 59 $is_advanced_revision = false; 60 if ( 'revision' == $post->post_type ) { 61 $parent = get_post( $post->post_parent ); 62 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 63 $is_advanced_revision = true; 64 } 65 66 if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) && ! $is_advanced_revision ) { 43 67 $status = get_post_status( $post_id ); 44 68 45 69 if ( isset( $_POST['publish'] ) ) { … … 57 81 $message = 'draft' == $status ? 10 : 1; 58 82 } 59 83 84 if ( ! empty( $_POST['publish_revision'] ) ) 85 $message = 13; 86 60 87 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 61 88 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 62 89 $location = add_query_arg( 'message', 2, wp_get_referer() ); … … 66 93 $location = add_query_arg( 'message', 3, wp_get_referer() ); 67 94 $location = explode('#', $location); 68 95 $location = $location[0] . '#postcustom'; 96 } elseif ( $is_advanced_revision ) { 97 $location = add_query_arg( 'post', $post->ID, get_edit_post_link( $parent->ID, 'url' ) ); 98 99 if ( ! empty( $_POST['save-version'] ) ) { 100 $message = 11; 101 } elseif ( ! empty( $_POST['save'] ) ) { 102 $message = 12; 103 } 104 105 if ( $message ) { 106 $location = add_query_arg( 'message', $message, $location ); 107 } 108 69 109 } else { 70 110 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 71 111 } … … 300 340 wp_die( __( 'Error in deleting.' ) ); 301 341 } 302 342 343 if ( 'revision' == $post->post_type ) { 344 $parent = get_post( $post->post_parent ); 345 $sendback = get_edit_post_link( $post->post_parent, 'url' ); 346 $sendback = add_query_arg( 'message', 14, $sendback ); 347 } 348 303 349 wp_redirect( add_query_arg('deleted', 1, $sendback) ); 304 350 exit(); 305 351 -
wp-includes/post.php
30 30 'rewrite' => false, 31 31 'query_var' => false, 32 32 'delete_with_user' => true, 33 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', ' post-formats' ),33 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'advanced-revisions', 'post-formats' ), 34 34 ) ); 35 35 36 36 register_post_type( 'page', array( … … 47 47 'rewrite' => false, 48 48 'query_var' => false, 49 49 'delete_with_user' => true, 50 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),50 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions', 'advanced-revisions' ), 51 51 ) ); 52 52 53 53 register_post_type( 'attachment', array( … … 81 81 'labels' => array( 82 82 'name' => __( 'Revisions' ), 83 83 'singular_name' => __( 'Revision' ), 84 'edit_item' => __( 'Edit Revision' ), 84 85 ), 85 86 'public' => false, 86 87 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ -
wp-includes/revision.php
495 495 496 496 $preview = wp_get_post_autosave($post->ID); 497 497 498 $preview_id = (int) $_GET['preview_id']; 499 if ( $preview->ID != $preview_id && current_user_can( 'read_post', $preview_id ) ) { 500 $revision = get_post( $preview_id ); 501 if ( 'revision' == $revision->post_type && $revision->post_parent == $post->ID ) { 502 $preview = $revision; 503 } 504 } 498 505 if ( ! is_object($preview) ) 499 506 return $post; 500 507