[wp-trac] [WordPress Trac] #53108: `get_theme_file_uri()` fails with query params

WordPress Trac noreply at wordpress.org
Thu Apr 29 01:25:31 UTC 2021

#53108: `get_theme_file_uri()` fails with query params
 Reporter:  zulaica      |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Themes       |     Version:  5.7.1
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
Changes (by dd32):

 * type:  defect (bug) => enhancement
 * component:  General => Themes


 The functionality currently isn't designed to handle query arguments, it's
 intentionally to find a URI for a ''file''.

 I would say the expected use-case currently is something like this:
 // preferably:
 $uri = add_query_arg( 'id', '41142aba6c0214da8ec1', get_theme_file_uri(
 'js/script.js' ) );

 // will probably work most of the time, unless a plugin has filtered the
 URI to include query args:
 $uri = get_theme_file_uri( 'js/script.js' ) . '?id=41142aba6c0214da8ec1';

 Marking this as an enhancement instead as a result, the fact that this
 works for parent themes is kind of an unexpected side effect of simply not
 checking to see if the file exists (ie. `get_theme_file_url( '404.js' )`
 returns a URI even though the file doesn't exist).

Ticket URL: <https://core.trac.wordpress.org/ticket/53108#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list