Make WordPress Core


Ignore:
Timestamp:
09/29/2023 09:37:06 PM (7 months ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r56748 r56749  
    20902090        <script>
    20912091        ( function() {
    2092             var urlParser, oldQueryParams, newQueryParams, i;
    20932092            if ( parent !== window ) {
    20942093                return;
    20952094            }
    2096             urlParser = document.createElement( 'a' );
    2097             urlParser.href = location.href;
    2098             oldQueryParams = urlParser.search.substr( 1 ).split( /&/ );
    2099             newQueryParams = [];
    2100             for ( i = 0; i < oldQueryParams.length; i += 1 ) {
    2101                 if ( ! /^customize_messenger_channel=/.test( oldQueryParams[ i ] ) ) {
    2102                     newQueryParams.push( oldQueryParams[ i ] );
    2103                 }
    2104             }
    2105             urlParser.search = newQueryParams.join( '&' );
    2106             if ( urlParser.search !== location.search ) {
    2107                 location.replace( urlParser.href );
     2095            const url = new URL( location.href );
     2096            if ( url.searchParams.has( 'customize_messenger_channel' ) ) {
     2097                url.searchParams.delete( 'customize_messenger_channel' );
     2098                location.replace( url );
    21082099            }
    21092100        } )();
Note: See TracChangeset for help on using the changeset viewer.