[wp-trac] [WordPress Trac] #60290: Changeset #56635 breaks template loading in multisite network using switch_to_blog()

WordPress Trac noreply at wordpress.org
Tue Jan 23 22:07:08 UTC 2024


#60290: Changeset #56635 breaks template loading in multisite network using
switch_to_blog()
--------------------------------------+--------------------------
 Reporter:  metropolis_john           |       Owner:  joemcgill
     Type:  defect (bug)              |      Status:  accepted
 Priority:  normal                    |   Milestone:  6.5
Component:  Themes                    |     Version:  6.4.2
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------

Comment (by manfcarlo):

 Replying to [comment:7 joemcgill]:
 > `switch_to_blog()` is a function that is meant to let you access
 ''data'' from another site on the network (e.g., users, posts, options,
 etc.), but was not meant to allow you to change to different parts of a
 filesystem. This similar to why `switch_to_blog()` doesn't change which
 plugins are active (see #14941).


 I think this is very different from #14941. The request there was to un-
 include files that were already included, which is not possible with PHP,
 so there was no choice but to leave the ticket unpatched.

 What we are talking about here is adding new code to explicitly disable a
 feature of `switch_to_blog` when it was fully operational previously.

 If I actually want to load a template part from the other site, and I know
 the template part isn't going to cause any PHP errors, then I would use
 this code:


 {{{
 switch_to_blog( 2 );
 get_template_part( 'template-part-for-site-2' );
 restore_current_blog();
 }}}

 If the above code is to not work as I expected, who does it benefit? It
 adds extra maintenance to core and causes inconvenience to me.

 Hypothetically, your patch could cause even greater issues. If the
 template part being included fetches theme mods or fetches the theme URI
 to load assets etc, it will try to fetch from the switched blog, which is
 obviously of no use to anyone.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60290#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list