Make WordPress Core

Ticket #38867: 38867.1.diff

File 38867.1.diff, 2.0 KB (added by westonruter, 10 years ago)
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index d047620..ee3865d 100644
    final class WP_Customize_Manager {  
    13531353
    13541354                wp_enqueue_script( 'customize-preview' );
    13551355                add_action( 'wp_head', array( $this, 'customize_preview_loading_style' ) );
     1356                if ( $this->messenger_channel ) {
     1357                        add_action( 'wp_head', array( $this, 'remove_frameless_preview_messenger_channel' ) );
     1358                }
    13561359                add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
    13571360                add_filter( 'get_edit_post_link', '__return_empty_string' );
    13581361
    final class WP_Customize_Manager {  
    14881491        }
    14891492
    14901493        /**
     1494         * Remove customize_messenger_channel query parameter from the preview window when it is not in an iframe.
     1495         *
     1496         * This ensures that the admin bar will be shown. It also ensures that link navigation will
     1497         * work as expected since the parent frame is not being sent the URL to navigate to.
     1498         *
     1499         * @since 4.7.0
     1500         * @access public
     1501         */
     1502        public function remove_frameless_preview_messenger_channel( ){
     1503                if ( ! $this->messenger_channel ) {
     1504                        return;
     1505                }
     1506                ?>
     1507                <script>
     1508                ( function() {
     1509                        var urlParser, oldQueryParams, newQueryParams, i;
     1510                        if ( parent !== window ) {
     1511                                return;
     1512                        }
     1513                        urlParser = document.createElement( 'a' );
     1514                        urlParser.href = location.href;
     1515                        oldQueryParams = urlParser.search.substr( 1 ).split( /&/ );
     1516                        newQueryParams = [];
     1517                        for ( i = 0; i < oldQueryParams.length; i += 1 ) {
     1518                                if ( ! /^customize_messenger_channel=/.test( oldQueryParams[ i ] ) ) {
     1519                                        newQueryParams.push( oldQueryParams[ i ] );
     1520                                }
     1521                        }
     1522                        urlParser.search = newQueryParams.join( '&' );
     1523                        if ( urlParser.search !== location.search ) {
     1524                                location.replace( urlParser.href );
     1525                        }
     1526                } )();
     1527                </script>
     1528                <?php
     1529        }
     1530
     1531        /**
    14911532         * Print JavaScript settings for preview frame.
    14921533         *
    14931534         * @since 3.4.0