Activate WP SlimStat Dashboard Widgets in WordPress Multisite

If you have WordPress Multisite installed and the WP SlimStat plugin activated network wide, the optional WP SlimStat Dashboard widgets won’t be available to you. The problem is that the dashboard widgets file is using get_option('active_plugins') to see if the plugin is active, and if it’s active network wide it won’t be in this array – it will be in get_site_options('active_sitewide_plugins'). Rather than modifying the WP SlimStat plugin files (which will be overwritten when you upgrade), I recommend adding the following filter to a custom functions plugin to add the value to the array before it is read by the dashboard widgets. Using functions.php in your theme is out because get_option() in the WP SlimStat plugin is called before it loads. You could also use a Must Use Plugin placed in /wp-content/mu-plugins.

There is some checking to make sure this only happens on the admin index page, but that’s just to be safe – it really shouldn’t have any adverse affects on your site except a few edge cases.

function activate_slimstat_dashboard_multisite($plugins){
	// only run on multisite admin index screens.
	// $pagenow isn't available, so we have to preg_match the SCRIPT_NAME (should work for subdirectories)
	if (is_multisite() && preg_match("~/wp-admin/index\.php$~", $_SERVER['SCRIPT_NAME'])){
		$slimstat_plugin = 'wp-slimstat/wp-slimstat.php';
		// check if plugin is active network wide and if so add to site plugins
		if (array_key_exists($slimstat_plugin, get_site_option('active_sitewide_plugins', array())))
			$plugins[] = $slimstat_plugin;
	return $plugins;
add_filter( 'option_active_plugins', 'activate_slimstat_dashboard_multisite' );

You may also like...

1 Response

  1. camu says:

    Hi there,

    I just stumbled upon this article coming from the support forum. I’ve been busy with other stuff, but your idea is great, and I’m adding it to the next release of WP SlimStat. I’m also planning to add a series of hooks here and there (and document them, of course), so that it will be easier to customize the plugin’s behavior with a child plugin or something. Stay tuned!

Leave a Reply

Your email address will not be published. Required fields are marked *