benecaster_email_queue_job_complete
Fires when all rows in an email queue job group reach a terminal status (sent or failed). A job group is identified by a related_id — an integer foreign key to a batch record such as a Migration Wizard import — and the exact email type of its rows, for example migration_welcome. One import that queues several email types therefore completes once per type.
This action fires at the end of the same WP-Cron tick that processes the final row in the group. It is not fired for one-off transactional emails, which have related_id = 0 and are never grouped. Use it to update a migration status record, send admin completion notifications, or trigger downstream workflows once all emails in a batch have been processed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$related_id |
int |
— | ID of the job group (for a Migration Wizard job, the import ID) |
$type |
string |
— | The exact email type of the job's rows (e.g. 'migration_welcome'). Never a family name such as 'migration' |
Examples
Record when each migration email batch finishes
add_action( 'benecaster_email_queue_job_complete', function ( int $related_id, string $type ): void {
// Each migration email type completes on its own: migration_welcome, migration_reminder, …
if ( ! str_starts_with( $type, 'migration_' ) ) {
return;
}
// Track completion in your own storage, keyed by the import ID and the email type.
update_option( "my_addon_{$type}_complete_{$related_id}", time() );
}, 10, 2 );
Notify Slack when an import's welcome emails have all gone out
add_action( 'benecaster_email_queue_job_complete', function ( int $related_id, string $type ): void {
if ( 'migration_welcome' !== $type ) {
return;
}
wp_remote_post( MY_SLACK_WEBHOOK_URL, [
'body' => wp_json_encode( [
'text' => sprintf( 'Migration import #%d: welcome emails finished sending.', $related_id ),
] ),
'headers' => [ 'Content-Type' => 'application/json' ],
] );
}, 10, 2 );
Notes
A job group that completes with mixed results (some sent, some failed) also fires this action — there is no separate hook for partial failure. If you need to distinguish a fully successful batch from one with failures, query the queue table for rows with related_id = $related_id and email_type = $type, and count by status after this hook fires.
Need this built rather than just documented? See our services →