Make WordPress Core

Ticket #23314: 23314.5.diff

File 23314.5.diff, 17.3 KB (added by adamsilverstein, 9 years ago)
  • wp-admin/css/common.css

     
    872872        line-height: 23px;
    873873}
    874874
    875 #publishing-action .spinner {
     875#major-publishing-actions .spinner,
     876#minor-publishing-actions .spinner {
    876877        float: left;
     878        margin: 4px 1px;
    877879}
    878880
    879881#misc-publishing-actions {
  • wp-admin/edit-form-advanced.php

     
    5555        remove_post_type_support( $post_type, 'editor' );
    5656}
    5757
     58$is_advanced_revision = false;
     59if ( 'revision' == $post->post_type ) {
     60        $parent = get_post( $post->post_parent );
     61        if ( isset( $parent->post_type ) && post_type_supports( $parent->post_type, 'advanced-revisions' ) ) {
     62                $is_advanced_revision = true;
     63        }
     64}
     65
    5866$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
    5967if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
    6068        if ( wp_attachment_is( 'audio', $post ) ) {
     
    123131         8 => __( 'Post submitted.' ) . $preview_link_html,
    124132         9 => sprintf( __( 'Post scheduled for: <strong>%1$s</strong>' ), $scheduled_date ) . $scheduled_link_html,
    125133        10 => __( 'Post draft updated.' ) . $preview_link_html,
     134        11 => __( 'A new version of this post has been created, but not published.' ),
     135        12 => __( 'Your changes have been saved, but not published.' ),
     136        13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ),
     137        14 => __( 'Your changes have been discarded.' ),
    126138);
    127139
    128140/** This filter is documented in wp-admin/includes/meta-boxes.php */
     
    140152         8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( $page_preview_url ) ),
    141153         9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
    142154        10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( $page_preview_url ) ),
     155        11 => __( 'A new version of this page has been created, but not published.' ),
     156        12 => __( 'Your changes have been saved, but not published.' ),
     157        13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View page</a>' ), esc_url( get_permalink( $post_ID ) ) ),
     158        14 => __( 'Your changes have been discarded.' ),
    143159);
    144160$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
    145161
     
    246262if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    247263        add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low');
    248264
    249 if ( post_type_supports($post_type, 'excerpt') )
     265if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) )
    250266        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    251267
    252268if ( post_type_supports($post_type, 'trackbacks') )
     
    271287if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
    272288        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    273289
    274 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
     290if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision )
    275291        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    276292
    277 if ( post_type_supports($post_type, 'author') ) {
     293if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) {
    278294        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
    279295                add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    280296}
     
    503519<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    504520<div id="post-body-content">
    505521
    506 <?php if ( post_type_supports($post_type, 'title') ) { ?>
     522<?php if ( post_type_supports( $post_type, 'title' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'title' ) ) ) { ?>
    507523<div id="titlediv">
    508524<div id="titlewrap">
    509525        <?php
     
    568584 */
    569585do_action( 'edit_form_after_title', $post );
    570586
    571 if ( post_type_supports($post_type, 'editor') ) {
     587if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) {
    572588?>
    573589<div id="postdivrich" class="postarea<?php if ( $_wp_editor_expand ) { echo ' wp-editor-expand'; } ?>">
    574590
  • wp-admin/includes/meta-boxes.php

     
    1717        $post_type = $post->post_type;
    1818        $post_type_object = get_post_type_object($post_type);
    1919        $can_publish = current_user_can($post_type_object->cap->publish_posts);
     20
     21        $is_advanced_revision = false;
     22        if ( 'revision' == $post->post_type && $post->post_parent ) {
     23                $parent = get_post( $post->post_parent );
     24                $is_advanced_revision = post_type_supports( $parent->post_type, 'advanced-revisions' );
     25        }
    2026?>
    2127<div class="submitbox" id="submitpost">
    2228
     
    2935
    3036<div id="minor-publishing-actions">
    3137<div id="save-action">
    32 <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
     38<?php if ( $is_advanced_revision ) { ?>
     39<input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Changes' ); ?>" class="button" />
     40<?php } elseif ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
    3341<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" />
    3442<span class="spinner"></span>
    3543<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    3644<input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" />
     45<?php } elseif ( 'publish' == $post->post_status && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { ?>
     46<input type="submit" name="save-version" id="save-post" value="<?php esc_attr_e( 'Save a Version' ); ?>" class="button" />
    3747<span class="spinner"></span>
    3848<?php } ?>
    3949</div>
    40 <?php if ( is_post_type_viewable( $post_type_object ) ) : ?>
     50<?php if ( $post_type_object->public || $is_advanced_revision ) : ?>
    4151<div id="preview-action">
    4252<?php
    4353if ( 'publish' == $post->post_status ) {
     
    5666         * @param WP_Post $post         Post object.
    5767         */
    5868        $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post ) );
    59         $preview_button = __( 'Preview' );
     69        $preview_button = ( $is_advanced_revision ) ? __( 'Preview Changes' ) : __( 'Preview' );
    6070}
    6171?>
    6272<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>
     
    6777</div><!-- #minor-publishing-actions -->
    6878
    6979<div id="misc-publishing-actions">
     80<?php if ( $is_advanced_revision ) : ?>
     81<?php else: ?>
    7082
    7183<div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e('Status:') ?></label>
    7284<span id="post-status-display">
     
    222234 */
    223235do_action( 'post_submitbox_misc_actions' );
    224236?>
    225 </div>
     237<?php endif; // $is_advanced_revision ?>
     238</div><!-- #misc-publishing-actions -->
    226239<div class="clear"></div>
    227240</div>
    228241
     
    242255                $delete_text = __('Delete Permanently');
    243256        else
    244257                $delete_text = __('Move to Trash');
     258
     259        $delete_link = get_delete_post_link( $post->ID );
     260        if ( $is_advanced_revision ) {
     261                $delete_text = __( 'Discard Changes' );
     262                $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) );
     263                $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" );
     264        }
    245265        ?>
    246 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php
     266<a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php
    247267} ?>
    248268</div>
    249269
     
    256276                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
    257277                <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false ); ?>
    258278<?php   else : ?>
     279                <?php $publish_label = ( $is_advanced_revision ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?>
     280                <?php if ( $is_advanced_revision ) : ?>
     281                        <input name="publish_revision" type="hidden" value="1" />
     282                <?php endif; ?>
    259283                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />
    260                 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false ); ?>
     284                <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    261285<?php   endif;
    262286        else : ?>
    263287                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" />
  • wp-admin/includes/post.php

     
    200200                }
    201201        }
    202202
     203        $is_advanced_revision = false;
     204        if ( 'revision' == $post->post_type ) {
     205                $parent = get_post( $post->post_parent );
     206                if ( isset( $parent->post_type ) && post_type_supports( $parent->post_type, 'advanced-revisions' ) ) {
     207                        $is_advanced_revision = true;
     208                }
     209        }
     210
    203211        $ptype = get_post_type_object($post_data['post_type']);
    204212        if ( !current_user_can( 'edit_post', $post_ID ) ) {
    205213                if ( 'page' == $post_data['post_type'] )
     
    366374
    367375        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    368376
    369         $success = wp_update_post( $post_data );
     377        if ( ! empty( $_POST['save-version'] ) && post_type_supports( $post->post_type, 'advanced-revisions' ) ) {
     378                unset( $post_data['post_ID'], $post_data['ID'] );
     379                $post_data['post_type'] = 'revision';
     380                $post_data['post_parent'] = $post_ID;
     381                $post_data['post_status'] = 'draft';
     382        }
     383
     384        if ( ! empty( $_POST['publish'] ) && $is_advanced_revision ) {
     385                if ( ! current_user_can( 'edit_post', $parent->ID ) )
     386                        wp_die( __( 'You are not allowed to edit this post.' ) );
     387
     388                unset( $post_data['post_parent'] );
     389                $post_data['post_type'] = $parent->post_type;
     390                $post_data['post_status'] = $parent->post_status;
     391                $post_data['ID'] = $parent->ID;
     392                $post_data['post_ID'] = $parent->ID;
     393
     394                // Discard the revision
     395                wp_delete_post( $post->ID, true );
     396        }
     397
     398        $post_ID = ( ! empty( $post_data['ID'] ) ) ? wp_update_post( $post_data ) : wp_insert_post( $post_data );
     399
     400
    370401        // If the save failed, see if we can sanity check the main fields and try again
    371         if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
     402        if ( ( ! $post_ID || 0 === $post_ID ) && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
    372403                $fields = array( 'post_title', 'post_content', 'post_excerpt' );
    373404
    374405                foreach ( $fields as $field ) {
     
    16861717        $post_ID = (int) $_POST['post_ID'];
    16871718        $_POST['ID'] = $post_ID;
    16881719
     1720        $parent = null;
     1721        $is_advanced_revision = null;
    16891722        if ( ! $post = get_post( $post_ID ) ) {
    16901723                wp_die( __( 'You are not allowed to edit this post.' ) );
    16911724        }
     
    16941727                wp_die( __( 'You are not allowed to edit this post.' ) );
    16951728        }
    16961729
     1730        if ( 'revision' == $post->post_type ) {
     1731                $parent = get_post( $post->post_parent );
     1732                if ( isset( $parent->post_type ) && post_type_supports( $parent->post_type, 'advanced-revisions' ) ) {
     1733                        $is_advanced_revision = true;
     1734                }
     1735        }
     1736
    16971737        $is_autosave = false;
    16981738
     1739        if ( $is_advanced_revision ) {
     1740                $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
     1741                $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), get_permalink( $parent->ID ) );
     1742                return apply_filters( 'preview_post_link', $url, $post );
     1743        }
     1744
    16991745        if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
    17001746                $saved_post_id = edit_post();
    17011747        } else {
  • wp-admin/post.php

     
    3636if ( $post ) {
    3737        $post_type = $post->post_type;
    3838        $post_type_object = get_post_type_object( $post_type );
     39
     40        if ( post_type_supports( $post_type, 'advanced-revisions' ) ) {
     41                $revisions = get_posts( array(
     42                        'post_parent' => $post->ID,
     43                        'post_type' => 'revision',
     44                        'post_status' => array( 'draft' ),
     45                ) );
     46
     47                if ( ! empty( $revisions ) && is_array( $revisions ) ) {
     48                        $revision = $revisions[0];
     49                        if ( current_user_can( 'edit_post', $revision->ID ) )
     50                                redirect_post( $revision->ID );
     51                }
     52        }
    3953}
    4054
    4155/**
     
    4458 * @param int $post_id Optional. Post ID.
    4559 */
    4660function redirect_post($post_id = '') {
    47         if ( isset($_POST['save']) || isset($_POST['publish']) ) {
     61        $post = get_post( $post_id );
     62
     63        $is_advanced_revision = false;
     64        if ( 'revision' == $post->post_type ) {
     65                $parent = get_post( $post->post_parent );
     66                if ( isset( $parent->post_type ) && post_type_supports( $parent->post_type, 'advanced-revisions' ) ) {
     67                        $is_advanced_revision = true;
     68                }
     69        }
     70
     71        if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) && ! $is_advanced_revision ) {
    4872                $status = get_post_status( $post_id );
    4973
    5074                if ( isset( $_POST['publish'] ) ) {
     
    6286                        $message = 'draft' == $status ? 10 : 1;
    6387                }
    6488
     89                if ( ! empty( $_POST['publish_revision'] ) )
     90                        $message = 13;
     91
    6592                $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
    6693        } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
    6794                $location = add_query_arg( 'message', 2, wp_get_referer() );
     
    7198                $location = add_query_arg( 'message', 3, wp_get_referer() );
    7299                $location = explode('#', $location);
    73100                $location = $location[0] . '#postcustom';
     101        } elseif ( $is_advanced_revision ) {
     102                $location = add_query_arg( 'post', $post->ID, get_edit_post_link( $parent->ID, 'url' ) );
     103
     104                if ( ! empty( $_POST['save-version'] ) ) {
     105                        $message = 11;
     106                } elseif ( ! empty( $_POST['save'] ) ) {
     107                        $message = 12;
     108                }
     109
     110                if ( $message ) {
     111                        $location = add_query_arg( 'message', $message, $location );
     112                }
     113
    74114        } else {
    75115                $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
    76116        }
     
    309349                        wp_die( __( 'Error in deleting.' ) );
    310350        }
    311351
     352        if ( 'revision' == $post->post_type ) {
     353                $parent = get_post( $post->post_parent );
     354                $sendback = get_edit_post_link( $post->post_parent, 'url' );
     355                $sendback = add_query_arg( 'message', 14, $sendback );
     356        }
     357
    312358        wp_redirect( add_query_arg('deleted', 1, $sendback) );
    313359        exit();
    314360
  • wp-includes/post-functions.php

     
    3131                'rewrite' => false,
    3232                'query_var' => false,
    3333                'delete_with_user' => true,
    34                 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
     34                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'advanced-revisions', 'post-formats' ),
    3535        ) );
    3636
    3737        register_post_type( 'page', array(
     
    4949                'rewrite' => false,
    5050                'query_var' => false,
    5151                'delete_with_user' => true,
    52                 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
     52                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions', 'advanced-revisions' ),
    5353        ) );
    5454
    5555        register_post_type( 'attachment', array(
     
    8383                'labels' => array(
    8484                        'name' => __( 'Revisions' ),
    8585                        'singular_name' => __( 'Revision' ),
     86                        'edit_item' => __( 'Edit Revision' ),
    8687                ),
    8788                'public' => false,
    8889                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
  • wp-includes/revision.php

     
    497497        }
    498498
    499499        $preview = wp_get_post_autosave( $post->ID );
     500
     501        // Possibly previewing a revision.
     502        if ( isset( $_GET['preview_id'] ) ) {
     503                $preview_id = (int) $_GET['preview_id'];
     504                if ( ( ! $preview || $preview->ID != $preview_id ) && current_user_can( 'read_post', $preview_id ) ) {
     505                        $revision = get_post( $preview_id );
     506                        if ( 'revision' == $revision->post_type && $revision->post_parent == $post->ID ) {
     507                                $preview = $revision;
     508                        }
     509                }
     510        }
     511
    500512        if ( ! is_object( $preview ) ) {
    501513                return $post;
    502514        }