WP_Customize_Manager::remove_frameless_preview_messenger_channel PHP Method

remove_frameless_preview_messenger_channel() public method

This ensures that the admin bar will be shown. It also ensures that link navigation will work as expected since the parent frame is not being sent the URL to navigate to.
Since: 4.7.0
    public function remove_frameless_preview_messenger_channel()
    {
        if (!$this->messenger_channel) {
            return;
        }
        ?>
		<script>
		( function() {
			var urlParser, oldQueryParams, newQueryParams, i;
			if ( parent !== window ) {
				return;
			}
			urlParser = document.createElement( 'a' );
			urlParser.href = location.href;
			oldQueryParams = urlParser.search.substr( 1 ).split( /&/ );
			newQueryParams = [];
			for ( i = 0; i < oldQueryParams.length; i += 1 ) {
				if ( ! /^customize_messenger_channel=/.test( oldQueryParams[ i ] ) ) {
					newQueryParams.push( oldQueryParams[ i ] );
				}
			}
			urlParser.search = newQueryParams.join( '&' );
			if ( urlParser.search !== location.search ) {
				location.replace( urlParser.href );
			}
		} )();
		</script>
		<?php 
    }

Usage Example

 /**
  * Test remove_frameless_preview_messenger_channel.
  *
  * @ticket 38867
  * @covers WP_Customize_Manager::remove_frameless_preview_messenger_channel()
  */
 function test_remove_frameless_preview_messenger_channel()
 {
     wp_set_current_user(self::$admin_user_id);
     $manager = new WP_Customize_Manager(array('messenger_channel' => null));
     ob_start();
     $manager->remove_frameless_preview_messenger_channel();
     $output = ob_get_clean();
     $this->assertEmpty($output);
     $manager = new WP_Customize_Manager(array('messenger_channel' => 'preview-0'));
     ob_start();
     $manager->remove_frameless_preview_messenger_channel();
     $output = ob_get_clean();
     $this->assertContains('<script>', $output);
 }
WP_Customize_Manager