[wp-trac] [WordPress Trac] #63462: add_query_arg() should handle encoded input URLs

WordPress Trac noreply at wordpress.org
Tue May 20 01:46:04 UTC 2025


#63462: add_query_arg() should handle encoded input URLs
--------------------------+-----------------------------
 Reporter:  kkmuffme      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When passing an already encoded URL to add_query_arg, it will make
 existing query args after # to be an anchor.
 Since add_query_arg expects URL encoded params for key/value, people often
 assume this is the case for the URL too - that results in an unexpected
 result though.
 Especially since it says:
 >Values are expected to be encoded appropriately with urlencode() or
 rawurlencode().

 and
 >$value Optional. Either a query variable value, **or a URL** to act upon.

 {{{#!php
 <?php
 echo add_query_arg('foo', 'bar', '/wp-
 admin/admin.php?page=hello&tab=world&abc=xyz' );
 }}}


 will result in

 {{{
 '/wp-admin/admin.php?page=hello&foo=bar#038;tab=world&abc=xyz'
 }}}

 I guess add_query_arg should either add a "doing it wrong" when passing an
 encoded URL or automatically, correctly handle encoded URLs.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63462>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list