Ability to programmatically disable modules
See original GitHub issueFeature Description
In a network install, each site admin doesn’t have many technical capabilities. They are unable to perform many of the actions necessary to optimise a website for speed. For example, PageSpeed Insights includes some very useful suggestions but the suggestions aren’t actionable by the site admin. They are, however, actionable by the super admin or a person with developer access.
It would be neat if the super admin could enable and disable the various modules at the network level based on whether they are useful for the site admins in the network.
By modules I’m referring to:
- Google AdSense
- Google Analytics
- Google Search Console
- PageSpeed Insights
- Tag Manager
- Optimize
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When registering the Site Kit modules internally in the Site Kit registry, the list of module class names should be filtered via a new filter
googlesitekit_available_modules
. The filter should only allow removing items, not adding any that aren’t in the unfiltered list.
Implementation Brief
- Using
includes/Core/Modules/Modules.php
:- Update the
$core_modules
array to be an associative array where keys are module slugs and values are class names. - Update the
setup_registry
method:- to apply the
googlesitekit_available_modules
filter to keys of the$this->core_modules
array. - then in the
foreach
loop register modules if their slug is in the list of the available modules returned from the filter or the module is force active.
- to apply the
- Update the
Test Coverage
- Update
tests/phpunit/integration/Core/Modules/ModulesTest.php
to include tests for thegooglesitekit_available_modules
filter.
QA Brief
List with the slug of all the modules.
site-verification
search-console
analytics
optimize
tag-manager
adsense
pagespeed-insights
analytics-4
Modules added via featured flags.
idea-hub
subcribe-with-google
Add the following snippets of code into your functions.php
of your active theme or in mu-plugins/overrides.php
and place the code there.
Disable All Modules
<?php
add_filter(
'googlesitekit_available_modules',
function( $modules ) {
return array();
}
);
*Enable Only Search Console
<?php
add_filter(
'googlesitekit_available_modules',
function( $modules ) {
return array( 'search-console' );
}
);
Changelog entry
- Add the ability to programmatically disable modules using the
googlesitekit_available_modules
filter.
Issue Analytics
- State:
- Created 2 years ago
- Comments:27 (9 by maintainers)
QA: ✔️
Verified that the filter works as expected.
LGTM.
It’s okay to change issue titles if the definition justifies it - I just updated the one for this, to exclude suggesting that this enhancement would be tied to multisite.