The following code is part of a save_post
action. It works as expected in my local dev environment, but doesn't work reliably on a hosted server. (By unreliably I mean it sometimes work, but without any regularity I can deduce.)
if (wp_next_scheduled('my_expiration_hook', [$post_id])) {
my_log('unscheduling all for post ' . $post_id);
wp_clear_scheduled_hook('my_expiration_hook', [$post_id]);
}
if ($today < $expire) {
my_log('scheduling ' . $post_id . ' with date ' . $expire);
wp_schedule_single_event(strtotime($expire), 'my_expiration_hook', [$post_id]);
}
Everything logs correctly, but it is as if the wp_clear_scheduled_hook
and wp_schedule_single_event
calls never occur.
I am using WP Crontrol plugin to check the schedule. Manually modifying the schedule with this plugin works as expected.
Am I missing something or is this a hosting issue? Thanks!
The following code is part of a save_post
action. It works as expected in my local dev environment, but doesn't work reliably on a hosted server. (By unreliably I mean it sometimes work, but without any regularity I can deduce.)
if (wp_next_scheduled('my_expiration_hook', [$post_id])) {
my_log('unscheduling all for post ' . $post_id);
wp_clear_scheduled_hook('my_expiration_hook', [$post_id]);
}
if ($today < $expire) {
my_log('scheduling ' . $post_id . ' with date ' . $expire);
wp_schedule_single_event(strtotime($expire), 'my_expiration_hook', [$post_id]);
}
Everything logs correctly, but it is as if the wp_clear_scheduled_hook
and wp_schedule_single_event
calls never occur.
I am using WP Crontrol plugin to check the schedule. Manually modifying the schedule with this plugin works as expected.
Am I missing something or is this a hosting issue? Thanks!
Share Improve this question edited Jan 26, 2022 at 21:09 noos asked Jan 26, 2022 at 21:02 noosnoos 11 bronze badge1 Answer
Reset to default 1Most hosts modify how the default cron works and I've specifically had issues with GoDaddy managed hosting as they 100% take control and you can't do anything about it.
If it works locally, I would contact the hosting company and ask about how crons are setup to run. If its Managed GoDaddy there isn't anything you can do but to change hosts. I fought them for 3 months before the client finally agreed.
Another thing to look out for is object caching, I've seen it cause some issues as well.