Automatic updates in plugin – not hosted on wordpress repository

You actually have several questions in there, so I’ll answer them one by one:

However, if I simply do this on my main plugin file, it doesn’t work:

add_filter('pre_set_site_transient_update_plugins', array('XYZ', 'check_update'));

First of all, I’d like to understand what’s the difference between the
two scenarios.

This is failing because you are calling the method statically, instead of on an instance of the class. Since the method isn’t being called on an instance, the class properties aren’t set. So for example, when check_update() tried to use $this->current_version, it will get null. For this reason the function will assume that there is no update available.

Besides that, I had to do

set_site_transient('update_plugins', null);

to force the hook to be called, otherwise I think I’d have to wait the
normal wordpress update check cycle, right?

Yes.

And now, another issue has surfaced: the $transient variable which is
passed to the check_update() function is always null! Is that because
of the set_site_transient() instruction?

Yes, you are setting the transient to null. So, you shouldn’t expect it to be anything but null afterward, unless that failed for some reason.

[H]ow can I check the whole solution without suffering for several hours to be able to test my latest changes?

For testing, change it to hook into get_site_transient_update_plugins instead. That will get called each time the transient is retrieved. You may want to set a static variable or something though, so you don’t call it more than once per page-request.

Leave a Comment