Usage of switch_to_blog() and restore_current_blog()
-
Hi,
I found an illegal usage of switch_to_blog() and restore_current_blog().wp-category-tag-cloud.php: line 155
foreach ( $blogs as $blog ) { switch_to_blog( $blog ); $this->single_activate( $network_wide ); } restore_current_blog();
This should be:
foreach ( $blogs as $blog ) { switch_to_blog( $blog ); $this->single_activate( $network_wide ); restore_current_blog(); }
These APIs have a stack (actually just an array) inside.
switch_to_blog() pushes current blog id to the stack and restore_current_blog() pops the stack and back to the previous blog in the switching history.
We need to call restore_current_blog() same number of times of calling switch_to_blog().I’m not sure this effect, but in generally, this causes strange behaviors of whole WordPress, because of switch_to_blog() replaces global variables.
- The topic ‘Usage of switch_to_blog() and restore_current_blog()’ is closed to new replies.