# Erase Custom Profile Fields on Erasure Requests

> Deletes the custom user fields you list when you run a personal data erasure request under Tools > Erase Personal Data, so they are not left behind.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: gdpr, erasure, user-meta
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-erase-user-meta/

## Code

```php
// User meta keys removed by an erasure request.
$wpide_erase_user_meta = array( 'phone', 'company', 'date_of_birth' );

add_filter( 'wp_privacy_personal_data_erasers', function ( $erasers ) use ( $wpide_erase_user_meta ) {
    $erasers['wpide-user-meta'] = array(
        'eraser_friendly_name' => 'Extra profile fields',
        'callback'             => function ( $email ) use ( $wpide_erase_user_meta ) {
            $user    = get_user_by( 'email', $email );
            $removed = false;

            if ( $user ) {
                foreach ( $wpide_erase_user_meta as $key ) {
                    if ( metadata_exists( 'user', $user->ID, $key ) ) {
                        $removed = delete_user_meta( $user->ID, $key ) || $removed;
                    }
                }
            }

            return array(
                'items_removed'  => $removed,
                'items_retained' => false,
                'messages'       => array(),
                'done'           => true,
            );
        },
    );

    return $erasers;
} );
```

## Notes

Only the listed keys are removed; the account itself is not deleted.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Erase Custom Profile Fields on Erasure Requests" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
