Include Custom Profile Fields in Personal Data Exports
Adds the custom user fields you list (such as phone or company) to the personal data export file WordPress creates under Tools > Export Personal Data.
Opens WPIDE on
Code
// User meta key => label shown in the export.
$wpide_export_user_meta = array(
'phone' => 'Phone number',
'company' => 'Company',
'billing_country' => 'Country',
);
add_filter( 'wp_privacy_personal_data_exporters', function ( $exporters ) use ( $wpide_export_user_meta ) {
$exporters['wpide-user-meta'] = array(
'exporter_friendly_name' => 'Extra profile fields',
'callback' => function ( $email ) use ( $wpide_export_user_meta ) {
$user = get_user_by( 'email', $email );
$data = array();
if ( $user ) {
foreach ( $wpide_export_user_meta as $key => $label ) {
$value = get_user_meta( $user->ID, $key, true );
if ( '' !== $value && null !== $value ) {
$data[] = array( 'name' => $label, 'value' => is_scalar( $value ) ? (string) $value : wp_json_encode( $value ) );
}
}
}
return array(
'data' => $data ? array( array( 'group_id' => 'wpide-profile', 'group_label' => 'Extra profile fields', 'item_id' => 'user-' . ( $user ? $user->ID : 0 ), 'data' => $data ) ) : array(),
'done' => true,
);
},
);
return $exporters;
} );
Notes
List the meta keys your theme or plugins store for users, with the label you want in the export.
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.