You may have code that relies on certain JetPack functions. If so, there’s a simple way to check if the module you need is enabled:
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) : endif;
Here’s some popular module names you might be looking for:
- carousel
- comments
- contact-form
- custom-css
- enhanced-distribution
- gplus-authorship
- gravatar-hovercards
- infinite-scroll
- json-api
- latex
- likes
- markdown
- minileven
- monitor
- notes
- omnisearch
- photon
- post-by-email
- publicize
- related-posts
- sharedaddy
- shortcodes
- shortlinks
- sso
- stats
- subscriptions
- tiled-gallery
- vaultpress
- videopress
- widget-visibility
- widgets
This post was edited and updated when JetPack introduced the is_module_active function.
Thanks Devin! I was looking for this for months!
This will still evaluate to true if Jetpack is de-activated after the option has been set at some point. Adding a check for the class seems to help:
if ( class_exists( 'Jetpack', false ) ) {
$jetpack_active_modules = get_option('jetpack_active_modules');
if ( $jetpack_active_modules && in_array( 'sharedaddy', $jetpack_active_modules ) ) {
// We're good to go!
}
}
Thanks Kirk. Good call, updated the snippet.
We just committed a new function to Jetpack Trunk, and it should be enabled in the next release,
Jetpack::is_module_active()
—http://plugins.trac.wordpress.org/changeset/716884
Then you can just call:
if( class_exists( ‘Jetpack’ ) && Jetpack::is_module_active( ‘contact-form’ ) ) {}
Or at least, you will once the next version releases, and the user has their Jetpack updated. :) If you’d like to preserve the backward compatability, you can just do:
if( class_exists( ‘Jetpack’ ) && in_array( ‘contact-form’, Jetpack::get_active_modules() ) {}
Awesome. Thanks for sharing that George.
And depending what you are doing you can also simply extend the JetPack class and check using $this->is_module_active( ‘module_name’ ) 8-)