Check if Jetpack Modules Are Enabled

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.

About Devin

I'm a WordPress developer based in Austin, Texas. I run a little theme shop called DevPress, and am @devinsays on twitter.

5 Responses

  1. 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!
    }
    }

  2. 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() ) {}

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>