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> <script>
( function() { ( function() {
var urlParser, oldQueryParams, newQueryParams, i;
if ( parent !== window ) { if ( parent !== window ) {
return; return;
} }
urlParser = document.createElement( 'a' ); const url = new URL( location.href );
urlParser.href = location.href; if ( url.searchParams.has( 'customize_messenger_channel' ) ) {
oldQueryParams = urlParser.search.substr( 1 ).split( /&/ ); url.searchParams.delete( 'customize_messenger_channel' );
newQueryParams = []; location.replace( url );
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 );
} }
} )(); } )();
</script> </script>

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.