Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/wp-includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -4962,18 +4962,32 @@ function wp_send_user_request( $request_id ) {
*/
$request->confirm_key = wp_generate_user_request_key( $request_id );

$confirm_url = add_query_arg(
array(
'action' => 'confirmaction',
'request_id' => $request_id,
'confirm_key' => $request->confirm_key,
),
wp_login_url()
);

/*
* When the user has explicitly selected a locale on their profile, add it to the
* confirmation URL so the confirmation page is displayed in the same language as the email.
*/
if ( ! empty( $request->user_id ) ) {
$user_selected_locale = get_user_meta( (int) $request->user_id, 'locale', true );

if ( ! empty( $user_selected_locale ) ) {
$confirm_url = add_query_arg( 'wp_lang', $user_selected_locale, $confirm_url );
}
}

$email_data = array(
'request' => $request,
'email' => $request->email,
'description' => wp_user_request_action_description( $request->action_name ),
'confirm_url' => add_query_arg(
array(
'action' => 'confirmaction',
'request_id' => $request_id,
'confirm_key' => $request->confirm_key,
),
wp_login_url()
),
'confirm_url' => $confirm_url,
'sitename' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
'siteurl' => home_url(),
);
Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/tests/user/wpSendUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public function test_should_send_user_request_email_in_user_locale() {
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
$this->assertStringContainsString( 'wp_lang=es_ES', $mailer->get_sent()->body );
}

/**
Expand All @@ -305,6 +306,7 @@ public function test_should_send_user_request_email_in_user_locale_when_site_is_
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Aktion bestätigen', $mailer->get_sent()->subject );
$this->assertStringContainsString( 'wp_lang=de_DE', $mailer->get_sent()->body );
}

/**
Expand All @@ -327,6 +329,7 @@ public function test_should_send_user_request_email_in_user_locale_when_admin_an
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
$this->assertStringNotContainsString( 'wp_lang=', $mailer->get_sent()->body );
}

/**
Expand All @@ -351,6 +354,7 @@ public function test_should_send_user_request_email_in_user_locale_when_both_hav
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Confirm Action', $mailer->get_sent()->subject );
$this->assertStringContainsString( 'wp_lang=en_US', $mailer->get_sent()->body );
}

/**
Expand All @@ -370,6 +374,7 @@ public function test_should_send_user_request_email_in_site_locale() {
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Confirm Action', $mailer->get_sent()->subject );
$this->assertStringNotContainsString( 'wp_lang=', $mailer->get_sent()->body );
}

/**
Expand All @@ -392,5 +397,31 @@ public function test_should_send_user_request_email_in_site_locale_when_not_en_u
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
$this->assertStringNotContainsString( 'wp_lang=', $mailer->get_sent()->body );
}

/**
* The confirmation URL should include the user's selected locale even when it matches the site's locale,
* so the confirmation page keeps the user's language if the site's locale changes later.
*
* @ticket 44550
* @group l10n
*/
public function test_should_send_user_request_email_in_user_locale_when_user_and_site_share_locale() {
update_option( 'WPLANG', 'de_DE' );
switch_to_locale( 'de_DE' );

update_user_meta( self::$test_user->ID, 'locale', 'de_DE' );
update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' );

wp_set_current_user( self::$admin_user->ID );

$request_id = wp_create_user_request( self::$test_user->user_email, 'remove_personal_data' );

wp_send_user_request( $request_id );
$mailer = tests_retrieve_phpmailer_instance();

$this->assertStringContainsString( 'Aktion bestätigen', $mailer->get_sent()->subject );
$this->assertStringContainsString( 'wp_lang=de_DE', $mailer->get_sent()->body );
}
}
Loading