WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 9 months ago

#44540 assigned defect (bug)

Revision restoring redirect issue when using custom wp_query inside shortcodes

Reported by: vendetta90 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.7
Component: Revisions Keywords:
Focuses: Cc:
PR Number:

Description

Using a custom WP_Query inside page content shortcodes leads to weird "revisions restoring" behavior which is redirecting to improper page id. However the page content is restored correctly. Have found this lines 55, 56 in revision.php


wp_restore_post_revision( $revision->ID ); 
$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) )

While wp_restore_post_revision( $revision->ID ) returns a correct post_id, the redirect is made to get_edit_post_link( $post->ID, 'url' ) and $post->ID may be broken by custom wp_query loop. Why not using wp_restore_post_revision( $revision->ID ) returned result to perform a correct redirect?

Change History (2)

#1 @vendetta90
17 months ago

Fixed that using

add_action( 'wp_restore_post_revision', 'fix_revisions', 10, 2 );

function fix_revisions( $post_id, $revision ) {
        global $post;
        $post->ID = $post_id;
}

#2 @Breno Alves
9 months ago

Nice catch @vendetta90, I was facing the same issue by using a page builder component that loops in a custom post type.

Note: See TracTickets for help on using tickets.