[wp-trac] [WordPress Trac] #61188: switch_to_blog() causes Fatal error on classic themes
WordPress Trac
noreply at wordpress.org
Mon May 13 08:53:38 UTC 2024
#61188: switch_to_blog() causes Fatal error on classic themes
-------------------------------+------------------------------
Reporter: digberlin | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: 6.5.3
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: multisite
-------------------------------+------------------------------
Comment (by digberlin):
Replying to [comment:1 swissspidy]:
> Hi there and welcome to WordPress Trac!
>
> Can you please share some code to reproduce this issue and where exactly
you are using this code?
>
> It sounds like your code is inadvertently creating some infinite loop or
so, hence the memory issue.
Thank you swissspidy for looking into this.
In my themes, I switch to the main site on a multisite installation and
get customs posts.
But this error occurs even when just calling switch_to_blog() and nothing
else.
For testing, I added this
{{{
switch_to_blog(1);
restore_current_blog();
}}}
to functions.php on a clean Twenty Twenty-One Theme running on WP 5.6.3
with no plug-ins active. Also tested on both, local dev and live
production installations.
Also tested on multiple other themes with same result:
{{{
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 8388608 bytes) in [redacted]/wordpress/wp-includes/class-wpdb.php
on line 2320
}}}
When switching to any other site, like
{{{
switch_to_blog(7);
restore_current_blog();
}}}
adds an additional error
{{{
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 20480 bytes) in [redacted]/wordpress/wp-includes/class-wpdb.php
on line 2320
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 20480 bytes) in [redacted]/wordpress/wp-includes/class-wp-fatal-
error-handler.php on line 76
}}}
Twenty Twenty-Four is unaffected.
WP 6.4 is unaffected.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61188#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list