Add your own user fields, like phone or job title, to WordPress's Export Personal Data and Erase Personal Data tools.
function nahnu_privacy_fields(): array {
// Meta key => label.
return [
'nahnu_job_title' => 'Job title',
'nahnu_phone' => 'Phone',
];
}
add_filter( 'wp_privacy_personal_data_exporters', function ( array $exporters ): array {
$exporters['nahnu-profile'] = [
'exporter_friendly_name' => 'Extra profile fields',
'callback' => function ( string $email, int $page = 1 ): array {
$user = get_user_by( 'email', $email );
$data = [];
if ( $user ) {
foreach ( nahnu_privacy_fields() as $key => $label ) {
$value = get_user_meta( $user->ID, $key, true );
if ( '' !== $value ) {
$data[] = [ 'name' => $label, 'value' => $value ];
}
}
}
return [
'data' => $data ? [ [
'group_id' => 'nahnu-profile',
'group_label' => 'Extra profile fields',
'item_id' => 'user-' . ( $user->ID ?? 0 ),
'data' => $data,
] ] : [],
'done' => true,
];
},
];
return $exporters;
} );
add_filter( 'wp_privacy_personal_data_erasers', function ( array $erasers ): array {
$erasers['nahnu-profile'] = [
'eraser_friendly_name' => 'Extra profile fields',
'callback' => function ( string $email, int $page = 1 ): array {
$user = get_user_by( 'email', $email );
$removed = false;
if ( $user ) {
foreach ( array_keys( nahnu_privacy_fields() ) as $key ) {
$removed = delete_user_meta( $user->ID, $key ) || $removed;
}
}
return [ 'items_removed' => $removed, 'items_retained' => false, 'messages' => [], 'done' => true ];
},
];
return $erasers;
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WordPress’s privacy tools, under Tools → Export Personal Data and Erase Personal Data, only know about the data WordPress and well-behaved plugins register. If you’ve added your own profile fields, they’re left out, and your exports are incomplete. This snippet adds them.
wp_privacy_personal_data_exporters registers an exporter. Given an email address, it finds the user and returns each of your fields that has a value, grouped under “Extra profile fields” in the export file.
wp_privacy_personal_data_erasers registers an eraser that deletes those fields for the user and reports whether anything was removed.
List your meta keys and labels once, in nahnu_privacy_fields(), and both tools use them.
$page and 'done' => false to process large amounts in batches.Go to Tools → Export Personal Data, add your own email and download the export. It should include an “Extra profile fields” section.