Customize: Harden and modernize URL manipulation in WP_Customize_Manager::remove_frameless_preview_messenger_channel().

Since IE11 is no longer supported, the `URL` and `URLSearchParams` APIs can now be leveraged for simpler and more robust URL manipulation. This was done similarly in [56383] for `embed.js`.

Props nicolefurlan, dmsnell, westonruter.
Fixes #59480.

Built from https://develop.svn.wordpress.org/trunk@56749


git-svn-id: http://core.svn.wordpress.org/trunk@56261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2023-09-29 21:39:25 +00:00
parent a20cb28d14
commit 59557e4c6e
2 changed files with 5 additions and 14 deletions

View File

@ -2089,22 +2089,13 @@ final class WP_Customize_Manager {
?>
<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 );
const url = new URL( location.href );
if ( url.searchParams.has( 'customize_messenger_channel' ) ) {
url.searchParams.delete( 'customize_messenger_channel' );
location.replace( url );
}
} )();
</script>

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-beta1-56748';
$wp_version = '6.4-beta1-56749';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.