From 08af3900c34b1bb4185aa1ae1272240e163b76e6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Aug 2018 16:32:27 +0000 Subject: [PATCH] Privacy: Ensure the user request email is sent in the requested user's locale (or the site's default locale if they are not a registered user) when the administrator creating the request uses a different locale. Props desrosj, Chouby, iandunn, lbenicio, birgire, earnjam, swissspidy, garrett-eclipse. Fixes #43985. Built from https://develop.svn.wordpress.org/trunk@43568 git-svn-id: http://core.svn.wordpress.org/trunk@43397 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 4 ++-- wp-includes/user.php | 28 +++++++++++++++++++++++----- wp-includes/version.php | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 3c8f9c221a..4fd93e2e60 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -2196,7 +2196,7 @@ function wp_privacy_send_personal_data_export_email( $request_id ) { $request = wp_get_user_request_data( $request_id ); if ( ! $request || 'export_personal_data' !== $request->action_name ) { - return new WP_Error( 'invalid', __( 'Invalid request ID when sending personal data export email.' ) ); + return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) ); } /** This filter is documented in wp-includes/functions.php */ @@ -2256,7 +2256,7 @@ All at ###SITENAME### ); if ( ! $mail_success ) { - return new WP_Error( 'error', __( 'Unable to send personal data export email.' ) ); + return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) ); } return true; diff --git a/wp-includes/user.php b/wp-includes/user.php index 4ebcf822a9..c1de6f1243 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -3357,16 +3357,25 @@ function wp_user_request_action_description( $action_name ) { * @since 4.9.6 * * @param string $request_id ID of the request created via wp_create_user_request(). - * @return WP_Error|bool Will return true/false based on the success of sending the email, or a WP_Error object. + * @return bool|WP_Error True on success, `WP_Error` on failure. */ function wp_send_user_request( $request_id ) { $request_id = absint( $request_id ); $request = wp_get_user_request_data( $request_id ); if ( ! $request ) { - return new WP_Error( 'user_request_error', __( 'Invalid request.' ) ); + return new WP_Error( 'invalid_request', __( 'Invalid user request.' ) ); } + // Localize message content for user; fallback to site default for visitors. + if ( ! empty( $request->user_id ) ) { + $locale = get_user_locale( $request->user_id ); + } else { + $locale = get_locale(); + } + + $switched_locale = switch_to_locale( $locale ); + $email_data = array( 'request' => $request, 'email' => $request->email, @@ -3454,7 +3463,17 @@ All at ###SITENAME### */ $subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data ); - return wp_mail( $email_data['email'], $subject, $content ); + $email_sent = wp_mail( $email_data['email'], $subject, $content ); + + if ( $switched_locale ) { + restore_previous_locale(); + } + + if ( ! $email_sent ) { + return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) ); + } + + return true; } /** @@ -3504,7 +3523,7 @@ function wp_validate_user_request_key( $request_id, $key ) { $request = wp_get_user_request_data( $request_id ); if ( ! $request ) { - return new WP_Error( 'user_request_error', __( 'Invalid request.' ) ); + return new WP_Error( 'invalid_request', __( 'Invalid request.' ) ); } if ( ! in_array( $request->status, array( 'request-pending', 'request-failed' ), true ) ) { @@ -3591,7 +3610,6 @@ final class WP_User_Request { * * @var int */ - public $user_id = 0; /** diff --git a/wp-includes/version.php b/wp-includes/version.php index a7236847be..b0010e7e8a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-43567'; +$wp_version = '5.0-alpha-43568'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.