If you’re making themes, Jetpack allows you to easily add additional functionality to your themes in a consistent way without a lot of overhead — and without accidentally wandering into “plugin territory.” Here at Automattic, more and more of our themes take advantage of Jetpack to implement site logos, featured content sliders, testimonials, portfolios, food menus, and other special functionality.
The trouble is that users don’t always realize they need to activate Jetpack in order to turn on this functionality. With so many installing themes directly from their WordPress dashboards, most users don’t even know where to find a readme file. As a result, we saw tons of confused users posting in the WordPress.org forums, asking how to make their sites look like our demos.
What we needed was a way to easily inform our users that their theme relied on certain Jetpack modules, and help them install or activate them as needed. This would save on support time as well as make our users happy. We also needed a solution that would be easy to add to lots of different themes, without requiring a lot of manual labor.
Enter the Jetpack Dependency Script
We’ve been working on a solution to this problem over the past few months, and we’ve come up with a simple script that helps our users figure out what’s going on. Since starting to use it in our themes, we’ve seen the number of support requests drop substantially.
Since we love open source, we’ve made the code freely available on Github — so you can use it, too!
Give It a Spin
Want to start using it in your themes? Download it from our Github repo, put it somewhere in your theme — I recommend the
inc folder — and include it from your theme’s
functions.php, like so:
* Load plugin enhancement file to display admin notices.
require get_template_directory() . '/inc/plugin-enhancements.php';
You’ll want to replace all instances of
textdomain in the script with your theme’s text domain, since it adds a few new strings. You’ll also want to regenerate your theme’s POT file once that’s done.
How It Works
Here’s how it works in Sela, which uses a Site Logo and the Testimonials custom post type.
If the user doesn’t have Jetpack installed, they’ll see this:
If the user has installed Jetpack, but hasn’t yet activated it:
If the user has installed and activated Jetpack, but hasn’t activated the required modules:
The notifications appear on the user’s dashboard and on the Themes and Plugin pages. The notifications can be dismissed so they don’t annoy users who don’t want to use Jetpack.
What’s Under the Hood?
Since the script is looking for theme support using
current_theme_supports(), themes need to explicitly register support for the Jetpack features they support. Some Jetpack features — like testimonials and portfolios — are available across all themes, and don’t require the theme to explicitly declare support for the feature. Be sure to add theme support for all Jetpack features you intend your theme to make use of. You can declare support like so:
add_theme_support( 'jetpack-portfolio' );
The script checks for theme support first, then checks to see if the required plugins (Jetpack) and modules are activated. It then builds out notifications tailored to the user’s individual situation, so that users are effectively guided through the process of installing and activating the plugin.
Presto! In only 366 lines of code, we have happier support people and happier users. Feel free to use this script in your own themes, or remix it for your own purposes.