[wp-trac] [WordPress Trac] #55195: Calling `::parent()` on a child theme object where parent theme is missing `index.php` returns false in WP5.9

WordPress Trac noreply at wordpress.org
Fri Feb 18 16:03:18 UTC 2022


#55195: Calling `::parent()` on a child theme object where parent theme is missing
`index.php` returns false in WP5.9
--------------------------+-----------------------------
 Reporter:  robdxw        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:  5.9
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Behaviour before v5.9:

 {{{#!php
 <?php
 $theme = wp_get_theme();
 $theme->parent();
 }}}

 would return the parent theme object, even if the parent theme was missing
 its `index.php` file.

 Since 5.9, this now returns `false`. This can result in fatal PHP errors
 being thrown if e.g. you call `$theme->parent()->get('Version');`, where
 previously the version would have been returned.

 To recreate:

 1. Create a child theme of twentytwentyone with the following
 `functions.php` file:

 {{{#!php
 <?php
 <?php
 $theme = wp_get_theme();
 $theme->parent()->get('Version');
 }}}

 and the following `styles.css`:

 {{{#!css
 /*
 Theme Name: twentytwentyone - Child
 Description: 2021 - Child
 Template: twentytwentyone
 */
 }}}

 2. Remove (or rename) the `index.php` file from the parent theme.

 In versions 5.8.3 and below, this would result in a "No matching template
 found" message being rendered on pages that should be using the parent
 `index.php`, and a warning on the admin themes page that the parent theme
 is missing its `index.php` template.

 In version 5.9, this results in a fatal PHP error in both the frontend and
 the admin.

 Investigation suggests the change was introduced in this commit:
 https://github.com/WordPress/WordPress/commit/f70fb51f99973274809caa80135d87f78b66b86a

 I appreciate that themes shouldn't be missing their `index.php` file, but
 it's not clear from the version history that this change in behaviour was
 intentional, and I haven't found it documented anywhere.

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


More information about the wp-trac mailing list