benecaster_before_gdpr_purge
Fires once per user immediately before Benecaster deletes that user’s data across all tables. This fires from both the nightly scheduled retention job and the manual right-to-erasure path.
At the point this hook fires, no data has been deleted yet. The deletion cascade that follows removes rows from the tokens, download log, email log, and migration tables. Use this hook to snapshot or archive user data before the irreversible purge runs. The $email parameter may be null in cron context when the job is processing by user ID only — guard against null before using it.
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: 'admin' (right-to-erasure request via Admin UI or REST) or 'cron' (scheduled retention purge) |
$user_id |
int |
— | WordPress user ID being purged; 0 when the purge is keyed on email only |
$email |
string |
— | Email address being purged; empty string when the purge is keyed on $user_id only |
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 →