From 0dd00badb2c8ad0dcdd60d170b6198b1e2eabc6f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 26 Jul 2020 21:24:00 +0000 Subject: [PATCH] Revisions: Ensure the global `$post` remains the same after revision is restored. Because `wp_insert_post()` and `wp_transition_post_status()` are called during the process, plugins can unexpectedly modify `$post`. Props markparnell, tofandel, archon810, SergeyBiryukov. Fixes #46671. git-svn-id: https://develop.svn.wordpress.org/trunk@48625 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/revision.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/wp-admin/revision.php b/src/wp-admin/revision.php index 43cc266748..156e998b57 100644 --- a/src/wp-admin/revision.php +++ b/src/wp-admin/revision.php @@ -60,8 +60,18 @@ switch ( $action ) { check_admin_referer( "restore-post_{$revision->ID}" ); + /* + * Ensure the global $post remains the same after revision is restored. + * Because wp_insert_post() and wp_transition_post_status() are called + * during the process, plugins can unexpectedly modify $post. + */ + $backup_global_post = clone $post; + wp_restore_post_revision( $revision->ID ); + // Restore the global $post as it was before. + $post = $backup_global_post; + $redirect = add_query_arg( array( 'message' => 5,