WordPress cron hooks – same callback for completely different action?

No, not quite.

When you say this:

wp_schedule_single_event( $sent_on, 'my_custom_cron', [ $notif_id, $notif_name, $membership_id, $lesson_id ] );

You are essentially saying is when the current time passes $sent_on, do:

do_action( 'my_custom_cron', [ $notif_id, $notif_name, $membership_id, $lesson_id ] );

Cron jobs are just a TODO note to fire an action with some arguments in the future. That’s all they are, the action works exactly the same as any other action/hook.

So:

But what happens if I have multiple lessons and multiple events I want to use for email triggers, all with various dates?

Then you’ll have multiple scheduled cron jobs with different arguments.

It will only send emails for all lessons if you built a function that sends emails for all lessons and added it to that hook. That’s an extremely obvious and deliberate thing to do, I think you would know if you had done that due to the special effort needed to fetch all lessons and send emails.

As mentioned, I might have lesson_started and lesson_webinar_started event for various lessons. So will my current approach work, or will various events for various lessons all triggered at different times, all using my one cron hook’s logic, interfere with one another?

Did you build them to interfere with eachother? If so yes! If not then no.


If you schedule a cron job 5 times for a hook, that hook will be fired 5 times. If you give it different arguments each time, the hook will fire with different arguments each time. It’s a queue. I understand the anxiety and uncertainty around this but a little investigation and common sense reveals it’s unfounded. Likewise some quick tests would demonstrate it’s not the case.

The one thing that I will point out though is the wp_clear_scheduled_hook call, it doesn’t make sense. It’s like declaring you will not go to the store on Monday just after you get home from the store. The cron job has already fired, it’s too late, and it’s a non-repeating one time single cron job so there’s nothing to clear in the future.

That entire loop makes no sense, that’s not how wp_schedule_single_event works, it would match the first time then there’d be nothing on the follow up iterations of the loop as you’ve already cleared it. wp_schedule_single_event schedules a single event, not a repeating event.