Customize the list of modules available in Jetpack

Jeffro published an interesting post on WPTavern yesterday: 15+ Plugins To Get Jetpack Functionality Without Using Jetpack.

Knowing me, you won’t be surprised that I immediately started thinking of a few alternatives. :) So here it comes, 3 other ways to customize the list of Jetpack modules, if you cannot use or aren’t interested in everything Jetpack has to offer.

If you look under the hood, you’ll notice that Jetpack offers a great number of filters (225 as of today) allowing you to customize each module to fit your needs. Some of these filters were created to give you more control over the modules and their activation. Here are a few examples.

1. Use Jetpack without connecting it to your WordPress.com account

You may be working in a local or protected environment, or you may not want to create a WordPress.com account. It doesn’t mean that you can’t use Jetpack, though. You can activate the development mode to use all the Jetpack features that do not require a connection to WordPress.com servers.

To do so, add this line to your site’s wp-config.php file:

define( 'JETPACK_DEV_DEBUG', true);

You can also use the jetpack_offline_mode filter in a plugin:

add_filter( 'jetpack_offline_mode', '__return_true' );

This removes the need to use other plugins like Slim Jetpack.

2. Choose which modules are activated by default

The Jetpack menu includes options to activate and deactivate the modules you’re interested in. But when doing client work, you might have a list of the modules you want to activate and deactivate for each one of your clients. In such cases, why not use the jetpack_get_default_modules filter in a functionality plugin? It will allow you to predefine which Jetpack modules should be activated by default, thus saving you some precious time when setting up new sites for your clients.

If you’re a plugin developer, this filter is also a great way to automatically deactivate a specific Jetpack module when your plugin is activated.

In the following example, only the Stats module will be activated by default:

add_filter(
    'jetpack_get_default_modules',
    function () {
        return array( 'stats' );
    }
);
Only Stats are activated by default

You could also choose to deactivate all modules by default like so:

add_filter( 'jetpack_get_default_modules', '__return_empty_array' );

3. Do not activate and do not even display a module in the Jetpack menu

The above tip allows you to change the default activation behaviour, but users will still be able to activate or deactivate the module later on, by going to the Jetpack menu in their dashboard.

What if you don’t want your clients to enable a specific module? You can use the jetpack_get_available_modules filter to hide that module, like so:

function jeherve_kill_stats( $modules, $min_version, $max_version ) {
    unset( $modules['stats'] );
    return $modules;
}
add_filter( 'jetpack_get_available_modules', 'jeherve_kill_stats', 20, 3 );

And that’s it. The Stats module is now deactivated, and you won’t even be able to see the module card and activate the module back:

No more stats

You could also use this filter to disable all modules but the one or two you want your clients to be using:

function jeherve_only_stats( $modules, $min_version, $max_version ) {
    $return = array();
    $return['stats'] = $modules['stats'];
    return $return;
}
add_filter( 'jetpack_get_available_modules', 'jeherve_only_stats', 20, 3 );
Only Stats!

That’s a bit drastic, since your clients won’t be able to try new Jetpack features when we release them. But that removes the need for separate plugins like Jetpack Sharing or Jetpack Widget Visibility. You get to enforce the use of specific modules without having to use separate plugins where you do not know when the plugin author will port Jetpack updates to their own plugin.

I hope some of these tips prove helpful to some of you. You can use these snippets in a functionality plugin.

If you think of a filter that would help you with your work, do not hesitate to contact us, post in the forums, or submit a patch. We’ll be there to see if such a filter already exists, or if we can add it to Jetpack for you.

24 replies on “Customize the list of modules available in Jetpack”

[…] employee Jeremy Herve who works on the Jetpack team took notice of the post and created his own version of Jetpack alternatives. In the post, Jeremy outlines how […]

Thomas says:

All I can say is WOW!!! Thanks for this. I love using Jetpack, but I always hate having to connect the site i am working on and then having to go through the entire list of components and deactivate all the ones I didn’t need. I think that maybe this is something that should be added to the plugin by default. You know, something like a settings page where the user can “set up” Jetpack by selecting which modules they want to use.

If a particular module isnt selected to be used, then it wont appear in the list of modules. If a particular module is selected for use, then it appears like above, but not activated yet. The user would have to go in and activate it. Just a thought.

There’s certainly the hooks in place (as Jeremy pointed out above) to let a third-party plugin further control this — but I don’t think it’s something that necessarily has a place in Jetpack itself. In keeping with the core WordPress philosophy of decisions over options, we don’t want to overly complicate the core UI by adding multiple layers of enabling or disabling modules.

But as it’s a need you seem to have, as I mentioned, it’s certainly feasible as an add-on plugin. I’d love to see you build it! :)

Keith Brenneman says:

I second the WOW comment!!! One question, How do we know what to replace the “jeherve” with in the above code examples? Is that your WordPress.com account name? Thanks!

You can replace it with anything you’d like. Just so long as that same function name doesn’t exist anywhere else.

David Decker says:

Thank you Jeremy! That’s just what we (a lot of us I guess…) need sometimes in our (client) work. Thank you for posting and documenting it. Maybe you know that I am not the greatest fan of Jetpack around, but posts like this and such documentation really raises my respect for Jetpack and seems to begin changing my mind a bit.

What I always loved about Jetpack: that you the team behind it really cares – no doubt about that! :)
Keep on rocking!

Dave from Germany :)

Just what I was looking for. I hated having to connect my local test site to wordpress.com just to try features. Thanks again!!!

Joan says:

Amazing, it’ll save me so much time!

Mark Hedley says:

I have avoided Jetpack in the past but with these hints will have to revisit it. Although I do agree with @Thomas and an admin interface would be very useful.

Dom Atreides says:

Thanks for the post – That is sooooooo useful

How does one “Look under the hood” and why can’t jetpack come with these options in the settings page? The auto enabled plugins that come with Jetpack are a BIG waste of time and can conflict with other plugins already installed. I always install Manual Control for Jetpack to control the worst of its bad behaviour. Some of the Jetpack modules are great, but this plugin suite has a long way to go before it becomes truly user friendly.

Jeremy says:

How does one “Look under the hood”

Since Jetpack is open source, you can check the code source in the plugin repository here.

why can’t jetpack come with these options in the settings page?

When developing the Jetpack plugin, we try to respect WordPress’ core philosophy as much as possible. An important principle of WordPress is Decisions, not Options; you can read more about it here. However, and as I demonstrated in this post, there are many different ways to customize Jetpack’s default behaviour to fit your needs. The Manual Control plugin is another good example.

The auto enabled plugins that come with Jetpack can conflict with other plugins already installed

If you find bugs or conflicts with other plugins, feel free to contact us to let us know about it. We’ll be happy to look into it!

kflint2013 says:

Your thoughtful reply and actions may change my mind about Jetpack which I was absolutely going to drop from my next project to avoid bloat. I can’t allow plugins that turn on new untested features. Very cool work and very cool information. Coming from a team who’s plugin checks on every page load to see if it is freaking Xmas it is good word.

Joan says:

Jeremy, the jetpack_get_default_modules filter is not working on 2.5, right?

Jeremy says:

That’s correct. My bad, I forgot that this filter was only added a few weeks ago, and has not been released yet. It will be part of Jetpack 2.6, that should be released later today.

Thanks for the reminder! I guess it’s been too long since the last Jetpack release! :)

Joan says:

Ok, no rush!

This filter will be veeeery helpful indeed!

Thanks again!

[…] 機能の代替プラグイン15個)」や、Jetpack チーム Jeremy Herve の「Customize the list of modules available in Jetpack(Jetpack […]

dan says:

I have Jetpack version 2.5 and in the Carousel, that small “X” in upper left is what I want to change. However, what module do I open to edit it? I want to add this:
close_hint = $(‘Close Slideshow’)
But I’m looking at that warning which says “Making changes to active plugins is not recommended . . . ” Will this discombobulate my efforts? If anyone can assist, please advise….thank you….
PS: I was able to delete the “comments” box completely, with a simple bit of code under all images and did it in APPEARANCE>EDIT CSS so anyone wanting that spicifc line of code, please advise. Any help on enlarging the “X” would be appreciated. . . . .

Jeremy says:

This thread in the WordPress.org support forums should answer your question:
http://wordpress.org/support/topic/jetpack-carousel-close-button-1

As I mentioned there, I’m afraid there is no other solution as it’s not possible to change this value from outside the plugin.

Charles Como says:

Jeremy, I tried your unset example above to try to disable photon, and it removes it from the list of available modules, but it doesn’t doable it. What could I be doing wrong?

I am basically trying to disable photon while uploading an image to Buddypress groups (as it breaks the ability to edit the images).. but I can’t even get your instructions above to even disable photon. I only want to disable it periodically when uploading and editing an images, so the filter will be very useful to me.

Thanks!

Charles

Jeremy says:

A few things to note here:

  • The unset example above hooks into the jetpack_get_available_modules filter: it only changes the list of modules available to be activated. It’s consequently best used for new installations of Jetpack, or plugin updates with new modules. This filter doesn’t deactivate modules, as you wouldn’t want to deactivate a module that might already be in use. To force the deactivation of a module, you can use a code like this one:
    https://gist.github.com/jeherve/7872205
  • When you want to deactivate a specific module from time to time, it might be best not to use any custom code, and use the Deactivate button in the Jetpack menu to deactivate the Photon module, as explained here:
    http://jetpack.me/support/activate-and-deactivate-modules/
  • It seems you’d like Photon not to be applied to specific images in your BuddyPress theme. Deactivating and reactivating Photon won’t help you there. Instead, you’ll need to ask Photon to ignore specific images, as explained in this tutorial:
    http://jetpack.me/2013/05/03/skip-a-image-with-photon/

If that doesn’t help, do not hesitate to post more details about your issue in the WordPress.org support forums. I’ll be happy to take a closer look at it after the holidays!

Charles Como says:

Thanks Jeremy, I appreciate your response and I’ll definitely make further responses over at the WordPress Support forums.

Thanks, and have a happy new year!

Charles

[…] Read about this and more neat Jetpack mastery on CUSTOMIZE THE LIST OF MODULES AVAILABLE IN JETPACK. […]