WP_Customize_Manager::remove_frameless_preview_messenger_channel()publicWP 4.7.0

Removes customize_messenger_channel query parameter from the preview window when it is not in an iframe.

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.

Method of the class: WP_Customize_Manager{}

No Hooks.

Return

null. Nothing (null).

Usage

$WP_Customize_Manager = new WP_Customize_Manager();
$WP_Customize_Manager->remove_frameless_preview_messenger_channel();

Changelog

Since 4.7.0 Introduced.

WP_Customize_Manager::remove_frameless_preview_messenger_channel() code WP 6.5.2

<?php
public function remove_frameless_preview_messenger_channel() {
	if ( ! $this->messenger_channel ) {
		return;
	}
	ob_start();
	?>
	<script>
	( function() {
		if ( parent !== window ) {
			return;
		}
		const url = new URL( location.href );
		if ( url.searchParams.has( 'customize_messenger_channel' ) ) {
			url.searchParams.delete( 'customize_messenger_channel' );
			location.replace( url );
		}
	} )();
	</script>
	<?php
	wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
}