Ticket #23314: 23314.3.diff
File 23314.3.diff, 17.3 KB (added by , 10 years ago) |
---|
-
wp-admin/edit-form-advanced.php
43 43 $user_ID = isset($user_ID) ? (int) $user_ID : 0; 44 44 $action = isset($action) ? $action : ''; 45 45 46 $parent = null; 47 $is_advanced_revision = false; 48 if ( 'revision' == $post->post_type ) { 49 $parent = get_post( $post->post_parent ); 50 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 51 $is_advanced_revision = true; 52 } 53 46 54 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ); 47 55 if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) { 48 56 if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) { … … 79 87 /* translators: Publish box date format, see http://php.net/date */ 80 88 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 81 89 10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 90 11 => __( 'A new version of this post has been created, but not published.' ), 91 12 => __( 'Your changes have been saved, but not published.' ), 92 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ), 93 14 => __( 'Your changes have been discarded.' ), 82 94 ); 83 95 $messages['page'] = array( 84 96 0 => '', // Unused. Messages start at index 1. … … 92 104 8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 93 105 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( get_permalink($post_ID) ) ), 94 106 10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 107 11 => __( 'A new version of this page has been created, but not published.' ), 108 12 => __( 'Your changes have been saved, but not published.' ), 109 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View page</a>' ), esc_url( get_permalink( $post_ID ) ) ), 110 14 => __( 'Your changes have been discarded.' ), 95 111 ); 96 112 $messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now. 97 113 … … 198 214 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) 199 215 add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 200 216 201 if ( post_type_supports($post_type, 'excerpt') )217 if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) ) 202 218 add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); 203 219 204 220 if ( post_type_supports($post_type, 'trackbacks') ) … … 223 239 if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') ) 224 240 add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); 225 241 226 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )242 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision ) 227 243 add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); 228 244 229 if ( post_type_supports($post_type, 'author') ) {245 if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) { 230 246 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) 231 247 add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); 232 248 } … … 452 468 <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> 453 469 <div id="post-body-content"> 454 470 455 <?php if ( post_type_supports( $post_type, 'title') ) { ?>471 <?php if ( post_type_supports( $post_type, 'title' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'title' ) ) ) { ?> 456 472 <div id="titlediv"> 457 473 <div id="titlewrap"> 458 474 <?php … … 515 531 */ 516 532 do_action( 'edit_form_after_title', $post ); 517 533 518 if ( post_type_supports( $post_type, 'editor') ) {534 if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) { 519 535 ?> 520 536 <div id="postdivrich" class="postarea<?php if ( $_wp_editor_expand ) { echo ' wp-editor-expand'; } ?>"> 521 537 -
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, array( 'accesskey' => 'p' ) ); ?> 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, array( 'accesskey' => 'p' ) ); ?>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') ?>" /> … … 755 780 * include 'meta-box' or 'quick-edit'. 756 781 */ 757 782 $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' ); 758 ?> 783 ?> 759 784 <option value="default"><?php echo esc_html( $default_title ); ?></option> 760 785 <?php page_template_dropdown($template); ?> 761 786 </select> -
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'] ) … … 318 326 319 327 update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); 320 328 321 $success = wp_update_post( $post_data ); 329 if ( ! empty( $_POST['save-version'] ) && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { 330 unset( $post_data['post_ID'], $post_data['ID'] ); 331 $post_data['post_type'] = 'revision'; 332 $post_data['post_parent'] = $post_ID; 333 $post_data['post_status'] = 'draft'; 334 } 335 336 if ( ! empty( $_POST['publish'] ) && $is_advanced_revision ) { 337 if ( ! current_user_can( 'edit_post', $parent->ID ) ) 338 wp_die( __( 'You are not allowed to edit this post.' ) ); 339 340 unset( $post_data['post_parent'] ); 341 $post_data['post_type'] = $parent->post_type; 342 $post_data['post_status'] = $parent->post_status; 343 $post_data['ID'] = $parent->ID; 344 $post_data['post_ID'] = $parent->ID; 345 346 // Discard the revision 347 wp_delete_post( $post->ID, true ); 348 } 349 350 $post_ID = ( ! empty( $post_data['ID'] ) ) ? wp_update_post( $post_data ) : wp_insert_post( $post_data ); 351 352 322 353 // If the save failed, see if we can sanity check the main fields and try again 323 if ( ! $success&& is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {354 if ( ( ! $post_ID || 0 === $post_ID ) && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { 324 355 $fields = array( 'post_title', 'post_content', 'post_excerpt' ); 325 356 326 357 foreach( $fields as $field ) { … … 1588 1619 $post_ID = (int) $_POST['post_ID']; 1589 1620 $_POST['ID'] = $post_ID; 1590 1621 1622 $parent = null; 1623 $is_advanced_revision = null; 1591 1624 if ( ! $post = get_post( $post_ID ) ) { 1592 1625 wp_die( __( 'You are not allowed to edit this post.' ) ); 1593 1626 } … … 1596 1629 wp_die( __( 'You are not allowed to edit this post.' ) ); 1597 1630 } 1598 1631 1632 if ( 'revision' == $post->post_type ) { 1633 $parent = get_post( $post->post_parent ); 1634 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 1635 $is_advanced_revision = true; 1636 } 1637 1599 1638 $is_autosave = false; 1600 1639 1640 if ( $is_advanced_revision ) { 1641 $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); 1642 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), get_permalink( $parent->ID ) ); 1643 return apply_filters( 'preview_post_link', $url, $post ); 1644 } 1645 1601 1646 if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) { 1602 1647 $saved_post_id = edit_post(); 1603 1648 } 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