benecaster_after_export
Fires after the XLSX export file is written to the exports directory, before the download response is sent to the browser. The file path points to a complete, valid XLSX file that persists in wp-content/uploads/benecaster/exports/ — it is not a temporary file and is not deleted after the download. It is deleted eventually, though. Export files are removed once they pass a time-to-live, 7 days by default. Change it with the benecaster_export_ttl_days filter or the BENECASTER_EXPORT_TTL_DAYS constant; a resolved value of 0 or less disables auto-deletion entirely and keeps exports forever. That matters if you use this hook to copy the file somewhere — to S3, a backup, a compliance archive. Do the copy inside your callback rather than storing the path and reading it later, because the path will stop resolving. There is currently no hook fired around the deletion itself, so nothing notifies you when a file goes.
Use this hook for audit logging, archiving the file to external storage such as S3, or indexing the export in a third-party system. The file continues to be available for download via the download endpoint after this hook fires.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$file_path |
string |
— | Absolute path to the generated XLSX file (temporary, deleted after download response) |
$sheets |
array |
— | The sheets included in this export |
$context |
array |
— | Export context: {show_id: int|null, date_start: string, date_end: string} |
Examples
Archive export file to S3
add_action( 'benecaster_after_export', function ( string $file_path, array $sheets, array $context ): void {
// Send the export file to S3 for long-term audit retention
if ( ! my_plugin_s3_is_configured() ) {
return;
}
my_plugin_s3_upload(
$file_path,
'podcast-exports/' . gmdate( 'Y/m/' ) . basename( $file_path )
);
}, 10, 3 );
Notes
The file at $file_path persists in the uploads directory after the download completes — it is not automatically deleted. An older version of this documentation incorrectly described it as a temporary file deleted after the download response; that is not the case.
Need this built rather than just documented? See our services →