Themes: Account for a numeric theme directory in WP_Theme::__construct().

This ensures that if a theme with a numeric directory name is active, it is correctly identified as such, and that theme support features work as expected.

Follow-up to [20029], [49925].

Props lopo, alvastar, winterpsv, hugodevos, ankit-k-gupta, jakariaistauk, mukesh27, spacedmonkey, SergeyBiryukov.
Fixes #54645.

git-svn-id: https://develop.svn.wordpress.org/trunk@55426 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2023-02-27 15:32:22 +00:00
parent 12fcc5cfac
commit 18878a1d93
2 changed files with 17 additions and 0 deletions

View File

@ -242,6 +242,9 @@ final class WP_Theme implements ArrayAccess {
}
}
// Handle a numeric theme directory as a string.
$theme_dir = (string) $theme_dir;
$this->theme_root = $theme_root;
$this->stylesheet = $theme_dir;

View File

@ -112,6 +112,20 @@ class Tests_Theme_wpTheme extends WP_UnitTestCase {
$this->assertSame( 'subdir/theme2', $theme->get_template() );
}
/**
* Tests that WP_Theme::__construct() handles a numeric theme directory as a string.
*
* @ticket 54645
*
* @covers WP_Theme::__construct
*/
public function test_new_WP_Theme_numeric_theme_directory() {
$theme = new WP_Theme( 1234, $this->theme_root );
$this->assertSame( '1234', $theme->get_stylesheet(), 'The stylesheet property should be a string.' );
$this->assertSame( '1234', $theme->get_template(), 'The template property should be a string.' );
}
/**
* @ticket 21749
*/