Jetpack

How to disable the auto-activation of a Jetpack module

In Jetpack 2.6, we will introduce a new filter, jetpack_get_default_modules. It will allow you to stop the auto-activation of a specific Jetpack module.

Here is an example with the Widget Visibility module:

// To disable the auto-activation of Jetpack's Widget Visibility module:
add_filter( 'jetpack_get_default_modules', 'disable_jetpack_widget_visibility_autoactivate' );
function disable_jetpack_widget_visibility_autoactivate( $modules ) {
	return array_diff( $modules, array( 'widget-visibility' ) );
}

// Or, to disable the functionality in your own plugin if the user activates it in Jetpack:
if ( ! class_exists( 'Jetpack' ) || ! Jetpack::is_module_active( 'widget-visibility' ) ) {
	// It's not there, do as you like!
}

Reference.

If you wanted all Jetpack modules to be deactivated by default, you could use the following code:

add_filter( 'jetpack_get_default_modules', '__return_empty_array' );
Posted in Code snippets, Tips & Tricks | Tagged , , , , | Comments Off

How to load only a specific Jetpack module

Sometimes you do not want to see a specific module in the Jetpack menu. You might not use it at all, or you might want to make sure other admins can’t activate it.

For such cases, you can use the jetpack_get_available_modules filter to control the list of modules available in Jetpack.

Load only a specific Jetpack module

function tweakjp_only_stats ( $modules ) {
    $return = array();
    $return['stats'] = $modules['stats'];
    return $return;
}
add_filter( 'jetpack_get_available_modules', 'tweakjp_only_stats' );

Disable a specific module

function tweakjp_disable_stats ( $modules ) {
    unset( $modules['stats'] );
    return $modules;
}
add_filter( 'jetpack_get_available_modules', 'tweakjp_disable_stats' );
Posted in Code snippets, Tips & Tricks | Tagged , , , | Comments Off
Follow

Get every new post delivered to your Inbox.

Join 62,914 other followers