From dde1caf1116bb37bc93c4aa9f281f1d372368605 Mon Sep 17 00:00:00 2001 From: sawfly Date: Fri, 6 Nov 2026 14:07:16 +0000 Subject: [PATCH] Confirmation page for export user data now on user language --- src/wp-includes/user.php | 30 +++++++++++++----- .../phpunit/tests/user/wpSendUserRequest.php | 31 +++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 02a412b291a8e..cb868f185b305 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -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(), ); diff --git a/tests/phpunit/tests/user/wpSendUserRequest.php b/tests/phpunit/tests/user/wpSendUserRequest.php index 11e3130f225a5..6097333c1715a 100644 --- a/tests/phpunit/tests/user/wpSendUserRequest.php +++ b/tests/phpunit/tests/user/wpSendUserRequest.php @@ -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 ); } /** @@ -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 ); } /** @@ -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 ); } /** @@ -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 ); } /** @@ -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 ); } /** @@ -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 ); } }