Try Tuts+ Premium, Get Cash Back!
Intro To TGM Plugin Activation Class For WordPress, A Video
videos

Intro To TGM Plugin Activation Class For WordPress, A Video

Looking to “bake” a plugin directly into your WordPress theme? This article will give a brief introduction on how to integrate the TGM Plugin Activation class with your WordPress theme, which essentially allows us to include a plugin with our WordPress theme upon activation.


Plugin, Meet Theme. Theme, Meet Plugin

There are lots of cases where you might want to include a WordPress plugin with a WordPress theme. Take contact forms for instance… it’s often a huge help if you can provide a pre-styled set of CSS rules for a particular contact form plugin right inside your theme. The problem is, doing this usually requires telling your theme users to grab the plugin themselves… which isn’t really a great system.

If you’ve ever tried to manually include a plugin with a theme, you’ll know that there’s one central problem: It requires you to A) copy that entire plugin to your theme and B) update the plugin folder manually each time an update becomes available.

There are lots of issues with this (we won’t go into the ethical stuff)… but let’s just look at one problem: it’s a horrible workflow. If you have, say, 30 themes that you’ve worked on in the past year and you’ve used 3 plugins on each one, you need to manually update 90 plugins by copying/pasting the plugin folders to your theme folder. Not cool. Not cool at all.

This class will revolutionize how plugins can be handled for WordPress themes. By using classes that are utilized within WordPress, the TGM_Plugin_Activation class can automatically install and activate multiple plugins that are either pre-packaged with a theme or downloaded from the WordPress Plugin Repository.

This has a variety of great and wonderful implications… but for our example above, it means that you no longer need to worry about manually updating plugins. You can simply visit each site, hit “update” on each plugin and you’re good to go. It’s still a fair bit of work, but it’s a lot less hairy than how we used to do it in the olden days (and by that, I mean last month).

Expand this example to themes that are distributed on a wide-spread basis (like from ThemeForest or the WP theme directory) and you can see that this is a much, much bigger deal than a neat little workflow trick; It is, as Thomas Griffin suggests, revolutionary.


The Screencast

TGM Plugin Activation Class

The TGM Plugin Activation class allows you to package plugins for installation with your WordPress theme, including directly from the WordPress.org plugin repository. Japh, our Envato WordPress Evangelist, has recorded a great little video explaining how to use it.

If you didn’t catch the link already, you can download the class from Thomas Griffin’s GitHub page and start playing around with this yourself.

Oh, and this goes without saying, but thanks for Thomas and Gary for taking on this problem!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.blog.mpcreation.pl Mpc

    Nice, two days ago I was asking about this on TF forums :) Thanks!!

    • http://wp.envato.com/ Japh
      Author

      Great! Hope you find this useful!

      I saw your forum post, and had made this video already, so I was going to link it to you when it was published ;)

      • Brandon Jones

        Great work on the quick video response Japh!

  • Bronwyn

    What timing, had been searching for a couple of days for a tutorial along these lines regarding integration of plugins to themes and this suddenly popped up.

    Very useful, thank you! :-)

  • GaryJ

    Hi Japh,

    Thanks for taking the time to review the code for TGMPA and do a video on how to implement it within a theme. In terms of how we envisaged it, you’ve got it pretty much spot on.

    Thomas and I still have a few issues we think need addressing, and we’re open to suggestions for how theme developers and administrators might want to make use of the code, and what we can improve to make those tasks easier to do.

    Suggestions, bug reports and progress on the project can all be found at https://github.com/thomasgriffin/TGM-Plugin-Activation

    • Brandon Jones

      Thanks Gary! I’ll need to formally drop by the Github page and add some of my own ideas, but as Thomas mentioned below, the auto-activation is HUGE in terms of removing that one extra step for theme users. I’m personally going to be including this in all of my themes over the next week or two, as it goes hand in hand with Theme Options plugins like OptionTree ;)

  • http://thomasgriffinmedia.com/ Thomas Griffin

    Hey Japh! Thanks for posting the video tutorial! It’s good to know that we weren’t the only ones that thought that this class might be beneficial for the community. You’ve done a great job at going over everything in the video! I echo what Gary says about suggestions and such – please feel free to contribute there. :)

    As far as the ‘required’ parameter for plugins, this feature has been added in dev and will be pushed out when 2.1 becomes available and stable. Also in 2.1 will be the automatic install feature (so no need to click the Activate Plugin link). :)

    Thanks again for pushing this out into the community! We hope it grabs traction and becomes a powerful tool for theme developers.

    • Brandon Jones

      That’s great to hear Thomas! I’m actually surprised (hindsight is 20/20) that it’s taken the community this long to really come up with a solution to this. Themes and plugins are what make WordPress WordPress… the fact that they haven’t had a way to really pair up with each other yet is just confounding. I’m sure you guys have lots of ideas for improvements, but the fact that you’re taking this on at all is a breath of fresh air! I can’t wait to remove my “recommended plugins” section from my theme documentation files.

    • http://wp.envato.com/ Japh
      Author

      Hey Thomas & Gary! My pleasure, thank YOU for developing this class!

      It really is fantastic and as Brandon said, kind of amazing that it’s taken this long for someone to build it. So I’m grateful to you guys for doing it, and so well.

      Implementation of the ‘required’ parameter, auto-install, and dismissable admin notices will really set this off too. Looking forward to playing with the release of 2.1 :)

      I’ll definitely be using this class in future theme development, and because you’ve released it on GitHub, I can always contribute back myself too!

      Thanks again

    • http://thomasgriffinmedia.com/ Thomas Griffin

      Just as an update to this, version 2.1.0 has just shipped and really makes this class shine. It now features true automatic plugin activation after installation, dismissable notices, consolidated messages, linked repo plugin info and more. :) Thanks again for covering it here! I’m hoping that this release will really start to make some noise because it adds features that makes this class very powerful for both the theme authors and users.

      • http://wp.envato.com/ Japh
        Author

        Great work, Thomas! I’ve tested the new version, and with no additional changes required in my theme other than updating the class file, everything works well.

        The notifications are now much better formatted, consolidated into one, and dismissable. Along with other updates mentioned in the changelog on GitHub.

  • http://webmastersintexas.com Jerry Lee

    Quite sweet. I believe this is going to make a huge difference in my workflow! Thanks, see ya at GIT!

  • http://coderbay.com coderbay

    very informative and good stuff. thanks

  • Pingback: Jekyll, jQuery, Mobile Apps, Stripe, and More - Tom McFarlin