From f21e17dbf0020067114855077537ed6087ff6043 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 21 Nov 2016 16:55:20 +0000 Subject: [PATCH] Customize: Remove iframe-specific behaviors from customize preview when previewing on frontend and not contained inside iframe. * Strip out `customize_messenger_channel` from preview window URL when not contained in iframe. * Allow interacting with unpreviewable links and forms when previewing customized state on frontend. See #30937. Fixes #38867. git-svn-id: https://develop.svn.wordpress.org/trunk@39332 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-customize-manager.php | 39 ++++++++++++++++ src/wp-includes/js/customize-preview.js | 44 +++++++++---------- tests/phpunit/tests/customize/manager.php | 22 ++++++++++ 3 files changed, 82 insertions(+), 23 deletions(-) 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( '