WordPress / WordPress/theme-check

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

Open
#429 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
371
Forks
113
Avg merge
8m
Merged PRs (30d)
5

Description

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

  • REQUIRED: No reference to add_theme_support( "title-tag" ) was found in the theme.
  • REQUIRED: Could not find add_theme_support( 'automatic-feed-links' ). See: add_theme_support

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the referenced WP_Theme::get_files() implementation and verify how its parent-theme scan combines paths when child and parent filenames collide. Reproduce the two reported false results, then determine whether theme-check needs a compatibility change or the issue belongs in WordPress core; done means the handling and expected result are documented with a regression check if the repository provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
testing, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.