Docs

Run code after import completes

The following code snippet hooks into the event handler and listens for the import_shutdown event, then if the import has the complete status the code will be ran.

<?php

/**
 * Run code after import completes
 * 
 * @param ImportWP\Common\Model\ImporterModel $importer_model
 * @return ImportWP\Common\Model\ImporterModel 
 */
function iwpe01_on_import_shutdown($importer_model)
{
    $state = ImportWP\Common\Importer\State\ImporterState::get_state($importer_model->getId());
    if ($state['status'] != 'complete') {
        return $importer_model;
    }

    // TODO: Add code to be ran when an import is complete

    return $importer_model;
}

add_action('iwp/register_events', function ($event_handler) {

    /**
     * @var EventHandler $event_handler
     */
    $event_handler->listen('importer_manager.import_shutdown', 'iwpe01_on_import_shutdown');
});