[wp-trac] [WordPress Trac] #59018: Blocks in child themes with folder names starting with the same as the parent cannot load assets in WP6.3

WordPress Trac noreply at wordpress.org
Tue Aug 22 23:50:19 UTC 2023


#59018: Blocks in child themes with folder names starting with the same as the
parent cannot load assets in WP6.3
-------------------------------------------------+-------------------------
 Reporter:  lgladdy                              |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.3.2
Component:  Editor                               |     Version:  6.3
 Severity:  major                                |  Resolution:
 Keywords:  has-unit-tests needs-testing needs-  |     Focuses:
  patch                                          |
-------------------------------------------------+-------------------------
Changes (by azaozz):

 * keywords:  has-patch has-unit-tests needs-testing => has-unit-tests
     needs-testing needs-patch


Comment:

 Replying to [comment:19 masteradhoc]:

 Yes seems this is caused by [56183]. If the child theme directory name
 starts with the parent theme's directory name, these two are both `true`
 (which shouldn't be possible):

 {{{
 $is_parent_theme_block = str_starts_with( $script_path_norm,
 $template_path_norm );
 $is_child_theme_block  = str_starts_with( $script_path_norm,
 $stylesheet_path_norm );
 }}}

 Testing with a child theme of Twenty Seventeen that's in a
 `twentyseventeen-child` directory,
 {{{
 wp_normalize_path( get_template_directory() )
 wp_normalize_path( get_stylesheet_directory() )
 }}}

 return

 {{{
 string(39) "/var/www/wp-content/themes/twentyseventeen"
 string(45) "/var/www/wp-content/themes/twentyseventeen-child"
 }}}

 where both match `str_starts_with( $script_path_norm, ... )` so
 `$is_parent_theme_block` is erroneously set to true. Later on that's used
 when determining the URL in `$script_uri = $is_parent_theme_block ? ...`.

 Assuming that `$is_parent_theme_block` and `$is_child_theme_block` cannot
 be true at the same time, an "easy fix" may be to test for a child theme
 block first and if negative, test for a parent theme. However that leaves
 the edge case where a parent theme's name/directory might contain the
 child theme's name (the reverse case). The same is true for the proposed
 patch with adding a slash.

 Seems matching with the longer string first may work, but is somewhat
 "weak". Ideally this comparison should not be used to determine whether a
 block is from a parent or child theme.

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


More information about the wp-trac mailing list