From 0068d161b3dbe7833d2b636d0d9804448da3f871 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 13 Nov 2015 05:24:28 +0000 Subject: [PATCH] Customize: Exclude `referer` URL from being used for Close link if it is `customize.php`. This fixes an edge case where the Close button could never link the user out of the Customizer, if the user initially accessed it without a `url` param and then clicked a link (provided by a plugin) that took them to another `customize.php` URL. See #32637. git-svn-id: https://develop.svn.wordpress.org/trunk@35635 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-manager.php | 2 +- tests/phpunit/tests/customize/manager.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index fcc9697fd6..baa50dfa62 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -1476,7 +1476,7 @@ final class WP_Customize_Manager { $referer = wp_get_referer(); if ( $this->return_url ) { $return_url = $this->return_url; - } else if ( $referer ) { + } else if ( $referer && 'customize.php' !== basename( parse_url( $referer, PHP_URL_PATH ) ) ) { $return_url = $referer; } else if ( $this->preview_url ) { $return_url = $this->preview_url; diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 247f7651b2..481fe61dde 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -262,6 +262,9 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { $this->manager->set_preview_url( $preview_url ); $this->assertEquals( $preview_url, $this->manager->get_return_url() ); + $_SERVER['HTTP_REFERER'] = wp_slash( admin_url( 'customize.php' ) ); + $this->assertEquals( $preview_url, $this->manager->get_return_url() ); + $url = home_url( '/referred/' ); $_SERVER['HTTP_REFERER'] = wp_slash( $url ); $this->assertEquals( $url, $this->manager->get_return_url() );