From 7ef6ece222a76aed7eee64b010d6aec4b4b3d96f Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 16 Jun 2015 23:12:21 +0000 Subject: [PATCH] Editor: do not reuse the preview tab when the user has navigated away. See #32588. git-svn-id: https://develop.svn.wordpress.org/trunk@32809 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 3 +++ src/wp-includes/functions.php | 33 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 7bf03885f1..93fac65c7d 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -290,6 +290,9 @@ add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 ); // Nonce check for Post Previews add_action( 'init', '_show_post_preview' ); +// Output JS to reset window.name for previews +add_action( 'wp_head', 'wp_post_preview_js', 1 ); + // Timezone add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 166f9a1da0..52c6831078 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4913,3 +4913,36 @@ function wp_delete_file( $file ) { @unlink( $delete ); } } + +/** + * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. + * This prevents reusing the same tab for a preview when the user has navigated away. + * + * @since 4.3.0 + */ +function wp_post_preview_js() { + global $post; + + if ( ! is_preview() || empty( $post ) ) { + return; + } + + // Has to match the window name used in post_submit_meta_box() + $name = 'wp-preview-' . (int) $post->ID; + + ?> + +