From 18878a1d93961767ca202b43a62341aedd7b38bd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 27 Feb 2023 15:32:22 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-wp-theme.php | 3 +++ tests/phpunit/tests/theme/wpTheme.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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 */