diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php
index ec7c251a68..439e2b5305 100644
--- a/src/wp-includes/class-wp-customize-manager.php
+++ b/src/wp-includes/class-wp-customize-manager.php
@@ -1353,6 +1353,7 @@ final class WP_Customize_Manager {
wp_enqueue_script( 'customize-preview' );
add_action( 'wp_head', array( $this, 'customize_preview_loading_style' ) );
+ add_action( 'wp_head', array( $this, 'remove_frameless_preview_messenger_channel' ) );
add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
add_filter( 'get_edit_post_link', '__return_empty_string' );
@@ -1487,6 +1488,44 @@ final class WP_Customize_Manager {
messenger_channel ) {
+ return;
+ }
+ ?>
+
+ assertEquals( $did_action_customize_preview_init + 1, did_action( 'customize_preview_init' ) );
$this->assertEquals( 10, has_action( 'wp_head', 'wp_no_robots' ) );
+ $this->assertEquals( 10, has_action( 'wp_head', array( $wp_customize, 'remove_frameless_preview_messenger_channel' ) ) );
$this->assertEquals( 10, has_filter( 'wp_headers', array( $wp_customize, 'filter_iframe_security_headers' ) ) );
$this->assertEquals( 10, has_filter( 'wp_redirect', array( $wp_customize, 'add_state_query_params' ) ) );
$this->assertTrue( wp_script_is( 'customize-preview', 'enqueued' ) );
@@ -2035,6 +2036,27 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertArrayHasKey( 'preview', $data['nonce'] );
}
+ /**
+ * 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( '