Adds an event to the Groundhogg event queue for processing on the next cron run. This is the low-level function behind send_email_notification() and all funnel step scheduling. The most important keys in $args are time (Unix timestamp), contact_id, step_id, funnel_id (use 0 for standalone events), event_type, and status.
Parameters
| Parameter | Type | Description |
|---|---|---|
$args | array | Event arguments. Required keys: contact_id, step_id, event_type. Optional: time (defaults to now), funnel_id (defaults to 0), status (defaults to Event::WAITING). |
Return value
Event_Queue_Item|false — The queued event item on success, or false on failure.
Usage
use Groundhogg\Event;
\Groundhogg\enqueue_event( [
'time' => strtotime( '+1 day' ),
'funnel_id' => 0,
'step_id' => MY_EMAIL_ID,
'contact_id' => $contact->get_id(),
'event_type' => Event::EMAIL_NOTIFICATION,
'status' => Event::WAITING,
] );
Example
Here’s a pseudo code example for a hypothetical drip sequence integration.
add_action( 'my_plugin_trial_started', 'my_plugin_queue_trial_drip' );
/**
* Queue a series of drip emails when a trial starts.
*
* @param string $email
*
* @return void
*/
function my_plugin_queue_trial_drip( $email ) {
$contact = \Groundhogg\get_contactdata( $email );
if ( ! $contact ) {
return;
}
$schedule = [
[ 'email_id' => MY_DAY_1_EMAIL_ID, 'delay' => DAY_IN_SECONDS ],
[ 'email_id' => MY_DAY_3_EMAIL_ID, 'delay' => 3 * DAY_IN_SECONDS ],
[ 'email_id' => MY_DAY_7_EMAIL_ID, 'delay' => 7 * DAY_IN_SECONDS ],
];
foreach ( $schedule as $item ) {
\Groundhogg\enqueue_event( [
'time' => time() + $item['delay'],
'funnel_id' => 0,
'step_id' => $item['email_id'],
'contact_id' => $contact->get_id(),
'event_type' => \Groundhogg\Event::EMAIL_NOTIFICATION,
'status' => \Groundhogg\Event::WAITING,
] );
}
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
