<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[57685] trunk: Themes: Use original template paths when switching blogs.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/57685">57685</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/57685","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>joemcgill</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-02-21 19:24:12 +0000 (Wed, 21 Feb 2024)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Themes: Use original template paths when switching blogs.
This fixes a bug introduced by <a href="https://core.trac.wordpress.org/changeset/57129">[57129]</a> and <a href="https://core.trac.wordpress.org/changeset/56635">[56635]</a> in which deprecating the previous `TEMPLATEPATH` and `STYLESHEETPATH` constants in favor of `get_template_directory()` and `get_stylesheet_directory()` functions caused the active theme template path to change when using `switch_to_blog()`.
This introduces a new function, `wp_set_template_globals()`, which is called during the bootstrap process to store the template paths to new globals values `$wp_template_path` and `$wp_stylesheet_path`. This restores behavior to how things worked prior to <a href="https://core.trac.wordpress.org/changeset/56635">[56635]</a> but retains the ability for template values to be reset for better testability.
Related <a href="https://core.trac.wordpress.org/ticket/18298">#18298</a>, <a href="https://core.trac.wordpress.org/ticket/60025">#60025</a>.
Props joemcgill, flixos90, mukesh27, swissspidy, manfcarlo, metropolis_john, jeremyfelt.
Fixes <a href="https://core.trac.wordpress.org/ticket/60290">#60290</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesthemephp">trunk/src/wp-admin/includes/theme.php</a></li>
<li><a href="#trunksrcwpincludescommenttemplatephp">trunk/src/wp-includes/comment-template.php</a></li>
<li><a href="#trunksrcwpincludesloadphp">trunk/src/wp-includes/load.php</a></li>
<li><a href="#trunksrcwpincludestemplatephp">trunk/src/wp-includes/template.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunksrcwpsettingsphp">trunk/src/wp-settings.php</a></li>
<li><a href="#trunktestsphpunitincludesabstracttestcasephp">trunk/tests/phpunit/includes/abstract-testcase.php</a></li>
<li><a href="#trunktestsphpunittestscommentmetaCachephp">trunk/tests/phpunit/tests/comment/metaCache.php</a></li>
<li><a href="#trunktestsphpunitteststhemephp">trunk/tests/phpunit/tests/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/theme.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-admin/includes/theme.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1160,6 +1160,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $theme Single theme to resume.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $redirect Optional. URL to redirect to. Default empty string.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool|WP_Error True on success, false if `$theme` was not paused,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1166,6 +1169,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * `WP_Error` on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function resume_theme( $theme, $redirect = '' ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_stylesheet_path, $wp_template_path;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> list( $extension ) = explode( '/', $theme );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1173,14 +1178,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * creating a fatal error.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $redirect ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet_path = get_stylesheet_directory();
- $template_path = get_template_directory();
-
</del><span class="cx" style="display: block; padding: 0 10px"> $functions_path = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( str_contains( $stylesheet_path, $extension ) ) {
- $functions_path = $stylesheet_path . '/functions.php';
- } elseif ( str_contains( $template_path, $extension ) ) {
- $functions_path = $template_path . '/functions.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( str_contains( $wp_stylesheet_path, $extension ) ) {
+ $functions_path = $wp_stylesheet_path . '/functions.php';
+ } elseif ( str_contains( $wp_template_path, $extension ) ) {
+ $functions_path = $wp_template_path . '/functions.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $functions_path ) ) {
</span></span></pre></div>
<a id="trunksrcwpincludescommenttemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/comment-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment-template.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-includes/comment-template.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1390,15 +1390,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global WP_Query $wp_query WordPress Query object.
- * @global WP_Post $post Global post object.
- * @global wpdb $wpdb WordPress database abstraction object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global WP_Query $wp_query WordPress Query object.
+ * @global WP_Post $post Global post object.
+ * @global wpdb $wpdb WordPress database abstraction object.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global int $id
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global WP_Comment $comment Global comment object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global WP_Comment $comment Global comment object.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global string $user_login
</span><span class="cx" style="display: block; padding: 0 10px"> * @global string $user_identity
</span><span class="cx" style="display: block; padding: 0 10px"> * @global bool $overridden_cpage
</span><span class="cx" style="display: block; padding: 0 10px"> * @global bool $withcomments
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $file Optional. The file to load. Default '/comments.php'.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1405,7 +1407,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Default false.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function comments_template( $file = '/comments.php', $separate_comments = false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage, $wp_stylesheet_path, $wp_template_path;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1600,11 +1602,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> define( 'COMMENTS_TEMPLATE', true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet_path = get_stylesheet_directory();
- $template_path = get_template_directory();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $theme_template = trailingslashit( $wp_stylesheet_path ) . $file;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $theme_template = $stylesheet_path . $file;
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the path to the theme template file used for the comments template.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1616,8 +1615,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( file_exists( $include ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> require $include;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( file_exists( $template_path . $file ) ) {
- require $template_path . $file;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( file_exists( trailingslashit( $wp_template_path ) . $file ) ) {
+ require trailingslashit( $wp_template_path ) . $file;
</ins><span class="cx" style="display: block; padding: 0 10px"> } else { // Backward compat code will be removed in a future release.
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/theme-compat/comments.php';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesloadphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/load.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/load.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-includes/load.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1046,12 +1046,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global string $pagenow The filename of the current screen.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global string $pagenow The filename of the current screen.
+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string[] Array of absolute paths to theme directories.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_active_and_valid_themes() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $pagenow;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $pagenow, $wp_stylesheet_path, $wp_template_path;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $themes = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1059,14 +1061,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $themes;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet_path = get_stylesheet_directory();
- $template_path = get_template_directory();
-
- if ( $template_path !== $stylesheet_path ) {
- $themes[] = $stylesheet_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_child_theme() ) {
+ $themes[] = $wp_stylesheet_path;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $themes[] = $template_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $themes[] = $wp_template_path;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * Remove themes from the list of active themes when we're on an endpoint
</span></span></pre></div>
<a id="trunksrcwpincludestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/template.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-includes/template.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -680,6 +680,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set up the globals used for template loading.
+ *
+ * @since 6.5.0
+ *
+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ */
+function wp_set_template_globals() {
+ global $wp_stylesheet_path, $wp_template_path;
+
+ $wp_stylesheet_path = get_stylesheet_directory();
+ $wp_template_path = get_template_directory();
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Retrieves the name of the highest priority template file that exists.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Searches in the stylesheet directory before the template directory and
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -689,6 +704,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.7.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.5.0 The `$args` parameter was added.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $template_names Template file(s) to search for, in order.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $load If true the template file will be loaded if it is found.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $load_once Whether to require_once or require. Has no effect if `$load` is false.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -698,20 +716,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The template filename if one is located.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet_path = get_stylesheet_directory();
- $template_path = get_template_directory();
- $is_child_theme = $stylesheet_path !== $template_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_stylesheet_path, $wp_template_path;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $wp_stylesheet_path ) || ! isset( $wp_template_path ) ) {
+ wp_set_template_globals();
+ }
+
+ $is_child_theme = is_child_theme();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $located = '';
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( (array) $template_names as $template_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $template_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( file_exists( $stylesheet_path . '/' . $template_name ) ) {
- $located = $stylesheet_path . '/' . $template_name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( file_exists( $wp_stylesheet_path . '/' . $template_name ) ) {
+ $located = $wp_stylesheet_path . '/' . $template_name;
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( $is_child_theme && file_exists( $template_path . '/' . $template_name ) ) {
- $located = $template_path . '/' . $template_name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( $is_child_theme && file_exists( $wp_template_path . '/' . $template_name ) ) {
+ $located = $wp_template_path . '/' . $template_name;
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
</span></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-includes/theme.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -153,11 +153,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether a child theme is in use.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.5.0 Makes use of global template variables.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if a child theme is in use, false otherwise.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function is_child_theme() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return get_template_directory() !== get_stylesheet_directory();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_stylesheet_path, $wp_template_path;
+
+ return $wp_stylesheet_path !== $wp_template_path;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -836,6 +842,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> update_option( 'theme_switched', $old_theme->get_stylesheet() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Reset template globals when switching themes outside of a switched blog
+ * context to ensure templates will be loaded from the new theme.
+ */
+ if ( ! is_multisite() || ! ms_is_switched() ) {
+ wp_set_template_globals();
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Clear pattern caches.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $new_theme->delete_pattern_cache();
</span></span></pre></div>
<a id="trunksrcwpsettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-settings.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/src/wp-settings.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -608,8 +608,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'setup_theme' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Define the template related constants.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Define the template related constants and globals.
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_templating_constants();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+wp_set_template_globals();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Load the default text localization domain.
</span><span class="cx" style="display: block; padding: 0 10px"> load_default_textdomain();
</span></span></pre></div>
<a id="trunktestsphpunitincludesabstracttestcasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/abstract-testcase.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/abstract-testcase.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/tests/phpunit/includes/abstract-testcase.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -190,6 +190,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['wp_sitemaps'] = null;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Reset template globals.
+ $GLOBALS['wp_stylesheet_path'] = null;
+ $GLOBALS['wp_template_path'] = null;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->unregister_all_meta_keys();
</span><span class="cx" style="display: block; padding: 0 10px"> remove_theme_support( 'html5' );
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
</span></span></pre></div>
<a id="trunktestsphpunittestscommentmetaCachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/comment/metaCache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/comment/metaCache.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/tests/phpunit/tests/comment/metaCache.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,6 +7,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected $queries = 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Performs setup tasks for every test.
+ */
+ public function set_up() {
+ parent::set_up();
+ switch_theme( 'default' );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16894
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::update_comment_meta
</span></span></pre></div>
<a id="trunktestsphpunitteststhemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme.php 2024-02-21 18:59:57 UTC (rev 57684)
+++ trunk/tests/phpunit/tests/theme.php 2024-02-21 19:24:12 UTC (rev 57685)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1305,4 +1305,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $old_root . '/test-parent', $path1, 'The original template path is not correct' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $new_root . '/test-parent', $path2, 'The new template path is not correct' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Tests that switch_to_blog() uses the original template path.
+ *
+ * @ticket 60290
+ *
+ * @group ms-required
+ *
+ * @covers ::locate_template
+ */
+ public function test_switch_to_blog_uses_original_template_path() {
+ $old_theme = wp_get_theme();
+ $template_path = locate_template( 'index.php' );
+
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
+
+ switch_theme( 'block-theme' );
+ $new_template_path = locate_template( 'index.php' );
+
+ // Cleanup.
+ restore_current_blog();
+ switch_theme( $old_theme->get_stylesheet() );
+
+ $this->assertSame( $template_path, $new_template_path, 'Switching blogs switches the template path' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>