I’m in a dead end with a schedualed task in a wordpress plugin for a multisite. Somehow the action I added don’t get triggered. The task is getting schedualed and returns a timestamp when I run wp_next_scheduled(), but the action itself doesn’t go off and trigger the function.
Information that might give some clues:
- It’s running on a WPMU-site
- The cronjob is a part of a plugin
- I’m using OOP approach
- The things I’m importing is a custom post type.
Code Example:
class Cronjobs
{
function Cronjobs()
{
add_action('init', array(&$this, 'add_cronjobs'));
}
function add_cronjobs()
{
add_action('update_properties_daily', array(&$this, 'do_updates'));
if(!wp_next_scheduled('update_properties_daily') )
{
wp_schedule_event( time(), 'daily', 'update_properties_daily');
}
}
function do_updates()
{
/* Do updates */
}
}
Could really use the help of some wizes on this one, thanks!
UPDATE
Solution: Create a global function and call that from the custom action.
Apparently is there some glitch with creating custom actions while refering to an object. Since custom actions is stored in the DB (as far as I’ve understood), the objected won’t be instansiated and therefor can’t use it’s methods. Therefor: back to basics and use a global function.
You need to call add_action from outside the class, with a reference to the object. Example:
I think you forgot register_activation_hook()
See http://codex.wordpress.org/Function_Reference/wp_schedule_event