diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 2d6ee7eca1..04cca33add 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1210,7 +1210,7 @@ final class WP_Theme implements ArrayAccess { $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); } - return $files; + return array_filter( $files ); } /** diff --git a/tests/phpunit/tests/theme/wpTheme.php b/tests/phpunit/tests/theme/wpTheme.php index 3fb1e6e4b7..1096ca29c6 100644 --- a/tests/phpunit/tests/theme/wpTheme.php +++ b/tests/phpunit/tests/theme/wpTheme.php @@ -261,6 +261,35 @@ class Tests_Theme_wpTheme extends WP_UnitTestCase { $this->assertSame( $expected, $theme->is_block_theme() ); } + /** + * Test get_files for an existing theme. + * + * @ticket 53599 + */ + public function test_get_files_theme() { + $theme = new WP_Theme( 'theme1', $this->theme_root ); + $files = $theme->get_files(); + + $this->assertIsArray( $files ); + $this->assertCount( 3, $files ); + $this->assertArrayHasKey( 'functions.php', $files ); + $this->assertArrayHasKey( 'index.php', $files ); + $this->assertArrayHasKey( 'style.css', $files ); + } + + /** + * Test get_files for a non-existing theme. + * + * @ticket 53599 + */ + public function test_get_files_nonexistent_theme() { + $theme = new WP_Theme( 'nonexistent', $this->theme_root ); + $files = $theme->get_files(); + + $this->assertIsArray( $files ); + $this->assertEmpty( $files ); + } + /** * Data provider. *