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

WordPress Trac noreply at wordpress.org
Thu Apr 29 01:18:08 UTC 2021


#53108: `get_theme_file_uri()` fails with query params
--------------------------+-----------------------------
 Reporter:  zulaica       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.7.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `get_theme_file_uri()` fails to locate a file if it is supplied with any
 query params and incorrectly falls back to returning the parent theme's
 path to the file, including the supplied query params. This prevents the
 ability to use a bundler's versioning without adding complexity to
 registering scripts and styles.

 {{{#!php
 <?php
 get_theme_file_uri( '/js/script.js?id=41142aba6c0214da8ec1' );

 // Expected output:
 // 'https://domain.com/wp-
 content/themes/ChildTheme/js/script.js?id=41142aba6c0214da8ec1'

 // Actual output:
 // 'https://domain.com/wp-
 content/themes/ParentTheme/js/script.js?id=41142aba6c0214da8ec1'
 }}}

 `file_exists()` does not understand the query param when attempting to
 locate the file. One solution could be to use `parse_url()` to determine
 the file path used in the condition:


 {{{#!php
 <?php // https://core.trac.wordpress.org/browser/tags/5.7.1/src/wp-
 includes/link-template.php#L4374
 ...
     } elseif ( file_exists( get_stylesheet_directory() . '/' .
 parse_url($file)['path'] ) ) {
 ...
 }}}

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


More information about the wp-trac mailing list