Skip to content

Instantly share code, notes, and snippets.

@robneu
Forked from jeherve/plugin.php
Last active December 30, 2015 19:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robneu/7872308 to your computer and use it in GitHub Desktop.
Save robneu/7872308 to your computer and use it in GitHub Desktop.
<?php
/**
* An array of Jetpack modules which will be whitelisted.
*
* This whitelist contains a list of all Jetpack modules which we would like users
* to have access to. Anything not listed here will be programmatically disabled.
*
* @author FAT Media, LLC
* @link http://wpbacon.com/disable-jetpack-modules/
*/
function prefix_jetpack_whitelist() {
$whitelist = array(
'publicize',
'enhanced-distribution',
'sharedaddy',
);
return $whitelist;
}
add_filter( 'jetpack_get_available_modules', 'prefix_make_non_whitelisted_unavailable' );
/**
* Make all non-whitelisted Jetpack modules unavailable.
*
* This will prevent all non-whitelisted Jetpack modules from displaying.
* As long as this is in use only whitelisted modules can be seen by the user.
*
* @author FAT Media, LLC
*/
function prefix_make_non_whitelisted_unavailable( $modules ) {
$whitelist = prefix_jetpack_whitelist();
$modules = array_intersect_key( $modules, array_flip( $whitelist ) );
return $modules;
}
add_action( 'init', 'prefix_force_deactivate_non_whitelisted' );
/**
* Force disable all non-whitelisted Jetpack modules.
*
* This will force all non-whitelisted Jetpack modules to be disabled.
* As long as this is in use, only whitelisted modules can be activated.
*
* @author Jeremy Herve
* @author FAT Media, LLC
*/
function prefix_force_deactivate_non_whitelisted() {
if ( ! class_exists( 'Jetpack_Options' ) ) {
return;
}
$whitelist = prefix_jetpack_whitelist();
Jetpack_Options::update_option( 'active_modules', array_unique( $whitelist ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment