[wp-trac] [WordPress Trac] #63128: Too Early Caching is breaking Block Child Themes

WordPress Trac noreply at wordpress.org
Wed Mar 19 15:45:34 UTC 2025


#63128: Too Early Caching is breaking Block Child Themes
--------------------------+-------------------------------------------
 Reporter:  SirLouen      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:
 Severity:  major         |   Keywords:  has-testing-info dev-feedback
  Focuses:                |
--------------------------+-------------------------------------------
 This is a follow-up for this ticket: #63086

 I'm going to copy/paste the most relevant aspects of my last research:

 I've been able to narrow down to the point that I've found that the
 problem is exactly here:

 {{{#!php
 <?php
 $parent_dir  = dirname( $this->stylesheet );
 $directories = search_theme_directories();

 if ( '.' !== $parent_dir
         && file_exists( $this->theme_root . '/' . $parent_dir . '/' .
 $this->template . '/index.php' )
 ) {
         $this->template = $parent_dir . '/' . $this->template;
 } elseif ( $directories && isset( $directories[ $this->template ] ) ) {
         /*
          * Look for the template in the search_theme_directories()
 results, in case it is in another theme root.
          * We don't look into directories of themes, just the theme root.
          */
         $theme_root_template = $directories[ $this->template
 ]['theme_root'];
 } else {
         // Parent theme is missing.
         $this->errors = new WP_Error(
         'theme_no_parent',
                 sprintf(
                         /* translators: %s: Theme directory name. */
                         __( 'The parent theme is missing. Please install
 the "%s" parent theme.' ),
                         esc_html( $this->template )
                 )
         );
         $this->cache_add(
                 'theme',
                 array(
                         'block_template_folders' =>
 $this->get_block_template_folders(),
                         'block_theme'            =>
 $this->is_block_theme(),
                         'headers'                => $this->headers,
                         'errors'                 => $this->errors,
                         'stylesheet'             => $this->stylesheet,
                         'template'               => $this->template,
                 )
         );
         $this->parent = new WP_Theme( $this->template, $this->theme_root,
 $this );
         return;
 }
 }}}

 The `cache_add` is done too early.

 By removing this fragment

 {{{#!php
 <?php
 $this->cache_add(
         'theme',
         array(
                 'block_template_folders' =>
 $this->get_block_template_folders(),
                 'block_theme'            => $this->is_block_theme(),
                 'headers'                => $this->headers,
                 'errors'                 => $this->errors,
                 'stylesheet'             => $this->stylesheet,
                 'template'               => $this->template,
         )
 );
 }}}

 It works well.

 This code is historical, before the introduction of block themes, where
 having a `index.php` in parent was a staple, useful for checks, but with
 block themes, this isn't the case anymore

 For example, adding this check here:

 {{{#!php
 <?php
 if ( ! $this->is_block_theme() ) {
         $this->cache_add(
                 'theme',
                 array(
                         'block_template_folders' =>
 $this->get_block_template_folders(),
                         'block_theme'            =>
 $this->is_block_theme(),
                         'headers'                => $this->headers,
                         'errors'                 => $this->errors,
                         'stylesheet'             => $this->stylesheet,
                         'template'               => $this->template,
                 )
         );
 }
 }}}

 Solves this report also, but cache should be populated after the parent
 call.

 Maybe the solution is simply considering another check specific for block
 themes instead of asking devs as the proposed solution in #63086 for not
 using this function between 'muplugins_loaded' and 'plugins_loaded' (in a
 mu-plugin basically)

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


More information about the wp-trac mailing list