mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Themes: Ensure WP_Theme::get_files() doesn't return unexpected values.
This change filters out empty entries from `WP_Theme::get_files()` before returning the array of files. This avoid returning an entry with `false` value when the directory of the theme does not exist. Props dd32, opurockey, Rahmohn, audrasjb. Fixes #53599. git-svn-id: https://develop.svn.wordpress.org/trunk@53253 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
94c0fb7628
commit
6189d64f31
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user