Skip to main content

Read a show’s migration funnel from PHP, including on cron

Premium Intermediate

benecaster_migration_get_funnel( int $show_id ): array answers one entry per migration batch, newest first, in the same eleven keys as the Migration Wizard REST API’s migration read. Use it for anything server-side: a scheduled digest, a CSV or PDF export. The REST route needs an administrator and a nonce, so a cron run cannot call it.

  • [] means nothing to report, and deliberately does not say why. A show the Migration Wizard is not switched on for and a show that has never migrated both answer []. To ask whether the funnel is available at all, test function_exists( 'benecaster_migration_get_funnel' ).
  • It checks no capability, because the caller that matters is a cron run with no user. Your code owns the permission check. Nothing it returns is personal data: counters, dates and a status.
  • Neutralise before writing it into a spreadsheet. sourcePlatform and status come back exactly as stored, so an exporter guards a leading =, +, - or @ itself.
  • All eleven keys are a published contract. A key may be added; none is renamed or removed.
  • Never recompute a figure. totalPending is worked out and never below zero, and completed, dropped and pending are the add-on’s logic. A figure derived from the migration tables would disagree with the Migration tab. importDate and graceEndsAt are ISO-8601 instants or null; read recordsFreeTiers rather than matching on status.
  • It passes through benecaster_migration_dashboard_imports, as the REST read does, so a site that hides a batch hides it here too.

Code

<?php
if ( ! function_exists( 'benecaster_migration_get_funnel' ) ) {
    return; // The Migration Wizard is not installed on this site.
}

foreach ( benecaster_migration_get_funnel( $show_id ) as $batch ) {
    // $batch['totalImported'], ['totalCompleted'], ['totalDropped'], ['totalPending'],
    // ['gracePeriodDays'], ['graceEndsAt'], ['status'], ['recordsFreeTiers'],
    // ['id'], ['sourcePlatform'], ['importDate']
}

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →