Commit c49f46b68b for wordpress.org
commit c49f46b68b98e975c35a49115d9a46c06b8aa6c4
Author: westonruter <westonruter@git.wordpress.org>
Date: Sun Sep 6 05:17:49 2026 +0000
Themes: Set the `template` property when a theme is its own parent.
When a theme's `Template` header names the theme's own directory, `WP_Theme::__construct()` recorded the `theme_child_invalid` error and returned before assigning `$this->template`, leaving the property unset. As a result `WP_Theme::get_template()` returned `null` despite being documented as returning a string. That error scenario now assigns the stylesheet to `$this->template` and stores it in the theme cache, matching how the `theme_no_stylesheet` and `theme_no_parent` errors are already handled. The invalid-theme error itself is unchanged, and tests cover both the fresh and the cached construction paths.
Developed in https://github.com/WordPress/wordpress-develop/pull/10837.
Follow-up to r41601.
Props marian1, westonruter.
See #40820.
Fixes #64582.
Built from https://develop.svn.wordpress.org/trunk@63507
git-svn-id: http://core.svn.wordpress.org/trunk@62683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php
index a26c7bbd94..87399e399a 100644
--- a/wp-includes/class-wp-theme.php
+++ b/wp-includes/class-wp-theme.php
@@ -361,7 +361,7 @@ final class WP_Theme implements ArrayAccess {
}
if ( ! $this->template && $this->stylesheet === $this->headers['Template'] ) {
- $this->errors = new WP_Error(
+ $this->errors = new WP_Error(
'theme_child_invalid',
sprintf(
/* translators: %s: Template. */
@@ -369,6 +369,7 @@ final class WP_Theme implements ArrayAccess {
'<code>Template</code>'
)
);
+ $this->template = $this->stylesheet;
$this->cache_add(
'theme',
array(
@@ -377,6 +378,7 @@ final class WP_Theme implements ArrayAccess {
'headers' => $this->headers,
'errors' => $this->errors,
'stylesheet' => $this->stylesheet,
+ 'template' => $this->template,
)
);
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 07a96686e7..0f42e24a08 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63506';
+$wp_version = '7.2-alpha-63507';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.