Easy way to automatically update commercial WordPress plug-ins

Update notification for a commercial plug-in

WordPress CMS has a nice auto update feature that displays update notifications for outdated plug-ins and themes in admin panel. Once you got a notification you can go to Dashboard->Updates and install all updates with few clicks while WordPress will automatically download and extract archives, remove old versions and reactivate plug-ins for you.

The only problem is  that it works for plug-ins published on wordpress.org which are open-source so it’s not an option for commercial plug-ins.

Luckily there is a very good solution to this problem: Upgrademe plug-in.

Users of most commercial Wordspress plug-ins suffer from painful manual update process which includes deactivation of the plug-in, deleting it, uploading new code and finally activating it. And obviously they do not get update notifications for commercial plug-in directly to their admin panels. This also applies to free plug-ins that aren’t hosted on wordpress.org for some reason.

Some commercial plug-ins have their own automatic update feature that shows notifications similar to notifications of WordPress auto-update system and some vendors provide their own auto-update plug-ins which are capable of updating their own products. Still their homemade code is limited and not so good and reliable as built-in WordPress update system.

I wish WordPress developers add a way to extend built-in update system with custom information sources but it seems they’re not willing to do so for some reasons.
Well, while there is no “official” way, some hacks are still available and Upgrademe plug-in just uses one of them (and I have to say it does it in a very smart way!).

Once installed on WordPress blog this little plug-in will hack into every WordPress request for fresh update information and add custom data gathered from other sources.  Nothing more! All the  job of displaying update notifications, downloading and installing updates is done by WordPress auto-update subsystem just like it does for any plug-in hosted on wordpress.org.

Enabling auto-updates in your commercial plug-in is extremely easy:

  1. Add this small function to the end of your main plug-in file:
    function <plugin_name>_upgrademe()
    {
        return 'http://yoursite.com/latest-version.php';
    }
    
    • Replace <plugin_name> with your main plug-in name w/o extension.
    • Replace http://yoursite.com/latest-version.php with actual URL that will provide JSON data with lates version info. It could be simply static file that you update manually or a script that cooks that data dynamically.
  2. Upload latest version script or static file to the URL provided by the function. See https://github.com/meglio/wp-upgrademe for more info on the JSON structure required.
  3. Deliver your plug-in along with the Upgrademe plug-in to your users and ask them to install and activate Upgrademe plug-in to get automatic updates.
Update notifications in admin menus
All natural: update notifications are coming from WordPress built-in update system

There are many benefits of using Upgrademe plug-in but there are also few problems that I believe will be fixed with further development of this great plug-in.

Pros

1. Reliable and forward compatible solution as it is based on usage of built-in WordPress auto-update subsystem.

2. Very small  modification to your plug-in code required.

3. One plug-in could serve update information for multiple plug-ins from various vendors.

Cons

1. Theme update not supported yet. While I see no problem in adding it. It just needs some research and development work.

2. If you install many update-enabled plug-ins on he same blog you may periodically notice a slowdown. It is caused by the Upgrademe plug-in calling all the latest version info URLs for those plug-ins. It would be better if this requests could be scattered over time.

3. You have to deliver Upgrademe plug-in to the end-user and make him/her activate it along with your plug-in.

How it works

Once everything is set up and there is new version available the user will see update notifications for your plug-in like those shown on images above. In fact, those notifications are produced by core WordPress code so if WordPress developers decide to change something in a way they are displayed, you have nothing to worry about.

To notify users about the update upload new version archive to your server and modify JSON version info accordingly. Note that WordPress caches version information for 12 hours so you’ll not see the notifications immediately.  For testing purposes you can delete ‘_site_transient_update_plugins’ option from options table and refresh any page in WordPress admin. This will force WordPress to request update information.

Finally, when the users decides to update the plug-in, WordPress automatically downloads and installs it in the same way as it does for for plug-in hosted on wordpress.org:

Update process log

As we wanted to avoid manual work as much as possible, we developed a small script that servers update info for all our plug-ins. The script takes plug-in name from URL query parameter and responds with version number it takes from filename of plug-in’s archive . So all we have to do now is uploading plug-in archives named  like <plug-in name>.<version>.zip to the server and that automatically fires update notification to end-users. That easy!

That’s it, with a help of Upgradme plug-in you can easily add great auto-update feature to your commercial WordPress plug-in.

Leave a Comment