Email the podcaster when an episode import finishes
Tell the site owner how a one-time episode import went, since it can still be running after they leave the setup wizard. The import runs in the background and a large back catalogue takes minutes, so the podcaster has often clicked Continue before it ends. This sends a summary either way — success or failure — from benecaster_bulk_import_completed.
Always branch on $progress['status']. The hook fires for failures too, and error_msg exists only on a failed run. A callback that assumes success emails “0 of 0 episodes imported” when the URL was wrong.
For a notification per episode rather than per run, use benecaster_episode_imported. For Feed Sync runs, use benecaster_feed_sync_completed; this hook never fires for them.
Code
<?php
add_action( 'benecaster_bulk_import_completed', function ( int $show_id, array $progress, string $job_id, string $feed_url ): void {
$show = get_the_title( $show_id );
if ( 'failed' === $progress['status'] ) {
wp_mail(
get_option( 'admin_email' ),
sprintf( 'Episode import for %s failed', $show ),
sprintf( "The import from %s stopped: %s", $feed_url, $progress['error_msg'] ?? 'unknown error' )
);
return;
}
wp_mail(
get_option( 'admin_email' ),
sprintf( 'Episode import for %s finished', $show ),
sprintf(
"%d of %d episodes were imported as drafts (%d were already there, %d could not be created).\nReview them in Benecaster → Episodes.",
$progress['imported'],
$progress['total'],
$progress['skipped'],
$progress['errors']
)
);
}, 10, 4 );
Hooks Used
Need this built rather than just documented? See our services →