Make WordPress Core

Ticket #46671: 46671.3.diff

File 46671.3.diff, 3.7 KB (added by SergeyBiryukov, 5 years ago)
  • src/wp-admin/revision.php

     
    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
    5050                // Don't restore if revisions are disabled and this is not an autosave.
    51                 if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
    52                         $redirect = 'edit.php?post_type=' . $post->post_type;
     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 restore if the post is locked.
    57                 if ( wp_check_post_lock( $post->ID ) ) {
     57                if ( wp_check_post_lock( $parent->ID ) ) {
    5858                        break;
    5959                }
    6060
    6161                check_admin_referer( "restore-post_{$revision->ID}" );
    6262
     63                // Set up global post variable for the use of any functions hooked into restore process.
     64                $post           = clone $parent;
     65                $wp_query->post = $post;
     66
    6367                wp_restore_post_revision( $revision->ID );
    6468
    6569                $redirect = add_query_arg(
     
    6771                                'message'  => 5,
    6872                                'revision' => $revision->ID,
    6973                        ),
    70                         get_edit_post_link( $post->ID, 'url' )
     74                        get_edit_post_link( $parent->ID, 'url' )
    7175                );
    7276                break;
    7377        case 'view':
     
    7882                        break;
    7983                }
    8084
    81                 $post = get_post( $revision->post_parent );
    82                 if ( ! $post ) {
     85                $parent = get_post( $revision->post_parent );
     86                if ( ! $parent ) {
    8387                        break;
    8488                }
    8589
     
    8892                }
    8993
    9094                // Bail if revisions are disabled and this is not an autosave.
    91                 if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
    92                         $redirect = 'edit.php?post_type=' . $post->post_type;
     95                if ( ! wp_revisions_enabled( $parent ) && ! wp_is_post_autosave( $revision ) ) {
     96                        $redirect = 'edit.php?post_type=' . $parent->post_type;
    9397                        break;
    9498                }
    9599
    96                 $post_edit_link = get_edit_post_link();
    97                 $post_title     = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
     100                $post_edit_link = get_edit_post_link( $parent );
     101                $post_title     = '<a href="' . $post_edit_link . '">' . _draft_or_post_title( $parent ) . '</a>';
    98102                /* translators: %s: Post title. */
    99103                $h1             = sprintf( __( 'Compare Revisions of &#8220;%s&#8221;' ), $post_title );
    100104                $return_to_post = '<a href="' . $post_edit_link . '">' . __( '&larr; Return to editor' ) . '</a>';
     
    105109}
    106110
    107111// Empty post_type means either malformed object found, or no valid parent was found.
    108 if ( ! $redirect && empty( $post->post_type ) ) {
     112if ( ! $redirect && empty( $parent->post_type ) ) {
    109113        $redirect = 'edit.php';
    110114}
    111115
     
    115119}
    116120
    117121// This is so that the correct "Edit" menu item is selected.
    118 if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) {
    119         $parent_file = 'edit.php?post_type=' . $post->post_type;
     122if ( ! empty( $parent->post_type ) && 'post' != $parent->post_type ) {
     123        $parent_file = 'edit.php?post_type=' . $parent->post_type;
    120124} else {
    121125        $parent_file = 'edit.php';
    122126}
     
    123127$submenu_file = $parent_file;
    124128
    125129wp_enqueue_script( 'revisions' );
    126 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
     130wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $parent, $revision_id, $from ) );
    127131
    128132/* Revisions Help Tab */
    129133
     
    157161        <?php echo $return_to_post; ?>
    158162</div>
    159163<?php
     164// Set up global post variable for wp_print_revision_templates().
     165$post = clone $parent;
     166
    160167wp_print_revision_templates();
    161168
    162169require_once ABSPATH . 'wp-admin/admin-footer.php';