question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to programmatically disable modules

See original GitHub issue

Feature 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.

Test Coverage

  • Update tests/phpunit/integration/Core/Modules/ModulesTest.php to include tests for the googlesitekit_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:closed
  • Created 2 years ago
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
kuasha420commented, Dec 16, 2021

QA: ✔️

Verified that the filter works as expected.

  • Filter works for enabling/disabling single or multiple modules.
  • Mandatory modules remain enabled regardless of their presence in the filter.
  • Filter interacts correctly with modules behind feature flags. ( checked with Tester Plugin).
    • Enabling modules that are disabled by feature flag with the filter is NOT possible.
    • But if the feature flag is enabled, it is possible to disable the module using the filter.

LGTM.

2reactions
felixarntzcommented, Dec 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable/disable modules programmatically
If you want to disable a module, there is a conveniently named sister function called module_disable(). module_disable(array('module_1', 'module_2', module_3));.
Read more >
How to disable/enable a module via code
I would like to enable /disable the devel_themer module via code (I display a toggle button in a form on the header of...
Read more >
Best method to enable/disable modules depending on the ...
One possible answer is the Environment module (the 7.x dev release works just fine). It allows you to define arbitrary environments (comes ...
Read more >
Temporarily disabling a module : IDEA-27471 - YouTrack
I'd like to temporarily disable the compilation of one or more modules included in my project. I know this has been asked before,...
Read more >
How to disable and uninstall a Drupal module ...
I want to be able to disable and then uninstall a module programmatically on my local environment and then easily push that code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found