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 migration import, broadcast, or similar batch record — and a type string.
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 or broadcast 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 (migration import ID, broadcast ID, etc.) |
$type |
string |
— | Email type string for the completed job (e.g. 'migration', 'broadcast') |
Examples
Record migration email completion
add_action( 'benecaster_email_queue_job_complete', function ( int $related_id, string $type ): void {
if ( 'migration' !== $type ) {
return;
}
// Track completion in your own add-on's storage, keyed by the import ID.
update_option( "my_addon_migration_emails_complete_{$related_id}", time() );
}, 10, 2 );
Notify Slack on broadcast complete
add_action( 'benecaster_email_queue_job_complete', function ( int $related_id, string $type ): void {
if ( 'broadcast' !== $type ) {
return;
}
wp_remote_post( MY_SLACK_WEBHOOK_URL, [
'body' => wp_json_encode( [
'text' => sprintf( 'Broadcast #%d email job complete.', $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 count by status after this hook fires.
Need this built rather than just documented? See our services →