<!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>[57129] trunk: Themes: Remove memoization from stylesheet and theme directories.</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/57129">57129</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/57129","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>2023-11-20 22:27:17 +0000 (Mon, 20 Nov 2023)</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: Remove memoization from stylesheet and theme directories.
This fixes bugs introduced in <a href="https://core.trac.wordpress.org/changeset/56635">[56635]</a> whereby the template or stylesheet path could be memoized incorrectly if `get_template_directory()` or `get_stylesheet_directory()` were called before the theme has been fully initialized.
Props partyfrikadelle, coreyw, kdowns, rebasaurus, meta4, flixos90, mukesh27, joemcgill.
Fixes <a href="https://core.trac.wordpress.org/ticket/59847">#59847</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesmsblogsphp">trunk/src/wp-includes/ms-blogs.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunktestsphpunitteststhemephp">trunk/tests/phpunit/tests/theme.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/tests/phpunit/data/themedir2/</li>
<li>trunk/tests/phpunit/data/themedir2/test/</li>
<li><a href="#trunktestsphpunitdatathemedir2testfunctionsphp">trunk/tests/phpunit/data/themedir2/test/functions.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir2testindexphp">trunk/tests/phpunit/data/themedir2/test/index.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir2teststylecss">trunk/tests/phpunit/data/themedir2/test/style.css</a></li>
<li>trunk/tests/phpunit/data/themedir2/test-parent/</li>
<li><a href="#trunktestsphpunitdatathemedir2testparentfunctionsphp">trunk/tests/phpunit/data/themedir2/test-parent/functions.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir2testparentindexphp">trunk/tests/phpunit/data/themedir2/test-parent/index.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir2testparentstylecss">trunk/tests/phpunit/data/themedir2/test-parent/style.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesmsblogsphp"></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/ms-blogs.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/ms-blogs.php 2023-11-20 00:06:08 UTC (rev 57128)
+++ trunk/src/wp-includes/ms-blogs.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -491,8 +491,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @global array $_wp_switched_stack
</span><span class="cx" style="display: block; padding: 0 10px"> * @global bool $switched
</span><span class="cx" style="display: block; padding: 0 10px"> * @global string $table_prefix
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global string $wp_template_path
- * @global string $wp_stylesheet_path
</del><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $new_blog_id The ID of the blog to switch to. Default: current blog.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -534,10 +532,8 @@
</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"> $wpdb->set_blog_id( $new_blog_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
- $GLOBALS['blog_id'] = $new_blog_id;
- $GLOBALS['wp_template_path'] = null;
- $GLOBALS['wp_stylesheet_path'] = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
+ $GLOBALS['blog_id'] = $new_blog_id;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_switch_to_blog( $new_blog_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -604,8 +600,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @global int $blog_id
</span><span class="cx" style="display: block; padding: 0 10px"> * @global bool $switched
</span><span class="cx" style="display: block; padding: 0 10px"> * @global string $table_prefix
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global string $wp_template_path
- * @global string $wp_stylesheet_path
</del><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True on success, false if we're already on the current blog.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -631,10 +625,8 @@
</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"> $wpdb->set_blog_id( $new_blog_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $GLOBALS['blog_id'] = $new_blog_id;
- $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
- $GLOBALS['wp_template_path'] = null;
- $GLOBALS['wp_stylesheet_path'] = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $GLOBALS['blog_id'] = $new_blog_id;
+ $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_switch_to_blog( $new_blog_id );
</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 2023-11-20 00:06:08 UTC (rev 57128)
+++ trunk/src/wp-includes/theme.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,39 +188,25 @@
</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"> * @since 6.4.0 Memoizes filter execution so that it only runs once for the current theme.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.4.2 Memoization removed.
</ins><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 $wp_stylesheet_path Current theme stylesheet directory path.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @return string Path to active theme's stylesheet directory.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_stylesheet_directory() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wp_stylesheet_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $stylesheet = get_stylesheet();
+ $theme_root = get_theme_root( $stylesheet );
+ $stylesheet_dir = "$theme_root/$stylesheet";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null === $wp_stylesheet_path ) {
- $stylesheet = get_stylesheet();
- $theme_root = get_theme_root( $stylesheet );
- $stylesheet_dir = "$theme_root/$stylesheet";
-
- /**
- * Filters the stylesheet directory path for the active theme.
- *
- * @since 1.5.0
- *
- * @param string $stylesheet_dir Absolute path to the active theme.
- * @param string $stylesheet Directory name of the active theme.
- * @param string $theme_root Absolute path to themes directory.
- */
- $stylesheet_dir = apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
-
- // If there are filter callbacks, force the logic to execute on every call.
- if ( has_filter( 'stylesheet' ) || has_filter( 'theme_root' ) || has_filter( 'stylesheet_directory' ) ) {
- return $stylesheet_dir;
- }
-
- $wp_stylesheet_path = $stylesheet_dir;
- }
-
- return $wp_stylesheet_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the stylesheet directory path for the active theme.
+ *
+ * @since 1.5.0
+ *
+ * @param string $stylesheet_dir Absolute path to the active theme.
+ * @param string $stylesheet Directory name of the active theme.
+ * @param string $theme_root Absolute path to themes directory.
+ */
+ return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
</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">@@ -338,39 +324,25 @@
</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"> * @since 6.4.0 Memoizes filter execution so that it only runs once for the current theme.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.4.1 Memoization removed.
</ins><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 $wp_template_path Current theme template directory path.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @return string Path to active theme's template directory.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_template_directory() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wp_template_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $template = get_template();
+ $theme_root = get_theme_root( $template );
+ $template_dir = "$theme_root/$template";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null === $wp_template_path ) {
- $template = get_template();
- $theme_root = get_theme_root( $template );
- $template_dir = "$theme_root/$template";
-
- /**
- * Filters the active theme directory path.
- *
- * @since 1.5.0
- *
- * @param string $template_dir The path of the active theme directory.
- * @param string $template Directory name of the active theme.
- * @param string $theme_root Absolute path to the themes directory.
- */
- $template_dir = apply_filters( 'template_directory', $template_dir, $template, $theme_root );
-
- // If there are filter callbacks, force the logic to execute on every call.
- if ( has_filter( 'template' ) || has_filter( 'theme_root' ) || has_filter( 'template_directory' ) ) {
- return $template_dir;
- }
-
- $wp_template_path = $template_dir;
- }
-
- return $wp_template_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the active theme directory path.
+ *
+ * @since 1.5.0
+ *
+ * @param string $template_dir The path of the active theme directory.
+ * @param string $template Directory name of the active theme.
+ * @param string $theme_root Absolute path to the themes directory.
+ */
+ return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
</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">@@ -776,13 +748,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Customize_Manager $wp_customize
</span><span class="cx" style="display: block; padding: 0 10px"> * @global array $sidebars_widgets
</span><span class="cx" style="display: block; padding: 0 10px"> * @global array $wp_registered_sidebars
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global string $wp_stylesheet_path
- * @global string $wp_template_path
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $stylesheet Stylesheet name.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function switch_theme( $stylesheet ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars, $wp_stylesheet_path, $wp_template_path;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $requirements = validate_theme_requirements( $stylesheet );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $requirements ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -866,13 +836,6 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * Reset globals to force refresh the next time these directories are
- * accessed via `get_stylesheet_directory()` / `get_template_directory()`.
- */
- $wp_stylesheet_path = null;
- $wp_template_path = null;
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Clear pattern caches.
</span><span class="cx" style="display: block; padding: 0 10px"> $new_theme->delete_pattern_cache();
</span><span class="cx" style="display: block; padding: 0 10px"> $old_theme->delete_pattern_cache();
</span></span></pre></div>
<a id="trunktestsphpunitdatathemedir2testfunctionsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test/functions.php (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test/functions.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+// Dummy theme.
+
+echo __DIR__ . '/' . basename(__FILE__);
+
+?>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test/functions.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir2testindexphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test/index.php (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test/index.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+// Dummy theme.
+
+echo __DIR__ . '/' . basename(__FILE__);
+
+?>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test/index.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir2teststylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test/style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test/style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test/style.css 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,12 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+Theme Name: Test Theme
+Theme URI: http://example.org/
+Description: An example theme
+Version: 1.3
+Author: Minnie Bannister
+Author URI: http://example.com/
+Template: test-parent
+*/
+
+
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test/style.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir2testparentfunctionsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test-parent/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test-parent/functions.php (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test-parent/functions.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+// Dummy theme.
+
+echo __DIR__ . '/' . basename(__FILE__);
+
+?>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test-parent/functions.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir2testparentindexphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test-parent/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test-parent/index.php (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test-parent/index.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+// Dummy theme.
+
+echo __DIR__ . '/' . basename(__FILE__);
+
+?>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test-parent/index.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir2testparentstylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir2/test-parent/style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir2/test-parent/style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir2/test-parent/style.css 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,12 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+Theme Name: Test Parent Theme
+Theme URI: http://example.org/
+Description: An example parent theme
+Version: 1.3
+Author: Minnie Bannister
+Author URI: http://example.com/
+Template: test-parent
+*/
+
+
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir2/test-parent/style.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><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 2023-11-20 00:06:08 UTC (rev 57128)
+++ trunk/tests/phpunit/tests/theme.php 2023-11-20 22:27:17 UTC (rev 57129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1179,4 +1179,130 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped( "Could not switch to $block_theme." );
</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">+
+ /**
+ * Make sure filters added after the initial call are fired.
+ *
+ * @ticket 59847
+ *
+ * @covers ::get_stylesheet_directory
+ */
+ public function test_get_stylesheet_directory_filters_apply() {
+ // Call the function prior to the filter being added.
+ get_stylesheet_directory();
+
+ $expected = 'test_root/dir';
+
+ // Add the filer.
+ add_filter(
+ 'stylesheet_directory',
+ function () use ( $expected ) {
+ return $expected;
+ }
+ );
+
+ $this->assertSame( $expected, get_stylesheet_directory() );
+ }
+
+ /**
+ * Make sure filters added after the initial call are fired.
+ *
+ * @ticket 59847
+ *
+ * @covers ::get_template_directory
+ */
+ public function test_get_template_directory_filters_apply() {
+ // Call the function prior to the filter being added.
+ get_template_directory();
+
+ $expected = 'test_root/dir';
+
+ // Add the filer.
+ add_filter(
+ 'template_directory',
+ function () use ( $expected ) {
+ return $expected;
+ }
+ );
+
+ $this->assertSame( $expected, get_template_directory() );
+ }
+
+ /**
+ * Make sure get_stylesheet_directory uses the correct path when the root theme dir changes.
+ *
+ * @ticket 59847
+ *
+ * @covers ::get_stylesheet_directory
+ */
+ public function test_get_stylesheet_directory_uses_registered_theme_dir() {
+ $old_theme = wp_get_theme();
+
+ switch_theme( 'test' );
+
+ $old_root = get_theme_root( 'test' );
+ $path1 = get_stylesheet_directory();
+
+ $new_root = DIR_TESTDATA . '/themedir2';
+ register_theme_directory( $new_root );
+
+ // Mock the stylesheet root option to mimic that the active root has changed.
+ add_filter(
+ 'pre_option_stylesheet_root',
+ function () use ( $new_root ) {
+ return $new_root;
+ }
+ );
+
+ $path2 = get_stylesheet_directory();
+
+ // Cleanup.
+ switch_theme( $old_theme->get_stylesheet() );
+
+ $this->assertEquals( $old_root . '/test', $path1, 'The original stylesheet path is not correct' );
+ $this->assertEquals( $new_root . '/test', $path2, 'The new stylesheet path is not correct' );
+ }
+
+ /**
+ * Make sure get_template_directory uses the correct path when the root theme dir changes.
+ *
+ * @ticket 59847
+ *
+ * @covers ::get_template_directory
+ */
+ public function test_get_template_directory_uses_registered_theme_dir() {
+ $old_theme = wp_get_theme();
+
+ switch_theme( 'test' );
+
+ // Mock parent theme to be returned as the template.
+ add_filter(
+ 'pre_option_template',
+ function () {
+ return 'test-parent';
+ }
+ );
+
+ $old_root = get_theme_root( 'test' );
+ $path1 = get_template_directory();
+
+ $new_root = DIR_TESTDATA . '/themedir2';
+ register_theme_directory( $new_root );
+
+ // Mock the template root option to mimic that the active root has changed.
+ add_filter(
+ 'pre_option_template_root',
+ function () use ( $new_root ) {
+ return $new_root;
+ }
+ );
+
+ $path2 = get_template_directory();
+
+ // Cleanup.
+ switch_theme( $old_theme->get_stylesheet() );
+
+ $this->assertEquals( $old_root . '/test-parent', $path1, 'The original template path is not correct' );
+ $this->assertEquals( $new_root . '/test-parent', $path2, 'The new template path is not correct' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>