Skip to content

[Bug]: Use of continue inside of switch_to_blog() corrupts blog loop  #81

@boonebgorges

Description

@boonebgorges

Description of the bug

In 9063da7 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

  1. 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
  2. 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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions