[wp-trac] [WordPress Trac] #64372: Additional URL args supplied via enqueued script/style handle cause malformed ver query param when null

WordPress Trac noreply at wordpress.org
Sun Dec 7 05:14:34 UTC 2025


#64372: Additional URL args supplied via enqueued script/style handle cause
malformed ver query param when null
--------------------------------------+---------------------
 Reporter:  westonruter               |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  low                       |   Milestone:  7.0
Component:  Script Loader             |     Version:  2.6
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------
Description changed by westonruter:

Old description:

> When working on fixing PHPStan issues (#64238) for `WP_Scripts` (r61358),
> I stumbled across a capability I was previously unaware of: you can pass
> additional query parameters to an enqueued script/style URL by adding
> them to the handle. For example:
>
> {{{#!php
> <?php
> wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js',
> array(), '1.0' );
> }}}
>

> This results in the following script being printed:
>
> {{{
> <script type="text/javascript"
> src="https://example.com/test.js?ver=1.0&bar=baz&baz=quux" id
> ="foo-js"></script
> }}}
>
> This capability is not included in any unit test, and it may be a vestige
> of something no longer used. Naturally, a better way to do this now would
> seem to be to leverage the `script_loader_src` filter, or rather, to add
> the query parameters to the URL being registered in the first place. I
> can [https://wpdirectory.net/search/01KBVJW6HFWQ4HM3X098AV1Z4S find] one
> plugin ([https://wordpress.org/plugins/mapnavigator/ Map Navigator])
> which seems to be [using] this intentionally.
>
> In any case, I found that this capability is broken when using `null` as
> a version:
>
> {{{#!php
> <?php
> wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js',
> array(), null );
> }}}
>
> This results in:
>
> {{{
> <script type="text/javascript"
> src="https://example.com/test.js?ver=bar=baz&baz=quux" id="foo-
> js"></script>
> }}}
>
> Note the query string: `ver=bar=baz&baz=quux`.
>
> The "ver=" shouldn't have been included here.

New description:

 When working on fixing PHPStan issues (#64238) for `WP_Scripts` (r61358),
 I stumbled across a capability I was previously unaware of: you can pass
 additional query parameters to an enqueued script/style URL by adding them
 to the handle. For example:

 {{{#!php
 <?php
 wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js',
 array(), '1.0' );
 }}}


 This results in the following script being printed:

 {{{
 <script type="text/javascript"
 src="https://example.com/test.js?ver=1.0&bar=baz&baz=quux" id
 ="foo-js"></script
 }}}

 This capability is not included in any unit test, and it may be a vestige
 of something no longer used. Naturally, a better way to do this now would
 seem to be to leverage the `script_loader_src` filter, or rather, to add
 the query parameters to the URL being registered in the first place. I can
 [https://wpdirectory.net/search/01KBVJW6HFWQ4HM3X098AV1Z4S find] one
 plugin ([https://wordpress.org/plugins/mapnavigator/ Map Navigator]) which
 seems to be
 [https://plugins.trac.wordpress.org/browser/mapnavigator/tags/1.1.1/functions.php#L1388
 using] this intentionally.

 In any case, I found that this capability is broken when using `null` as a
 version:

 {{{#!php
 <?php
 wp_enqueue_script( 'foo?bar=baz&baz=quux', 'https://example.com/test.js',
 array(), null );
 }}}

 This results in:

 {{{
 <script type="text/javascript"
 src="https://example.com/test.js?ver=bar=baz&baz=quux" id="foo-
 js"></script>
 }}}

 Note the query string: `ver=bar=baz&baz=quux`.

 The "ver=" shouldn't have been included here.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64372#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list