Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There are multiple ways to identify if a plugin is active (here's one) but how can we identify if a specific JetPack component is active, for example Photon?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

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

It's a slightly tidier way than querying the option directly.

share|improve this answer

Checking for the option value jetpack_active_modules.

database option value

Searching for photon in wp_options is how I found the option_name.


The following prints the option as an admin notice:

add_action( 'admin_notices', 'wpse_75103_active_jetpack_modules' );

function wpse_75103_active_jetpack_modules() 
{
    if( !current_user_can( 'delete_users' ) )
        return;

    $jetp = get_option( 'jetpack_active_modules' );

    $photon_active = ( in_array( 'photon', $jetp ) ) ? 'is' : 'is not';
    echo '<h1>Photon ' . $photon_active . ' active</h1>';

    echo '<h2>All JetPack Options</h2>';
    echo '<pre>' . print_r( $jetp, true ) . '</pre>';
}

The following is the result with all modules activate.
The key numbers are in the order by which the modules were activated and should not be used as reference.
( in a local host installation )

Array
(
    [0] => vaultpress
    [1] => photon
    [3] => notes
    [5] => publicize
    [7] => stats
    [9] => comments
    [11] => subscriptions
    [13] => post-by-email
    [15] => carousel
    [17] => sharedaddy
    [19] => after-the-deadline
    [21] => infinite-scroll
    [23] => enhanced-distribution
    [25] => json-api
    [27] => mobile-push
    [29] => widgets
    [31] => latex
    [33] => gravatar-hovercards
    [35] => contact-form
    [37] => minileven
    [39] => custom-css
    [41] => shortcodes
    [43] => shortlinks
)
share|improve this answer
    
Photon displays as number 19 for me... [19] => photon. Would it be better (in your opinion) to check the array for the presence of Photon as a value? –  mattrepublic Dec 6 '12 at 14:13
    
You can use PHP function in_array() to check for Photon activation. I've updated the Answer to include an example of how to check this (which was your Question in the first place) :) –  brasofilo Dec 6 '12 at 15:33
    
That was perfect, thank you! –  mattrepublic Dec 10 '12 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.