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
This commit is contained in:
Sergey Biryukov 2018-08-13 16:32:27 +00:00
parent a2648da538
commit 08af3900c3
3 changed files with 26 additions and 8 deletions

View File

@ -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;

View File

@ -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;
/**

View File

@ -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.