Posted by & filed under Developer Blog.

Update

It looks like there is a fully fledged plugin for accomplishing this feat for both plugins and themes. I recommend using it instead of this hack:
https://github.com/jeremyclark13/automatic-theme-plugin-update

The Problem

WordPress PluginsThe biggest appeal WordPress has is it’s extensibility via plugins. But if you create a private plugin for personal use or for a corporation with a very specific purpose, you may not want to go through the process of having it submitted, approved, and available for the world on the WordPress Plugin repository. So what’s wrong with just hosting your plugin .zip file and providing a link for convenient access? One answer: updates.

When a plugin is installed via the official repository, it will automatically make a call back periodically and check for updates. If updates are available, it will alert the user and provide a link to “update automatically.” With a home-grown private plugin, or a plugin kept out of the official repo. for whatever reason, there is no such lookup and link available. Until now!

(Note: In my testing, this only works on Multisite if the plugin is activated for the entire network.)

Don’t You Just Love Open Source?

The wonderful thing about Open Source products like WordPress, is that you can see how things are working, and make your own solutions for issues like the scenario described above. After a lot of tinkering and investigation I came up with a really easy and simple solution with just 3 easy steps.

Step 1: Host an update file.

Create a plain-text file that contains 2 parts. The first part contains the current version number of your plugin, the second part contains the URL of where your plugin .zip file can be downloaded from. Separate these parts from each other using a simple pipe. Like this:

1.2.3|http://www.mycustomrepository.com/plugins/myplugin-1.2.3.zip

Now you need to host this file somewhere accessible by WordPress. My recomendation is to include this file right within your plugin folder prior to compressing it, and host the folder along side your .zip file. So the URL for the update file in our example above might be:

http://www.mycustomrepository.com/plugins/myplugin/myplugin.chk

Notice that I added a .chk extension on the filename. The extension does not matter here, just as long as the file is saved out as plain text. Using .chk just makes it easy to distinguish. It could just as well be .txt or whatever you want.

Step 2: Include update checker

I have developed a php file that contains all of the code necessary to make this work. You can either copy/paste its contents unchanged into your plugin’s main .php file, or I recommend just adding this file to your plugin folder and require it in your code.

Download gill-updates.php

You will also add some code to your plugin referencing the update check file discussed in step 1, and set a quick variable referencing your plugin.

To accomplish all of this, follow this example at the bottom of your plugin php:
//custom updates/upgrades
$this_file = __FILE__;
$update_check = "http://www.mycustomrepository.com/plugins/myplugin/myplugin.chk";
require_once('gill-updates.php');

Step 3: Host your plugin .zip file in the location you specified above

In our case, you would add the myplugin.zip file to the web host so that it will be accessible at the exact location specified in your update check file. For example:

http://www.mycustomrepository.com/plugins/myplugin-1.2.3.zip

What now?

Once you have completed the steps above you are set to allow your plugin to automatically check for updates of itself. All you need to do when you update your plugin, is edit the update file to a new version. Also, make sure the .zip file it points to contains your new version.For example:

2.0|http://www.mycustomrepository.com/plugins/myplugin-2.0.zip

That’s it! The plugin will now compare it’s current version (specified in the meta information of your plugin) to the version listed in the check file. If the check file number is greater than the number in your plugin, it will provide an “update automatically” link as though it were being hosted in the official repository, and when clicked it will update the plugin automatically with the file specified.

Credit

Ainun Nazieb who wrote a similar post on How to Make Your Own Plugins/Themes Updating Service. Ainun’s post claims it will work for plugins, but there wasn’t any specific information to support that claim. It was specifically related to Themes. This post certainly saved me a lot of work and started me on the right path, however.

The image used above was stolen from Smashingmagazine.com