[buddypress-trac] [BuddyPress Trac] #6240: restore_current_blog() being called when not needed, causing issues with some plugins
buddypress-trac
noreply at wordpress.org
Fri Feb 20 16:23:16 UTC 2015
#6240: restore_current_blog() being called when not needed, causing issues with
some plugins
--------------------------+-----------------------------
Reporter: sj-xweb | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: API | Version:
Severity: normal | Keywords:
--------------------------+-----------------------------
bp_get_object_terms() in bp-core/bp-core-taxonomy.php does a root blog
check, and switches to root if the check fails.
Then restore_current_blog() is called soon after.
The problem is that restore_current_blog() can be called even if
switch_to_blog() didn't get called earlier. This is causing some issues
with some plugins that has some functionality that leans on switch_to_blog
quite a bit, but can't/don't use restore_to_blog to go back to the
original blog. Which means that {{{$GLOBALS['_wp_switched_stack']}}}
(what WP uses to keep track of all the blog switches, and
restore_current_blog() uses to determine if there is a blog to restore to)
doesn't get cleared out properly.
When BP calls bp_get_object_terms() which in turn calls
restore_current_blog() even when not needed, causes current blog to be
changed to the last time switch_to_blog() was called.
For example, if {{{$GLOBALS['_wp_switched_stack']}}} has the following
value:
{{{
array(
'0' => 1
'1' => 2
'2' => 3
'3' => 4
'4' => 5
)
}}}
The current blog is 1, and the last element was the last blog the code
switched from. The above may happen if the plugin loop through
switch_to_blog to poll all the blogs in multisite. So the next time
restore_to_blog() is called, the blog it switches to is 5, which is wrong.
Please let me know if you need more clarification.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6240>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list