New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust the WC_Admin_Notices to support multisite setups #45349
Adjust the WC_Admin_Notices to support multisite setups #45349
Conversation
Previously there was one single locally cached instance of the notice names array that wasn't aware of switch_to_blog executions. Now in multisite setups one separate array is kept for each existing blog id.
Hi @lsinger, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: 202375b
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and tests as intended. Also tested with a non-multisite blog to make sure that's not affected. Merge when CI has passed.
Previously there was one single locally cached instance of the notice names array that wasn't aware of switch_to_blog executions. Now in multisite setups one separate array is kept for each existing blog id.
Changes proposed in this Pull Request:
The
WC_Admin_Notices
uses a static array to cache the names of the existing notices locally (the$notices
field). In multisite setups this will cause the sequence of callsWC_Admin_Notices::add_custom_notice()
-switch_to_blog()
-WC_Admin_Notices::store_notices()
to generate awoocommerce_admin_notices
option in the second site with the values of the option names for the first site.While this doesn't cause notices to actually appear in wrong sites (each notice gets an additional
woocommerce_admin_notice_<name>
that is created in the proper site and is needed for the notice to actually be displayed), it causes thewoocommerce_admin_notices
option to get unnecessary values, which can lead to confussion (and in extreme cases degrade the site performance).This pull request fixes this by transforming the
$notices
field into an associative array where keys are site ids and values are arrays of notice names (for multisite only: for single site setups the original behavior is kept, so$notices
is still a plain names array).How to test the changes in this Pull Request:
Create a site in multisite mode, add one additional site, run
wp shell
in the command line and execute this:Without this fix you'll get an array with two entries,
site_1
andsite_2
. With the fix you'll get an array with onlysite_2
.You can also browse the admin area of both sites and verify that each site is still displaying its own notice only.
Changelog entry
Significance
Type
Message
Comment