WordPress.org

Make WordPress Core

Ticket #23314: 23314.3.diff

File 23314.3.diff, 17.3 KB (added by adamsilverstein, 6 years ago)

refresh against trunk

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

     
    4343$user_ID = isset($user_ID) ? (int) $user_ID : 0;
    4444$action = isset($action) ? $action : '';
    4545
     46$parent = null;
     47$is_advanced_revision = false;
     48if ( '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
    4654$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
    4755if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
    4856        if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
     
    7987                /* translators: Publish box date format, see http://php.net/date */
    8088                date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    8189        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.' ),
    8294);
    8395$messages['page'] = array(
    8496         0 => '', // Unused. Messages start at index 1.
     
    92104         8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    93105         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) ) ),
    94106        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.' ),
    95111);
    96112$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
    97113
     
    198214if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    199215        add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
    200216
    201 if ( post_type_supports($post_type, 'excerpt') )
     217if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) )
    202218        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    203219
    204220if ( post_type_supports($post_type, 'trackbacks') )
     
    223239if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
    224240        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    225241
    226 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
     242if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision )
    227243        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    228244
    229 if ( post_type_supports($post_type, 'author') ) {
     245if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) {
    230246        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
    231247                add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    232248}
     
    452468<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    453469<div id="post-body-content">
    454470
    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' ) ) ) { ?>
    456472<div id="titlediv">
    457473<div id="titlewrap">
    458474        <?php
     
    515531 */
    516532do_action( 'edit_form_after_title', $post );
    517533
    518 if ( post_type_supports($post_type, 'editor') ) {
     534if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) {
    519535?>
    520536<div id="postdivrich" class="postarea<?php if ( $_wp_editor_expand ) { echo ' wp-editor-expand'; } ?>">
    521537
  • 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, array( 'accesskey' => 'p' ) ); ?>
    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, array( 'accesskey' => 'p' ) ); ?>
     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') ?>" />
     
    755780 *                        include 'meta-box' or 'quick-edit'.
    756781 */
    757782$default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'meta-box' );
    758 ?> 
     783?>
    759784<option value="default"><?php echo esc_html( $default_title ); ?></option>
    760785<?php page_template_dropdown($template); ?>
    761786</select>
  • 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'] )
     
    318326
    319327        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    320328
    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
    322353        // 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' ) ) ) {
    324355                $fields = array( 'post_title', 'post_content', 'post_excerpt' );
    325356
    326357                foreach( $fields as $field ) {
     
    15881619        $post_ID = (int) $_POST['post_ID'];
    15891620        $_POST['ID'] = $post_ID;
    15901621
     1622        $parent = null;
     1623        $is_advanced_revision = null;
    15911624        if ( ! $post = get_post( $post_ID ) ) {
    15921625                wp_die( __( 'You are not allowed to edit this post.' ) );
    15931626        }
     
    15961629                wp_die( __( 'You are not allowed to edit this post.' ) );
    15971630        }
    15981631
     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
    15991638        $is_autosave = false;
    16001639
     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
    16011646        if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
    16021647                $saved_post_id = edit_post();
    16031648        } 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