Skip to content

Instantly share code, notes, and snippets.

@rhyswynne
Created June 18, 2018 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhyswynne/09d1b31862c1f0eebc986452663d5b47 to your computer and use it in GitHub Desktop.
Save rhyswynne/09d1b31862c1f0eebc986452663d5b47 to your computer and use it in GitHub Desktop.
Hook the GDPR exporter into WordPress
<?php
/**
* Hook function adding the wp-email-capture array to the GDPR friendly plugin exporter.
*
* @param array $exporters All current Exporters
* @return array All exporters plus the WP Email Capture one.
*/
function wp_email_capture_register_plugin_exporter( $exporters ) {
$exporters['wp-email-capture'] = array(
'exporter_friendly_name' => __( 'WP Email Capture' ),
'callback' => 'wp_email_capture_plugin_exporter',
);
return $exporters;
} add_filter( 'wp_privacy_personal_data_exporters', 'wp_email_capture_register_plugin_exporter', 10 );
/**
* This function links into the GDPR exporter, meaning we can begin to export registered today.
*
* @param string $email_address The email address we are looking for.
* @param integer $page The page of data we are grabbing.
* @return array An array of data we will need to find.
*/
function wp_email_capture_plugin_exporter( $email_address, $page = 1 ) {
$number = 500; // Limit us to avoid timing out
$page = (int) $page;
$export_items = array();
$emaildatatocheck[] = wp_email_capture_get_data_from_email_temp( $email_address );
$emaildatatocheck[] = wp_email_capture_get_data_from_email_main( $email_address );
$x = '';
foreach ( $emaildatatocheck as $emaildatatemp ) {
$datatocheck = array();
$columns = get_object_vars( $emaildatatemp[0] );
foreach ( $columns as $column => $value ) {
$datatocheck[] = $column;
}
foreach ( (array) $emaildatatemp as $emaildata ) {
$x++;
$item_id = "wp-email-capture-{$emaildata->id}";
// Core group IDs include 'comments', 'posts', etc.
// But you can add your own group IDs as needed
$group_id = 'emailcapture';
// 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 = __( 'WP Email Capture Data' );
$data = array();
// Plugins can add as many items in the item data array as they want
foreach ( $datatocheck as $header ) {
$data[] = array(
'name' => $header,
'value' => $emaildata->$header,
);
}
$export_items[] = array(
'group_id' => $group_id,
'group_label' => $group_label,
'item_id' => $item_id,
'data' => $data,
);
}
}
$done = $x < $number;
return array(
'data' => $export_items,
'done' => $done,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment