Created
June 20, 2018 18:18
-
-
Save rhyswynne/1aa18d9bf2fe41491969bd5b63093dc6 to your computer and use it in GitHub Desktop.
Adding the GDPR eraser functionality in WordPress to your plugin
This file contains hidden or 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 the Plugin Eraser for WP Email Capture Premium | |
| * | |
| * @param array $erasers All erasers. | |
| * @return array $erasers All erasers with the WP Email Capture one. | |
| */ | |
| function wp_email_capture_register_premium_plugin_eraser( $erasers ) { | |
| $erasers['wp-email-capture'] = array( | |
| 'eraser_friendly_name' => __( 'WP Email Capture' ), | |
| 'callback' => 'wp_email_capture_premium_plugin_eraser', | |
| ); | |
| return $erasers; | |
| } add_filter( 'wp_privacy_personal_data_erasers', 'wp_email_capture_register_plugin_eraser', 10 ); | |
| /** | |
| * WP Email Capture Premium Eraser function. | |
| * | |
| * Removes all data from the WP Email Capture tables. Including the meta table. | |
| * | |
| * @param string $email_address The email address we are looking to erase. | |
| * @param integer $page The page we are looking for. | |
| * @return array Array containing data on how successful the erasure process has been. | |
| */ | |
| function wp_email_capture_premium_plugin_eraser( $email_address, $page = 1 ) { | |
| $number = 500; // Limit us to avoid timing out | |
| $page = (int) $page; | |
| $items_removed = false; | |
| $tabledata = array( WP_EMAIL_CAPTURE_TEMP_MEMBERS_TABLE, WP_EMAIL_CAPTURE_REGISTERED_MEMBERS_TABLE ); | |
| global $wpdb; | |
| foreach ( $tabledata as $table ) { | |
| $ids = $wpdb->get_col( $wpdb->prepare( 'SELECT id FROM ' . $table . ' WHERE email = %s', $email_address ) ); | |
| foreach ( $ids as $id ) { | |
| $metadelete = wp_email_capture_delete_meta_data_from_id( $id ); | |
| } | |
| //$delete_member_sql = "DELETE FROM $table WHERE email = '%s'"; | |
| $querysuccessful = $wpdb->delete( $table, array( 'email' => $email_address ), array( '%s' ) ); | |
| if ( false !== $querysuccessful && true !== $items_removed ) { | |
| $items_removed = true; | |
| $rowsremoved = $rowsremoved + $querysuccessful; | |
| } | |
| } | |
| // Tell core if we have more comments to work on still | |
| $done = $querysuccessful < $number; | |
| return array( | |
| 'items_removed' => $items_removed, | |
| 'items_retained' => false, // always false in this example | |
| 'messages' => array(), // no messages in this example | |
| 'done' => $done, | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment