Skip to main content

benecaster_after_gdpr_purge

Action Free

Fires after a per-user GDPR erasure cascade completes, with row counts for each affected table. 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. Does not fire for users whose erasure was aborted by the benecaster_gdpr_purge_skip filter.

Use this hook to mirror the purge to external systems — CRM contact deletion, email service provider unsubscribe, data warehouse row tombstoning — log completion for compliance audits, or trigger a downstream verification job.

Parameters

Name Type Default Description
$source string — Origin of the purge, the same value the paired benecaster_before_gdpr_purge received: 'cron' (the nightly retention sweep), 'manual' (a subscriber deleted by email from the Tools screen) or 'account_deleted' (the person's WordPress account was deleted).
$result array — Purge result: {tables: {table_name: rows_affected}, user_id: int, email: ?string}. There is no total; sum `tables` yourself. Rows anonymised rather than deleted (subscriber events, membership payments, buy-ups, preview links) are counted too. Iterate `tables` rather than hard-coding a key; the entitlements count is always 0 on 'cron'. `benecaster_subscriber_buyups` counts buy-ups unlinked from the person, and is non-zero only on 'account_deleted'. `benecaster_preview_tokens` counts episode preview links whose recipient name and email were cleared; it runs on any source given an email, so it is always 0 on 'cron'.

Examples

Log erasure for GDPR compliance records

add_action( 'benecaster_after_gdpr_purge', function ( string $source, array $result ): void {
    $log_entry = sprintf(
        '[GDPR] Erasure complete — source=%s user_id=%d email=%s records_affected=%d',
        $source,
        $result['user_id'],
        $result['email'] ?? 'n/a',
        array_sum( $result['tables'] )
    );
    error_log( $log_entry );
}, 10, 2 );

Notes

All deletions have already been committed when this action fires — it is an observation point, not an opportunity to prevent the erasure. The erasure includes the person's queued emails, pending ones included, along with the stored copies of emails already sent. A table count of 0 means no rows matched that user in that table, which is expected for users who never triggered activity there. Use this hook for GDPR compliance records and external system notifications.

Need this built rather than just documented? See our services →