[wp-trac] [WordPress Trac] #59677: Incorrect theme returned when switching to blog in multisite subsite
WordPress Trac
noreply at wordpress.org
Thu Oct 19 05:28:34 UTC 2023
#59677: Incorrect theme returned when switching to blog in multisite subsite
--------------------------------+-----------------------------
Reporter: codex-m | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version: trunk
Severity: major | Keywords:
Focuses: multisite |
--------------------------------+-----------------------------
I think I have found issue with the coming WordPress 6.4. I tested with
latest WordPress 6.4 RC1.
**Environment**
PHP Version: 8.0
Operating system: Ubuntu 20.04
**Test code to reproduce the issue (e.g. save this as reproduce.php):**
{{{#!php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);
require_once('wp-load.php');
switch_to_blog(2);
$template_path = get_template_directory();
$stylesheet_path = get_stylesheet_directory();
restore_current_blog();
echo "PARENT THEME: {$template_path}";
echo "<br />";
echo "CHILD THEME: {$stylesheet_path}";
}}}
**How to reproduce the issue:**
1.) Setup a fresh WordPress multisite.
2.) Create a new subsite (BLOG ID: 2)
3.) Activate a non-default theme (with parent and child theme) subsite
BLOG ID: 2. For example, in this testing I use Astra parent and child
theme).
4.) Run the test script on the main site by calling it as:
`https://yourmultisite.tld/reproduce.php`
**Test result**:
1.) WordPress 6.3.2 OUTPUT:
PARENT THEME: `/home/emerson/sourcecode/subdomaintest/wp-
content/themes/astra`
CHILD THEME: `/home/emerson/sourcecode/subdomaintest/wp-content/themes
/astra-child`
2.) Latest WordPress 6.4 RC1 OUTPUT:
PARENT THEME: `/home/emerson/sourcecode/subdomaintest/wp-
content/themes/twentytwentythree`
CHILD THEME: `/home/emerson/sourcecode/subdomaintest/wp-
content/themes/twentytwentythree`
**Test summary**:
I expected to see the actual theme used in the subsite (blog ID: 2)
instead I got the currently activated main site theme (incorrect).
**Solution**
I think the issue is that in WordPress 6.4, the result of these functions
(`get_template_directory()` &
`get_stylesheet_directory()`) are now stored into global variables for
performance reasons. However the issue is that in multisite - these can be
set first before the blog is switched thus preventing to return the
correct value once the blog is switched.
I think we can fix this by checking if the call is made in multisite and
if the blog is already switched. Once switched, we unset these global
variables so it will return the correct values.
This is only my suggestion to fix this issue. Please attached patch.
Thanks!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59677>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list