Make WordPress Core


Ignore:
Timestamp:
07/26/2020 09:24:00 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/revision.php

    r48624 r48625  
    6161        check_admin_referer( "restore-post_{$revision->ID}" );
    6262
     63        /*
     64         * Ensure the global $post remains the same after revision is restored.
     65         * Because wp_insert_post() and wp_transition_post_status() are called
     66         * during the process, plugins can unexpectedly modify $post.
     67         */
     68        $backup_global_post = clone $post;
     69
    6370        wp_restore_post_revision( $revision->ID );
     71
     72        // Restore the global $post as it was before.
     73        $post = $backup_global_post;
    6474
    6575        $redirect = add_query_arg(
Note: See TracChangeset for help on using the changeset viewer.