I declared an action for a single event in WordPress which accepts an array as an argument:
$asins = array(); //I had to declare this since I'm getting a notice of undefined variable if I don't
add_action('z_purge_products_cache', array($this, 'purge_products_cache', $asins));
I also tried this one, but it doesn’t perform the action either:
add_action('z_purge_products_cache', array($this, 'purge_products_cache'));
Then I schedule it:
wp_schedule_single_event(time() + 20, 'z_purge_products_cache', $asins_r);
Then here’s the function that will be called once wp cron executes the action:
public function purge_products_cache($asins){
//send email here
}
Any ideas?
The parameter needs to be passed to the callback function in the wp_schedule_single_event function, not the add_action function.
Try this:
Then schedule the event, putting the parameter in an array:
Your
purge_products_cache
function will be called with parameter$asins_r
.Passing Argument in add_action() just see the following example ,
Brief explanation about add_action() is here.