I’m developing a wordpress plugin at the moment which I do not want in the WordPress plugin repository. However I still want to be able to push updates to my costumers from my own API repository.
I’ve been reading quite a bit about this, and one thing that seems to be something about is the pre_set_site_transient_update_plugins
filter, however I can’t find much info about this. I’ve tried this tutorial (http://konstruktors.com/blog/wordpress/2538-automatic-updates-for-plugins-and-themes-hosted-outside-wordpress-extend/) which I couldn’t get working. I can tell from the comments that others can actually get this working with what must be almost the current version of WP (latest response Apr 22).
I tried installing the plugin from the site and putting the API folder on a second domain, but the update notification I usually get when an update is available, didn’t show anywhere at all.
I’m not sure if it is actually possible to have custom plugins run the auto-update from other repositories so I would like to hear if anyone in here has any experience at all with this stuff? The solution in the tutorial seemed to be an easy solution – I wonder if it’s somehow possible to do it in a more advanced way?
Any help getting this auto-update from my own repository working would be much appreciated!
(PS: I’m running WP version 3.1.3)
For the benefit of others who find this page, I suggest those wishing to provide their own updates outside the official WP repository check out this project on GitHub, that demonstrates the functionality:
https://github.com/jeremyclark13/automatic-theme-plugin-update
For a single-site install (I haven’t tested it on a multi-site), there are only two hooks you need to update from an external service such as github or gitlab. In the code below, I use gitlab since that’s what I use to host my code right now. I probably should abstract the gitlab parts out…
The first hook you’ll need to use is
pre_set_site_transient_update_themes
. This is the filter that WordPress uses to set the site_transient to show if there are updates available. Use this hook to connect to your remote version and see if there are updates available. If there are, then modify the transient so that WordPress knows there are updates and can show the notice to the user.The other hook you’ll need to use is
upgrader_source_selection
. This filter is needed, for gitlab anyway, because the name of the downloaded folder is not the same as the theme, so we use this hook to rename it to the correct name. If you’re remote repository provides a zip with the correct name, then you don’t even need this hook.The third, optional, hook you can use is
auto_update_theme
if you want to auto update your theme. In the example below, I use this hook to auto update only this specific theme.This code has only been tested with WordPress 4.9.x. It requires PHP > 7.0.
functions.php
updater.php
Yes, this is possible. There’s an entire chapter in Professional WordPress Plugin Development dedicated to this. If you haven’t already, pick up a copy. It will definitely help.
There is this commercial Plugin and Theme Update API manager for WooCommerce that specifically works if the plugin or theme is not hosted on wordpress.org. It is designed to provide updates for self hosted plugins and themes. The plugin is for those who donât want to write it yourself, and need a lot of features, plus working examples for plugins and themes that are being sold.
http://www.toddlahman.com/shop/wordpress-automatic-update-api-manager/
There is also a neat service at http://wp-updates.com/ – you get one theme or plugin for free. FYI – this is not my site but I’ve tried it a while ago and it seemed pretty good.