bueltge / wordpress-multisite-enhancements

Enhance WordPress Multisite for Network Admins with different topics
https://wordpress.org/plugins/multisite-enhancements/
GNU General Public License v2.0
103 stars 28 forks source link

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

Closed boonebgorges closed 2 days ago

boonebgorges commented 1 month ago

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

  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

beckej13820 commented 2 weeks ago

Just commenting that this bug caused me to uninstall this plugin from my multisite until it is fixed.

It caused blogs on a multisite who were running the same theme to pull the site name and tagline of another blog on the network, it broke gravity forms because it was searching for forms from a different site, and broke several themes.

We have uninstalled until an update fixes the issue.

Zodiac1978 commented 2 weeks ago

Same for me:

After disabling the plugin, everything returns to normal. Waiting for a fix.

danielhuesken commented 2 weeks ago

multisite-enhancements.zip Package for testing the fix

Zodiac1978 commented 1 week ago

Fix seems to work! Thank you @boonebgorges @danielhuesken