11 hours ago on May 19, 2026 at 6:19 pm
When I select the scheduled import and click the “get latest file” it does not actually get the latest file.
it uses the one that is cached – when I run the regular import when it is checked as well it does not get the latest stuff — I have a webhook that calls some of your extra code to fix it when I am forcing it to run on my own – but it would be nice to use your scheduler and not have to call my own code to ensure the file is overwritten – I have this code that I use to make sure the import gets the new stuff
// ── Trigger Import WP via Container ──────────────────────────────────────────
try {
if ( ! class_exists( ‘ImportWP\Container’ ) ) {
throw new Exception( ‘ImportWP\Container class not found — is the plugin active?’ );
}
$container = \ImportWP\Container::getInstance();
$importer_manager = $container->get( ‘importer_manager’ );
if ( ! $importer_manager ) {
throw new Exception( ‘importer_manager service not found in container’ );
}
// Set the current user to the one configured on the importer
$importer_manager->set_current_user( $importer_id );
// ── Force Import WP to re-fetch our CSV before running ───────────────
// Import WP has two hooks we use here:
//
// iwp/importer/run_fetch_file — forces a file fetch at import start
// iwp/importer/datasource/local — overrides the local source path
//
// Together these tell Import WP to always grab our freshly deployed CSV
// regardless of what datasource is configured on the importer settings.
add_filter( ‘iwp/importer/run_fetch_file’, function() {
return true;
} );
add_filter( ‘iwp/importer/datasource/local’, function( $source, $raw_source, $importer_data ) use ( $csv_path ) {
error_log( ‘[PivotDoor Webhook] Overriding datasource path to: ‘ . $csv_path );
return $csv_path;
}, 10, 3 );
// Also handle remote datasource type in case the importer is set to remote
add_filter( ‘iwp/importer/datasource/remote’, function( $source, $raw_source, $importer_data ) use ( $csv_path ) {
error_log( ‘[PivotDoor Webhook] Overriding remote datasource path to: ‘ . $csv_path );
return $csv_path;
}, 10, 3 );
// ── Clear stale session state before running ─────────────────────────
// Import WP stores session state in a WordPress option. If a previous
// session ID is still stored there, import() will throw “Session has
// changed” and return the cached result instead of starting fresh.
// Deleting the option forces import() to initialise a new clean session.
$state_option = ‘iwp_importer_state_’ . $importer_id;
delete_option( $state_option );
error_log( ‘[PivotDoor Webhook] Cleared stale session state for importer #’ . $importer_id );
// Run the import
$result = $importer_manager->import( $importer_id, get_current_user_id() );
$status = isset( $result[‘status’] ) ? $result[‘status’] : ‘unknown’;
Thanks
Heather