wordpress-multisite-enhancements
wordpress-multisite-enhancements copied to clipboard
[Bug]: Use of `continue` inside of `switch_to_blog()` corrupts blog loop
Description of the bug
In https://github.com/bueltge/wordpress-multisite-enhancements/commit/9063da7b1fd0a3c691f99953d5a7484d6fed9993 you modified the admin-bar routine so that the current blog is skipped when no comment node can be found. However, because this happens inside a switch_to_blog() loop, the next call to switch_to_blog() causes the next blog_id to be added to the top of the "switched" stack. Then, when restore_current_blog() is finally called, the incorrect blog is return. This results in data corruption when the rest of the page is rendered, since WP thinks we're on the wrong blog.
Reproduction instructions
- On Multisite, visit a secondary site while logged in as a user who is a member of a number of sites, at least one of which will not have the
$comment_node - You'll see data corruption on the rest of the page
Expected behavior
The correct data will load.
Environment info
No response
Relevant log output
No response
Additional context
The fix is to add a restore_current_blog() call just before continue:
$comment_node = $wp_admin_bar->get_node( $menu_id );
if ( ! $comment_node ) {
restore_current_blog();
continue;
}
I can send a PR if it's preferred.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct