Make WordPress Core

Changeset 32809


Ignore:
Timestamp:
06/16/2015 11:12:21 PM (9 years ago)
Author:
azaozz
Message:

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

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r32633 r32809  
    291291add_action( 'init', '_show_post_preview' );
    292292
     293// Output JS to reset window.name for previews
     294add_action( 'wp_head', 'wp_post_preview_js', 1 );
     295
    293296// Timezone
    294297add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );
  • trunk/src/wp-includes/functions.php

    r32800 r32809  
    49144914    }
    49154915}
     4916
     4917/**
     4918 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
     4919 * This prevents reusing the same tab for a preview when the user has navigated away.
     4920 *
     4921 * @since 4.3.0
     4922 */
     4923function wp_post_preview_js() {
     4924    global $post;
     4925
     4926    if ( ! is_preview() || empty( $post ) ) {
     4927        return;
     4928    }
     4929
     4930    // Has to match the window name used in post_submit_meta_box()
     4931    $name = 'wp-preview-' . (int) $post->ID;
     4932
     4933    ?>
     4934    <script>
     4935    ( function() {
     4936        var query = document.location.search;
     4937
     4938        if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
     4939            window.name = '<?php echo $name; ?>';
     4940        }
     4941
     4942        if ( window.addEventListener ) {
     4943            window.addEventListener( 'unload', function() { window.name = ''; }, false );
     4944        }
     4945    }());
     4946    </script>
     4947    <?php
     4948}
Note: See TracChangeset for help on using the changeset viewer.