How to tell if Jetpack’s Photon is active?

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?

Related posts

Leave a Reply

2 comments

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

  2. 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
    )