benecaster_before_gdpr_purge
Fires once per user immediately before Benecaster deletes that user’s data across all tables. It fires from the nightly retention sweep, from deleting a subscriber by email on the Tools screen, and when a WordPress account is deleted. Tools → Erase Personal Data (the WordPress eraser) does not fire it.
At the point this hook fires, no data has been deleted yet. The cascade that follows deletes the person’s feed tokens, feed request log, download log, email log, queued emails and migration records, anonymises their subscriber events and membership payments, removes them from the sales-tax records, and, on every source except ‘cron’, deletes their episode-purchase records. Use this hook to snapshot or archive user data before the irreversible purge runs. The $email parameter is null in the retention sweep, and when a deleted account had no email — guard against null before using it.
On ‘account_deleted’ the WordPress account is already gone, and the person’s tokens were revoked (reason account_deleted) just before this fires.
To skip the purge for a specific user entirely, use benecaster_gdpr_purge_skip.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$source |
string |
— | Origin of the purge: 'cron' (the nightly retention sweep), 'manual' (a subscriber deleted by email from the Tools screen, `POST /tools/gdpr/delete-subscriber`) or 'account_deleted' (the person's WordPress account was deleted). |
$user_id |
int |
— | WordPress user ID being purged; 0 on 'manual' when no WordPress account has that email |
$email |
?string |
— | Email address being purged; null on 'cron', and on 'account_deleted' when the account had no email |
Examples
Archive download history before erasure
add_action( 'benecaster_before_gdpr_purge', function ( string $source, int $user_id, ?string $email ): void {
$history = my_plugin_fetch_download_history( $user_id );
if ( ! empty( $history ) ) {
my_plugin_archive_to_external( $user_id, $history, $source );
}
}, 10, 3 );
Notes
This action fires only after the benecaster_gdpr_purge_skip filter returns false. Users that are skipped do not trigger this hook.
Need this built rather than just documented? See our services →