Yes, You Can: Plugin Auto-Updates From Github

Yes, You Can: Plugin Auto-Updates From Github

It's been a question that has puzzled WordPress plugin developers from centuries - can you auto-update plugins from Github? The answer is in: yes, you can. Nuno takes a look at how it's done.

One of the things I love about WordPress is the plugin architecture, as it allows users to contribute and extend WordPress without compromising the sanity and clarity of its core.

Whenever I write a plugin I tend to submit it to the official plugin repo, where it can quickly be downloaded  and used by thousands of savvy users. I also often host my plugins on GitHub too; either because I’m still developing them and I’m not quite ready to release them to the world or simply because it might be a client-specific or commercial plugin. In those cases I always feel shorthanded when I see other plugins receive new update notifications and the ones on GitHub have to be updated manually.

However, with some recent code by Joachim Kudish, pushing new releases of these plugins on GitHub has become a lot easier, as it allows me to seamlessly combine official plugins with commercial ones and to update them in one go. Every time I decide to release a new version, I just need to tag the release and the plugin will get a “new release available” message on the user’s admin panel. I have tried it out and it’s fairly easy to setup.

It’s available via a class we must include in the plugin to support GitHub updates. Download it and put the updater.php (source) into the plugin directory that you will want to auto update and make sure that the plugin includes the file:

include_once('updater.php');

The next step is to initialize the class. You can do this by adding:

In your Github repository, you will need to include the following line (formatted exactly like this) anywhere in your Readme file:

~Current Version:1.0~

You will need to increment the version number whenever you update the plugin, as this will ultimately let the plugin know that a new version is available. Once the plugin finds it has an update, it downloads a zip file from GitHub, eliminating the need for git installed on the server.

It used to be the case where this would only work with GitHub public repositories, but about 4 months ago Paul Clark stepped in and started working on support for private repos through Github oAuth tokens. He says it’s functionally complete and I’ll definitely give it a try (Issue #15).

I’m quite excited with this updater class and I think plugin developers should seriously consider integrating it into their workflow because it makes things a lot easier.

I, for one, know I’ve impressed a few clients already.

WPGitHubUpdater class file Download

Comments

  1. Ooh, I quite like this one. I had already bookmarked a few options like this, but this solutions actually looks like it the easiest way to implement it. Thanks for sharing!

  2. hey,

    Thanks for sharing this :)

    I’ll be making some updates to the class in the future. It needs some code cleanup and a few things can be simplified about it.

    Let me know if there’s anything you’d like to see in there

  3. Nice! I was looking for something like this :) Thanx.

  4. One thing which would put me off this solution for WordPress.org hosted plugin is the fact that any updates from Github will not increase your download count on WordPress.org.

    I’d definitely use this for things hosted outside of WordPress.org though. It looks like a great way to implement this functionality.

    • True about the counters. Thanks for this tip too.

    • The intention of the class isn’t to work with WordPress.org hosted plugins, but instead to replace that system in specific scenarios only. For example, if you have a plugin that was written for a client or there is some other reason that you don’t want to promote it using the WordPress.org repository, you would be able to host it on Github and use the class to provide auto-updates for the users of your plugin.

  5. I was looking for something like this beautiful post thanx guys

Leave a Reply