Scheduling an event inside plugin class is not working
wp_schedule_single_event
is not firing.
I wrote a function that is posting to external API, if it failed I schedule the same posting function to run 5 seconds later in cases of timeouts.
Here's the simplified code of the function:
class MyPlugin {
public function post( $fields, $type ) {
// Posting to external API logic, if it failed I schedule the same function to run in 5 seconds.
wp_schedule_single_event( time() + 5, 'post', array( $fields, $type ) );
return;
}
}
I assumed that the post
function is simply not found so when the time comes for that function to run, nothing happens, so I tried to use:
wp_schedule_single_event( time() + 5, MyPlugin-post(), array( $fields, $type ) );
OR
wp_schedule_single_event( time() + 5, 'MyPlugin-post', array( $fields, $type ) );
Nothing seems to work! How can I get the same function to run with the same accepted args, 5 seconds after it failed?
Thanks!
Topic wp-cron php plugin-development Wordpress
Category Web