Remove Completed Privacy Requests After 90 Days
Deletes finished export and erasure requests (and failed ones) from Tools > Export/Erase Personal Data once they are 90 days old, since the request records themselves contain email addresses.
Opens WPIDE on
Code
// Age in days after which finished requests are removed.
$wpide_request_days = 90;
add_action( 'init', function () {
if ( ! wp_next_scheduled( 'wpide_clean_privacy_requests' ) ) {
wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'wpide_clean_privacy_requests' );
}
} );
add_action( 'wpide_clean_privacy_requests', function () use ( $wpide_request_days ) {
$ids = get_posts( array(
'post_type' => 'user_request',
'post_status' => array( 'request-completed', 'request-failed' ),
'posts_per_page' => 100,
'fields' => 'ids',
'no_found_rows' => true,
'date_query' => array( array( 'column' => 'post_modified_gmt', 'before' => $wpide_request_days . ' days ago' ) ),
) );
foreach ( $ids as $id ) {
wp_delete_post( $id, true );
}
} );
Notes
Keep records longer if you need them as proof that requests were handled.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.