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:
if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin | |
$config = array( | |
'slug' => plugin_basename(__FILE__), // this is the slug of your plugin | |
'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in | |
'api_url' => 'https://api.github.com/repos/username/repository-name', // the github API url of your github repo | |
'raw_url' => 'https://raw.github.com/username/repository-name/master', // the github raw url of your github repo | |
'github_url' => 'https://github.com/username/repository-name', // the github url of your github repo | |
'zip_url' => 'https://github.com/username/repository-name/zipball/master', // the zip url of the github repo | |
'sslverify' => true // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details | |
'requires' => '3.0', // which version of WordPress does your plugin require? | |
'tested' => '3.3', // which version of WordPress is your plugin tested up to? | |
'readme' => 'README.MD' // which file to use as the readme for the version number | |
); | |
new WPGitHubUpdater($config); | |
} |
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.