Make WordPress Core

Ticket #46671: 46671.2.diff

File 46671.2.diff, 3.2 KB (added by markparnell, 5 years ago)
  • wp-admin/revision.php

    diff --git a/wp-admin/revision.php b/wp-admin/revision.php
    index b1590ee6d7..d7410b2ac3 100644
    a b switch ( $action ) { 
    4242                        break;
    4343                }
    4444
    45                 $post = get_post( $revision->post_parent );
    46                 if ( ! $post ) {
     45                $parent = get_post( $revision->post_parent );
     46                if ( ! $parent ) {
    4747                        break;
    4848                }
    4949
    50                 // Restore if revisions are enabled or this is an autosave.
    51                 if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
    52                         $redirect = 'edit.php?post_type=' . $post->post_type;
     50                // Don't restore if revisions are disabled and this is not an autosave.
     51                if ( ! wp_revisions_enabled( $parent ) && ! wp_is_post_autosave( $revision ) ) {
     52                        $redirect = 'edit.php?post_type=' . $parent->post_type;
    5353                        break;
    5454                }
    5555
    5656                // Don't allow revision restore when post is locked.
    57                 if ( wp_check_post_lock( $post->ID ) ) {
     57                if ( wp_check_post_lock( $parent->ID ) ) {
    5858                        break;
    5959                }
    6060
     61                /**
     62                 * @global WP_Query $wp_query
     63                 */
     64                global $wp_query;
     65
     66                // Set up global post variables for the use of any functions hooked into restore process.
     67                $post = clone $parent;
     68                $wp_query->posts = array( $post );
     69                $wp_query->post = $post;
     70                setup_postdata( $post );
     71
    6172                check_admin_referer( "restore-post_{$revision->ID}" );
    6273
    6374                wp_restore_post_revision( $revision->ID );
    switch ( $action ) { 
    6677                                'message'  => 5,
    6778                                'revision' => $revision->ID,
    6879                        ),
    69                         get_edit_post_link( $post->ID, 'url' )
     80                        get_edit_post_link( $parent->ID, 'url' )
    7081                );
    7182                break;
    7283        case 'view':
    switch ( $action ) { 
    7788                        break;
    7889                }
    7990
    80                 $post = get_post( $revision->post_parent );
    81                 if ( ! $post ) {
     91                $parent = get_post( $revision->post_parent );
     92                if ( ! $parent ) {
    8293                        break;
    8394                }
    8495
    switch ( $action ) { 
    8798                }
    8899
    89100                // Revisions disabled and we're not looking at an autosave.
    90                 if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
    91                         $redirect = 'edit.php?post_type=' . $post->post_type;
     101                if ( ! wp_revisions_enabled( $parent ) && ! wp_is_post_autosave( $revision ) ) {
     102                        $redirect = 'edit.php?post_type=' . $parent->post_type;
    92103                        break;
    93104                }
    94105
    switch ( $action ) { 
    104115}
    105116
    106117// Empty post_type means either malformed object found, or no valid parent was found.
    107 if ( ! $redirect && empty( $post->post_type ) ) {
     118if ( ! $redirect && empty( $parent->post_type ) ) {
    108119        $redirect = 'edit.php';
    109120}
    110121
    if ( ! empty( $redirect ) ) { 
    114125}
    115126
    116127// This is so that the correct "Edit" menu item is selected.
    117 if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) {
    118         $parent_file = 'edit.php?post_type=' . $post->post_type;
     128if ( ! empty( $parent->post_type ) && 'post' != $parent->post_type ) {
     129        $parent_file = 'edit.php?post_type=' . $parent->post_type;
    119130} else {
    120131        $parent_file = 'edit.php';
    121132}
    122133$submenu_file = $parent_file;
    123134
    124135wp_enqueue_script( 'revisions' );
    125 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
     136wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $parent, $revision_id, $from ) );
    126137
    127138/* Revisions Help Tab */
    128139