Add minimal support for multisite (not network mode)
Since it's release, Site Kit has not supported network wide usage in any way (see #276). It explicitly does not load when network activated, and shows an admin notice that it should be activated per site instead.
While the reason for that are the larger plans to implement a true "network mode", in which Site Kit applies to the entire network of sites and has its UI within the Network Admin, this is only one sub set of WordPress multisite use-cases.
At a very high level, there are two types of multisites:
- A network represents the main entity, and the sites within it are part of that
- Example: A university network, where e.g. each faculty has its own site
- A network is purely used for administrative purposes, and the sites are entirely unrelated/disconnected
- Example: wordpress.com, where anybody can sign up to create a site, decoupled from any other site
The "network mode" described in #276 really applies mostly to type 1. However, many multisite networks have entirely unrelated sites, and for them using Site Kit could just work the same as it does today. To be fair, the only win in having Site Kit support network wide usage there would be that it could be network-activated while still behaving the same as today. But that is already a small worthy win for maintenance purposes and at least covers basic multisite compatibility.
Supporting 2. is an extremely small effort, which this issue is about. Supporting 1. remains a much larger effort, which is still unclear for when it can be prioritized. #276 will remain focused on that.
Props @bahia0019 for raising that point with us during WordCamp US.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
Context::is_network_mode()method should for now always returnfalse, even when the plugin is network active.- Network mode is not yet supported, but the condition itself should be kept throughout the plugin for the future.
- The
Context::is_network_active()call should remain in the method (even though it technically also returnsfalse. For the newfalsereturn value, a filtergooglesitekit_is_network_modeshould be added that allows filtering that value. Documentation for the filter should include something likeThis is always false by default since Site Kit does not support a network mode yet.
- The network admin notice added when the plugin is network active should be changed as follows:
- It should call the
is_network_mode()method instead ofis_network_active()going forward (which will always befalseby default, except possibly because of the above filter). In other words, for basically any regular multisite, the plugin should now initialize as usual. The condition should only be kept in place in case somebody uses the above filter (which probably nobody should at this point, except for testing). - The copy of the notice should be adjusted to purely be about network mode rather than overall multisite support:
The Site Kit by Google plugin does <strong>not yet offer</strong> a network mode, but we’re actively working on that. - Additionally, the paragraph
Meanwhile, we recommend deactivating it in the network and re-activating it for an individual site.should be entirely removed.
- It should call the
Implementation Brief
- Adjust
Context::is_network_mode()as described in the ACs, including the new filter (only when network active). - Tweak the condition and admin notice message at the beginning of
Plugin::register()as described in the ACs.
Test Coverage
- Update relevant tests that would otherwise fail. For multisite tests, rely on e.g.
add_filter( 'googlesitekit_is_network_mode', '__return_true' )to enforce network mode for a single test as needed.
QA Brief
- Use a multisite, and network-activate Site Kit.
- Set up Site Kit on at least 2 sites within that multisite network (you will need to go into the WP Admin for those individual sites), and fully configure it.
- Play around with various common things in Site Kit, e.g. activating other modules, tweaking settings, just to roughly check that those interactions still work as expected with the plugin network active (it's unlikely that something broke here, but we should have high level checks at least).
Changelog entry
- Allow WordPress Multisite network activation of Site Kit (currently only for per-site use).
@felixarntz this sounds good to me. Regarding the changes to the notice, should we then remove this portion of it? https://github.com/google/site-kit-wp/blob/db0c22626212552d025da373114844a9e5f6cc3a/includes/Plugin.php#L83-L85
Perhaps this was implied but just wanted to check.
@aaemnnosttv Good catch, included that in the ACs to clarify.
IB ✅
QA Update: ✅
Verified:
- Set up a multisite, and network-activate Site Kit.
- Set up Site Kit on 3 sites within that multisite network and fully configured each one.
- Set up all modules within settings and the usual CTAs.
- Changed the settings for the different modules.
- Deleted modules within settings.
- Browsed around the main and entity dashboard.
- Went the UI by changing date periods at a high level.
- Everything worked as expected no errors appeared on the FE or in console.
https://user-images.githubusercontent.com/73545194/196408451-869dec2f-a2fa-40f9-bfb4-c52daac8f46f.mp4