Make WordPress Core

Ticket #23314: 23314.4.diff

File 23314.4.diff, 16.8 KB (added by adamsilverstein, 10 years ago)

refresh against trunk

  • wp-admin/edit-form-advanced.php

     
    4545$user_ID = isset($user_ID) ? (int) $user_ID : 0;
    4646$action = isset($action) ? $action : '';
    4747
     48$parent = null;
     49$is_advanced_revision = false;
     50if ( '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
    4856$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
    4957if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
    5058        if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
     
    8694                /* translators: Publish box date format, see http://php.net/date */
    8795                date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
    8896        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.' ),
    89101);
    90102$messages['page'] = array(
    91103         0 => '', // Unused. Messages start at index 1.
     
    99111         8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    100112         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 ) ),
    101113        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.' ),
    102118);
    103119$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
    104120
     
    205221if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    206222        add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
    207223
    208 if ( post_type_supports($post_type, 'excerpt') )
     224if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) )
    209225        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    210226
    211227if ( post_type_supports($post_type, 'trackbacks') )
     
    230246if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
    231247        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    232248
    233 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
     249if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision )
    234250        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    235251
    236 if ( post_type_supports($post_type, 'author') ) {
     252if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) {
    237253        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
    238254                add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    239255}
     
    459475<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    460476<div id="post-body-content">
    461477
    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' ) ) ) { ?>
    463479<div id="titlediv">
    464480<div id="titlewrap">
    465481        <?php
     
    522538 */
    523539do_action( 'edit_form_after_title', $post );
    524540
    525 if ( post_type_supports($post_type, 'editor') ) {
     541if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) {
    526542?>
    527543<div id="postdivrich" class="postarea<?php if ( $_wp_editor_expand ) { echo ' wp-editor-expand'; } ?>">
    528544
  • wp-admin/includes/meta-boxes.php

     
    1515        $post_type = $post->post_type;
    1616        $post_type_object = get_post_type_object($post_type);
    1717        $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        }
    1825?>
    1926<div class="submitbox" id="submitpost">
    2027
     
    2734
    2835<div id="minor-publishing-actions">
    2936<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 ) { ?>
    3140<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" />
    3241<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    3342<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" />
    3445<?php } ?>
    3546<span class="spinner"></span>
    3647</div>
    37 <?php if ( $post_type_object->public ) : ?>
     48<?php if ( $post_type_object->public || $is_advanced_revision ) : ?>
    3849<div id="preview-action">
    3950<?php
    4051if ( 'publish' == $post->post_status ) {
     
    5364         * @param WP_Post $post         Post object.
    5465         */
    5566        $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' );
    5768}
    5869?>
    5970<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>
     
    6475</div><!-- #minor-publishing-actions -->
    6576
    6677<div id="misc-publishing-actions">
     78<?php if ( $is_advanced_revision ) : ?>
     79<?php else: ?>
    6780
    6881<div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e('Status:') ?></label>
    6982<span id="post-status-display">
     
    216229 */
    217230do_action( 'post_submitbox_misc_actions' );
    218231?>
    219 </div>
     232<?php endif; // $is_advanced_revision ?>
     233</div><!-- #misc-publishing-actions -->
    220234<div class="clear"></div>
    221235</div>
    222236
     
    236250                $delete_text = __('Delete Permanently');
    237251        else
    238252                $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        }
    239260        ?>
    240 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php
     261<a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php
    241262} ?>
    242263</div>
    243264
     
    250271                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
    251272                <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false ); ?>
    252273<?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; ?>
    253278                <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' ) ); ?>
    255280<?php   endif;
    256281        else : ?>
    257282                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" />
  • wp-admin/includes/post.php

     
    198198                }
    199199        }
    200200
     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
    201209        $ptype = get_post_type_object($post_data['post_type']);
    202210        if ( !current_user_can( 'edit_post', $post_ID ) ) {
    203211                if ( 'page' == $post_data['post_type'] )
     
    364372
    365373        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    366374
    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
    368399        // 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' ) ) ) {
    370401                $fields = array( 'post_title', 'post_content', 'post_excerpt' );
    371402
    372403                foreach( $fields as $field ) {
     
    16491680        $post_ID = (int) $_POST['post_ID'];
    16501681        $_POST['ID'] = $post_ID;
    16511682
     1683        $parent = null;
     1684        $is_advanced_revision = null;
    16521685        if ( ! $post = get_post( $post_ID ) ) {
    16531686                wp_die( __( 'You are not allowed to edit this post.' ) );
    16541687        }
     
    16571690                wp_die( __( 'You are not allowed to edit this post.' ) );
    16581691        }
    16591692
     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
    16601699        $is_autosave = false;
    16611700
     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
    16621707        if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
    16631708                $saved_post_id = edit_post();
    16641709        } else {
  • wp-admin/post.php

     
    3131if ( $post ) {
    3232        $post_type = $post->post_type;
    3333        $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        }
    3448}
    3549
    3650/**
     
    3953 * @param int $post_id Optional. Post ID.
    4054 */
    4155function 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 ) {
    4367                $status = get_post_status( $post_id );
    4468
    4569                if ( isset( $_POST['publish'] ) ) {
     
    5781                                $message = 'draft' == $status ? 10 : 1;
    5882                }
    5983
     84                if ( ! empty( $_POST['publish_revision'] ) )
     85                        $message = 13;
     86
    6087                $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
    6188        } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
    6289                $location = add_query_arg( 'message', 2, wp_get_referer() );
     
    6693                $location = add_query_arg( 'message', 3, wp_get_referer() );
    6794                $location = explode('#', $location);
    6895                $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
    69109        } else {
    70110                $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    71111        }
     
    300340                        wp_die( __( 'Error in deleting.' ) );
    301341        }
    302342
     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
    303349        wp_redirect( add_query_arg('deleted', 1, $sendback) );
    304350        exit();
    305351
  • wp-includes/post.php

     
    3030                'rewrite' => false,
    3131                'query_var' => false,
    3232                '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' ),
    3434        ) );
    3535
    3636        register_post_type( 'page', array(
     
    4747                'rewrite' => false,
    4848                'query_var' => false,
    4949                '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' ),
    5151        ) );
    5252
    5353        register_post_type( 'attachment', array(
     
    8181                'labels' => array(
    8282                        'name' => __( 'Revisions' ),
    8383                        'singular_name' => __( 'Revision' ),
     84                        'edit_item' => __( 'Edit Revision' ),
    8485                ),
    8586                'public' => false,
    8687                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
  • wp-includes/revision.php

     
    495495
    496496        $preview = wp_get_post_autosave($post->ID);
    497497
     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        }
    498505        if ( ! is_object($preview) )
    499506                return $post;
    500507