diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index f9f93994e7..a8975457d2 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -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; diff --git a/tests/phpunit/tests/theme/wpTheme.php b/tests/phpunit/tests/theme/wpTheme.php index 4f2fec9f2b..bd04148721 100644 --- a/tests/phpunit/tests/theme/wpTheme.php +++ b/tests/phpunit/tests/theme/wpTheme.php @@ -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 */