WordPress / theme-check

Theme Check plugin
https://wordpress.org/plugins/theme-check/
341 stars 114 forks source link

Incorrect results when run on child theme because of a possible bug in WP_Theme::get_files() #429

Open pbiron opened 2 years ago

pbiron commented 2 years ago

I just ran a check on child theme I'm developing for a client. The check reports at least 2 incorrect results:

The parent theme does call add_theme_support( 'title-tag' ) and add_theme_support( 'automatic-feed-links' ).

At first I thought this must a bug in this plugin, but after digging into the code, as far as I can tell, the bug seems to be in WP_Theme::get_files():

public function get_files( $type = null, $depth = 0, $search_parent = false ) {
    $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth );

    if ( $search_parent && $this->parent() ) {
        $files += (array) self::scandir( $this->get_template_directory(), $type, $depth );
    }

    return array_filter( $files );
}

Notice that when it gets the files from the parent theme, it does not pass the 4th (optional) $relative_path parameter. As a result of the += operator used to combine the child and parent theme files, only the child's functions.php file is included in the returned files (ditto for any file in the parent theme with the same filename relative to its theme_root as one in the child theme relative to its theme_root).

Does my analysis above seem correct? If so, should I open a trac ticket about WP_Theme::get_files()?

p.s. I've seen https://github.com/WordPress/theme-check/issues/143#issuecomment-213112704 and realize that this plugin is not used for child themes submitted to .org, and the theme I ran it will not be submitted to .org but I think it would be good to address these incorrect results.