Announce a migration before it runs
benecaster_migration_import_started fires once when a Migration Wizard import opens, before the first row of the CSV is read. This recipe uses it to email the site owner, so nobody is surprised by a burst of new accounts on the Subscribers screen.
It fires once per import, not once per row. At that moment no patron row, WordPress account or feed token exists yet. The import’s own record is already written, so its tier mapping, options and grace-period end are settled.
$batch_id is the import’s ID. The batch and the import are the same record in benecaster_migration_imports; there is no separate batch identifier to look for.
It does not fire when nothing was started: when the import record could not be created, or when Benecaster is too old for the Migration Wizard and the import is refused.
Pausing something until the import is done? Resume it on benecaster_migration_import_complete, but give the pause its own expiry too. The two hooks are not a guaranteed pair: a fatal error part-way through an import fires this one and never the closer, which would leave whatever you paused paused for good.
Code
<?php
// Tell the site owner the moment a migration opens, so nobody is surprised
// by a burst of new accounts on the Subscribers screen.
add_action(
'benecaster_migration_import_started',
static function ( int $show_id, string $platform, int $batch_id ): void {
// get_the_title() returns HTML (Dave’s Q&A); this is plain text.
$show = html_entity_decode( get_the_title( $show_id ), ENT_QUOTES, 'UTF-8' );
wp_mail(
get_option( 'admin_email' ),
sprintf( 'Migration started: %s', $show ),
sprintf(
"A %s migration (import #%d) has just started for %s.\n\nSubscribers are being imported now.",
ucfirst( $platform ),
$batch_id,
$show
)
);
},
10,
3
);
Hooks Used
Need this built rather than just documented? See our services →