Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions checks/class-directories-check.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php
/**
* Check if directories only intended for development are included
* Check if disallowed directories are included
*
* @package Theme Check
*/

/**
* Check if directories only intended for development are included.
* Check if disallowed directories are included.
*
* Check if directories only intended for development are included. If they are, require them to be removed.
* Checks each file path for disallowed directory names such as .git or __MACOSX.
* Empty disallowed directories will not be detected as they contain no files.
*/
class Directories_Check implements themecheck {
/**
Expand All @@ -21,13 +22,14 @@ class Directories_Check implements themecheck {
/**
* Check that return true for good/okay/acceptable, false for bad/not-okay/unacceptable.
*
* @param array $php_files File paths and content for PHP files.
* @param array $css_files File paths and content for CSS files.
* @param array $php_files File paths and content for PHP files.
* @param array $css_files File paths and content for CSS files.
* @param array $other_files Folder names, file paths and content for other files.
*/
public function check( $php_files, $css_files, $other_files ) {

$excluded_directories = array(
'__MACOSX',
'.git',
'.svn',
'.hg',
Expand All @@ -45,15 +47,16 @@ public function check( $php_files, $css_files, $other_files ) {
foreach ( $all_filenames as $path ) {
checkcount();

$filename = basename( $path );
$path_segments = explode( '/', str_replace( '\\', '/', $path ) );

if ( in_array( $filename, $excluded_directories, true ) ) {
if ( array_intersect( $path_segments, $excluded_directories ) ) {
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_intersect() returns an array; relying on its truthiness is a bit implicit. For readability, consider checking it explicitly (e.g., assign to a variable and/or use ! empty(...)) so it’s clear the condition is “any disallowed segment matched”.

Suggested change
if ( array_intersect( $path_segments, $excluded_directories ) ) {
$matched_directories = array_intersect( $path_segments, $excluded_directories );
if ( ! empty( $matched_directories ) ) {

Copilot uses AI. Check for mistakes.
$this->error[] = sprintf(
'<span class="tc-lead tc-required">%s</span>: %s',
__( 'REQUIRED', 'theme-check' ),
__( 'Please remove any extraneous directories like .git or .svn from the ZIP file before uploading it.', 'theme-check' )
__( 'Please remove any extraneous directories like <strong>.git</strong>, <strong>.svn</strong> or <strong>__MACOSX</strong> from the ZIP file before uploading it.', 'theme-check' )
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message hard-codes examples (".git", ".svn", "__MACOSX"), but the actual disallowed list also includes ".hg" and ".bzr". This can become misleading/out-of-sync if the list changes. Consider generating the displayed directory list from $excluded_directories (or wording the message generically without enumerating specific names).

Copilot uses AI. Check for mistakes.
);
$ret = false;
break;
}
}

Expand Down
Loading