Private WordPress plugin repository with automatic updates

I’m probably not the only one who’d like to have my private WordPress plugins auto-update, just like the plugins from the standard repository.

It took some time to figure out the nitty-gritty details, but I now have a setup which works. Not only that, but it should also be adaptable for use by others, with minimal changes.

TL;DR

The short story here is that I have a system of two or three plugins, which combined will do the trick.

The back-end is a WordPress site, with a custom plugin to do the hidden back-end stuff. The plugin is ~1000 lines of code. There’s a new post type, a taxonomy, a number of new end-points, a wp-cli interface and some tools for generating meta-data and readme files from the site content.

WordPress Plugin Site

The front-end is little more than a bit of glue to connect the WordPress Updates API with the back-end. It is less than 200 lines of code. It does basic search, installation and activation from the search result, manual updates from the updates page and the plugin list, pop-ups with plugin details, and automatic unattended updates.

RS Updater

Due to the way I write my plugins, both of the above rely on a small framework plugin, which must be installed first.

RS Base Plugin

That’s it!

The Updates API

The WordPress Updates API has been around for a while, but the documentation is a bit diffuse.

I found some small examples, and read the source, and the error logs 🙂

On the client side it is basically a matter of adding a few hooks, which either intercepts the communication between WordPress and the standard repository, or short circuits it.

All data structures are just what the standard plugin repository does, but curl’s your friend.

Setup your own repository

To have your own WordPress plugin repository with automatic updates, first make a blank site, then install the RS Base Plugin first, and then the WordPress Plugin Site.

Create a download folder in the document root. This is where you dump your ZIP files with versions of your plugins. How you get them there is your business — I use scp(1).

Now, for each plugin create a page in the Plugins section (that’s a custom post type). Make sure the slug matches the files you’ve uploaded and the slug of your plugin.

Most of the meta-data for the plugin comes from what you enter on the plugin page on the back-end. All the details about which information comes from where is on the back-end plugin page.

That’s about it. You have a plugin repository.

On the client side site

On the client site you need to install the RS Base Plugin and then the RS Updater plugins.

In the latter, either edit the source to change the URL of the back-end, or set the rs_updater_backend option to the URL. There’s no settings page for now, but wp-cli is your friend.

Again, that’s it.

You should be able to find your plugins (by slug only currently), and install, activate and update them. On the plugins list it should be possible to enable automatic updates.

At this point whenever you have a new version of one of your plugins, just upload it to the download folder on the back-end and forget about it. All the sites using that plugin will discover it and update it within twelve hours.

No need to hunt around on all your sites (or your clients’ sites) to do manual updates.

Scratching itches

I wrote this to scratch my own itch — too many home spun plugins on too many sites — and I’m quite satisfied with the result because I now have more time to do fun stuff.

If this can scratch somebody else’s itch too, the more the merrier.

Let me know if it’s useful to you.

All three plugins are under the GPLv2.


Comments

One response to “Private WordPress plugin repository with automatic updates”

  1. @plugins You might want to take a peek at Git Updater.

    https://git-updater.com/

Leave a Reply

Your email address will not be published. Required fields are marked *