Add support to your plugin or theme for WordPress Personal Data Exporter (GDPR Compliancy).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register exporter for Plugin user data. | |
* | |
* @see https://github.com/allendav/wp-privacy-requests/blob/master/EXPORT.md | |
* | |
* @param $exporters | |
* | |
* @return array | |
*/ | |
function plugin_register_exporters( $exporters ) { | |
$exporters[] = array( | |
'exporter_friendly_name' => __( 'User Social Accounts' ), | |
'callback' => 'plugin_user_data_exporter', | |
); | |
return $exporters; | |
} | |
add_filter( 'wp_privacy_personal_data_exporters', 'plugin_register_exporters' ); | |
/** | |
* Exporter for Plugin user data. | |
* | |
* @see https://github.com/allendav/wp-privacy-requests/blob/master/EXPORT.md | |
* | |
* @param $email_address | |
* @param int $page | |
* | |
* @return array | |
*/ | |
function plugin_user_data_exporter( $email_address, $page = 1 ) { | |
$export_items = array(); | |
$user = get_user_by( 'email', $email_address ); | |
if ( $user && $user->ID ) { | |
// Most item IDs should look like postType-postID | |
// If you don't have a post, comment or other ID to work with, | |
// use a unique value to avoid having this item's export | |
// combined in the final report with other items of the same id | |
$item_id = "user-social-{$user->ID}"; | |
// Core group IDs include 'comments', 'posts', etc. | |
// But you can add your own group IDs as needed | |
$group_id = 'user-social'; | |
// Optional group label. Core provides these for core groups. | |
// If you define your own group, the first exporter to | |
// include a label will be used as the group label in the | |
// final exported report | |
$group_label = __( 'User Social Data' ); | |
// Plugins can add as many items in the item data array as they want | |
$data = array(); | |
// Add the users facebook url | |
$facebook_url = get_user_meta( $user->ID, 'facebook_url' ); | |
if ( $facebook_url ) { | |
$data[] = array( | |
'name' => __( 'Facebook URL', 'popup-maker' ), | |
'value' => $facebook_url, | |
); | |
} | |
// Add their twitter handle | |
$twitter_handle = get_user_meta( $user->ID, 'twitter_handle' ); | |
if ( $twitter_handle ) { | |
$data[] = array( | |
'name' => __( 'Twitter Handle', 'popup-maker' ), | |
'value' => $twitter_handle, | |
); | |
} | |
// Add this group of items to the exporters data array. | |
$export_items[] = array( | |
'group_id' => $group_id, | |
'group_label' => $group_label, | |
'item_id' => $item_id, | |
'data' => $data, | |
); | |
} | |
// Returns an array of exported items for this pass, but also a boolean whether this exporter is finished. | |
//If not it will be called again with $page increased by 1. | |
return array( | |
'data' => $export_items, | |
'done' => true, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment