I'm coding a plugin which probably will have updates in the future, and I want to take advantage of the automatic update mechanism in wordpress.
I followed this tutorial:
Everything seemed quite straightforward to me, but for some reason, nothing works. The function hooked to the pre_set_site_transient_update_plugins
filter never gets called.
I tried to go step by step and just added a "Hello" and a log line on that hook. It simply doesn't get called, even when I tried to force the update checks.
Is there any catch on that? Btw, I'm trying that on a multisite installation.
Any help would be greatly appreciated.
Arnaldo
UPDATE: I got the function hooked to the pre_set_site_transient_update_plugins
to be called. Strangely, if I do the hooking inside the constructor of the object which has the checking function it works, otherwise, it doesn't.
Example (this works):
class XYZ {
public function __construct() {
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
}
public function check_update($transient) {
// logic here
}
}
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. 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? 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? If it is, how can I check the whole solution without suffering for several hours to be able to test my latest changes?
Thanks again, Arnaldo
UPDATE 2: @kaiser, the behavior is exactly as I described, even using a static method. I had tried that already.
public static function check_update()
.