From bc5ecec3fc28f9e4e31ebfc001ce6aa74e7c9365 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 10 May 2018 20:42:15 +0000 Subject: [PATCH] Privacy: Send an email notification to the user once their personal data erasure request is fulfilled. Props desrosj, allendav, garrett-eclipse. Fixes #43973. git-svn-id: https://develop.svn.wordpress.org/trunk@43230 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/admin-filters.php | 1 + src/wp-admin/includes/user.php | 9 ++ src/wp-includes/user.php | 114 ++++++++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php index 233f40f6dd..79e30c0eda 100644 --- a/src/wp-admin/includes/admin-filters.php +++ b/src/wp-admin/includes/admin-filters.php @@ -136,6 +136,7 @@ add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 ); add_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 ); add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 ); add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 ); +add_action( 'wp_privacy_personal_data_erased', '_wp_privacy_send_erasure_fulfillment_notification', 10 ); // Privacy policy text changes check. add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 100 ); diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 7694889b44..79286f1014 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -981,6 +981,15 @@ function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index _wp_privacy_completed_request( $request_id ); + /** + * Fires immediately after a personal data erasure request has been marked completed. + * + * @since 4.9.6 + * + * @param int $request_id The privacy request post ID associated with this request. + */ + do_action( 'wp_privacy_personal_data_erased', $request_id ); + return $response; } diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 48b00f49ac..a5254bf4d3 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3066,6 +3066,120 @@ All at ###SITENAME### } } +/** + * Notify the user when their erasure request is fulfilled. + * + * Without this, the user would never know if their data was actually erased. + * + * @since 4.9.6 + * + * @param int $request_id The privacy request post ID associated with this request. + */ +function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { + $request_data = wp_get_user_request_data( $request_id ); + + if ( ! is_a( $request_data, 'WP_User_Request' ) || 'request-completed' !== $request_data->status ) { + return; + } + + $already_notified = (bool) get_post_meta( $request_id, '_wp_user_notified', true ); + + if ( $already_notified ) { + return; + } + + $subject = sprintf( + /* translators: %s Site name. */ + __( '[%s] Erasure Request Fulfilled' ), + wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) + ); + + /** + * Filters the recipient of the data erasure fulfillment notification. + * + * @since 4.9.6 + * + * @param string $user_email The email address of the notification recipient. + * @param WP_User_Request $request_data The request that is initiating the notification. + */ + $user_email = apply_filters( 'user_erasure_fulfillment_email_to', $request_data->email, $request_data ); + + $email_data = array( + 'request' => $request_data, + 'user_email' => $request_data->email, + 'privacy_policy_url' => get_privacy_policy_url(), + 'sitename' => get_option( 'blogname' ), + 'siteurl' => home_url(), + ); + + if ( empty( $email_data['privacy_policy_url'] ) ) { + /* translators: Do not translate SITENAME, SITEURL; those are placeholders. */ + $email_text = __( + 'Howdy, + +Your request to erase your personal data on ###SITENAME### has been completed. + +If you have any follow-up questions or concerns, please contact the site administrator. + +Regards, +All at ###SITENAME### +###SITEURL###' + ); + } else { + /* translators: Do not translate SITENAME, SITEURL, PRIVACY_POLICY_URL; those are placeholders. */ + $email_text = __( + 'Howdy, + +Your request to erase your personal data on ###SITENAME### has been completed. + +If you have any follow-up questions or concerns, please contact the site administrator. + +For more information, you can also read our privacy policy: ###PRIVACY_POLICY_URL### + +Regards, +All at ###SITENAME### +###SITEURL###' + ); + } + + /** + * Filters the body of the data erasure fulfillment notification. + * + * The email is sent to a user when a their data erasure request is fulfilled + * by an administrator. + * + * The following strings have a special meaning and will get replaced dynamically: + * + * ###SITENAME### The name of the site. + * ###PRIVACY_POLICY_URL### Privacy policy page URL. + * ###SITEURL### The URL to the site. + * + * @since 4.9.6 + * + * @param string $email_text Text in the email. + * @param array $email_data { + * Data relating to the account action email. + * + * @type WP_User_Request $request User request object. + * @type string $user_email The email address confirming a request. + * @type string $privacy_policy_url Privacy policy URL. + * @type string $sitename The site name sending the mail. + * @type string $siteurl The site URL sending the mail. + * } + */ + $content = apply_filters( 'user_confirmed_action_email_content', $email_text, $email_data ); + + $content = str_replace( '###SITENAME###', wp_specialchars_decode( $email_data['sitename'], ENT_QUOTES ), $content ); + $content = str_replace( '###PRIVACY_POLICY_URL###', $email_data['privacy_policy_url'], $content ); + $content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content ); + + $email_sent = wp_mail( $user_email, $subject, $content ); + + if ( $email_sent ) { + update_post_meta( $request_id, '_wp_user_notified', true ); + } +} + /** * Return request confirmation message HTML. *