Editor: do not reuse the preview tab when the user has navigated away.

See #32588.
Built from https://develop.svn.wordpress.org/trunk@32809


git-svn-id: http://core.svn.wordpress.org/trunk@32780 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-06-16 23:13:26 +00:00
parent ac33d71623
commit 82fcdec660
3 changed files with 37 additions and 1 deletions

View File

@ -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' );

View File

@ -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;
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php echo $name; ?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
}
}());
</script>
<?php
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32808';
$wp_version = '4.3-alpha-32809';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.