[wp-trac] [WordPress Trac] #53599: WP_Theme::get_files() returns unexpected entry if parent theme not available.

WordPress Trac noreply at wordpress.org
Sat Apr 9 23:05:37 UTC 2022


#53599: WP_Theme::get_files() returns unexpected entry if parent theme not
available.
-------------------------------------------------+-------------------------
 Reporter:  dd32                                 |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.0
Component:  Themes                               |     Version:
 Severity:  minor                                |  Resolution:
 Keywords:  good-first-bug has-patch has-unit-   |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by Rahmohn):

 WP_Theme::get_files() will return an entry with `false` value when the
 directory of the theme doesn't exist. So it's possible to reproduce this
 issue with the code below:

 {{{#!php
 <?php
 $theme = wp_get_theme( 'non-existent-directory-name' );

 var_dump( $theme->get_files() );

 /**
  * Output:
  *
  * array (size=1)
  *   0 => boolean false
  */
 }}}

 This is happening because [https://github.com/WordPress/wordpress-
 develop/blob/0ea7a38664746f9ad4f402768975c66928817531/src/wp-includes
 /class-wp-theme.php#L1200 WP_Theme::get_files()] uses the method
 [https://github.com/WordPress/wordpress-
 develop/blob/0ea7a38664746f9ad4f402768975c66928817531/src/wp-includes
 /class-wp-theme.php#L1355 WP_Theme::scandir()] to retrieve the files and
 this method can return `false` if the path doesn't exist or isn't a
 directory.

 Although the patch added by opurockey can fix the issue when the parent
 theme is not available, it doesn't for the case I described above.

 So, I've changed the WP_Theme::get_files() to filter out empty entries
 before returning the array of files. Other than that, I've added tests for
 this scenario.

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


More information about the wp-trac mailing list