Make WordPress Core

Changeset 45039


Ignore:
Timestamp:
03/27/2019 07:41:01 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Ensure the privacy data erase fulfillment email is sent in the locale of the user whose data is being erased (or the site's default locale if they are not a registered user) when the administrator fulfilling the request uses a different locale.

Props desrosj, birgire, garrett-eclipse.
Fixes #44721.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r44930 r45039  
    31413141    }
    31423142
     3143    // Localize message content for user; fallback to site default for visitors.
     3144    if ( ! empty( $request->user_id ) ) {
     3145        $locale = get_user_locale( $request->user_id );
     3146    } else {
     3147        $locale = get_locale();
     3148    }
     3149
     3150    $switched_locale = switch_to_locale( $locale );
     3151
    31433152    /**
    31443153     * Filters the recipient of the data erasure fulfillment notification.
     
    32503259
    32513260    $email_sent = wp_mail( $user_email, $subject, $content );
     3261
     3262    if ( $switched_locale ) {
     3263        restore_previous_locale();
     3264    }
    32523265
    32533266    if ( $email_sent ) {
  • trunk/tests/phpunit/data/languages/de_DE.po

    r43568 r45039  
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2018-08-13 19:19+0300\n"
     5"PO-Revision-Date: 2019-03-27 22:27+0300\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    99"Plural-Forms: nplurals=2; plural=n != 1;\n"
    10 "X-Generator: Poedit 2.1.1\n"
    11 "Project-Id-Version: Development (4.9.x)\n"
     10"X-Generator: Poedit 2.2.1\n"
     11"Project-Id-Version: Development (5.2.x)\n"
    1212"Language: de_DE\n"
    1313"POT-Creation-Date: \n"
     
    4949msgid "[%1$s] Confirm Action: %2$s"
    5050msgstr "[%1$s] Aktion bestätigen: %2$s"
     51
     52#. translators: %s: Site name.
     53#: wp-includes/user.php:3175
     54msgid "[%s] Erasure Request Fulfilled"
     55msgstr "[%s] Löschauftrag ausgeführt"
  • trunk/tests/phpunit/data/languages/es_ES.po

    r43568 r45039  
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2018-08-13 19:19+0300\n"
     5"PO-Revision-Date: 2019-03-27 22:27+0300\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    99"Plural-Forms: nplurals=2; plural=n != 1;\n"
    10 "X-Generator: Poedit 2.1.1\n"
    11 "Project-Id-Version: Development (4.9.x)\n"
     10"X-Generator: Poedit 2.2.1\n"
     11"Project-Id-Version: Development (5.2.x)\n"
    1212"Language: es_ES\n"
    1313"POT-Creation-Date: \n"
     
    4545msgid "[%1$s] Confirm Action: %2$s"
    4646msgstr "[%1$s] Confirma la acción: %2$s"
     47
     48#. translators: %s: Site name.
     49#: wp-includes/user.php:3175
     50msgid "[%s] Erasure Request Fulfilled"
     51msgstr "[%s] Solicitud de borrado completada"
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php

    r44535 r45039  
    3636
    3737    /**
     38     * Request user.
     39     *
     40     * @since 5.2.0
     41     *
     42     * @var WP_User $request_user
     43     */
     44    protected static $request_user;
     45
     46    /**
     47     * Test administrator user.
     48     *
     49     * @since 5.2.0
     50     *
     51     * @var WP_User $admin_user
     52     */
     53    protected static $admin_user;
     54
     55    /**
    3856     * Create user request fixtures shared by test methods.
    3957     *
     
    4462    public static function wpSetUpBeforeClass( $factory ) {
    4563        self::$requester_email = 'erase-my-data@local.test';
    46         self::$request_id      = wp_create_user_request( self::$requester_email, 'erase_personal_data' );
     64        self::$request_user    = $factory->user->create_and_get(
     65            array(
     66                'user_email' => self::$requester_email,
     67                'role'       => 'subscriber',
     68            )
     69        );
     70        self::$admin_user      = $factory->user->create_and_get(
     71            array(
     72                'user_email' => 'admin@local.dev',
     73                'role'       => 'administrator',
     74            )
     75        );
     76
     77        self::$request_id = wp_create_user_request( self::$requester_email, 'remove_personal_data' );
    4778        wp_update_post(
    4879            array(
     
    70101    public function tearDown() {
    71102        reset_phpmailer_instance();
     103        restore_previous_locale();
    72104        parent::tearDown();
    73105    }
     
    277309    }
    278310
     311    /**
     312     * The function should respect the user locale settings when the site uses the default locale.
     313     *
     314     * @since 5.2.0
     315     * @ticket 44721
     316     * @group l10n
     317     */
     318    public function test_should_send_fulfillment_email_in_user_locale() {
     319        update_user_meta( self::$request_user->ID, 'locale', 'es_ES' );
     320
     321        _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     322        $mailer = tests_retrieve_phpmailer_instance();
     323
     324        $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     325    }
     326
     327    /**
     328     * The function should respect the user locale settings when the site does not use en_US, the administrator
     329     * uses the site's default locale, and the user has a different locale.
     330     *
     331     * @since 5.2.0
     332     * @ticket 44721
     333     * @group l10n
     334     */
     335    public function test_should_send_fulfillment_email_in_user_locale_when_site_is_not_en_us() {
     336        update_option( 'WPLANG', 'es_ES' );
     337        switch_to_locale( 'es_ES' );
     338
     339        update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     340        wp_set_current_user( self::$admin_user->ID );
     341
     342        _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     343        $mailer = tests_retrieve_phpmailer_instance();
     344
     345        $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     346    }
     347
     348    /**
     349     * The function should respect the user locale settings when the site is not en_US, the administrator
     350     * has a different selected locale, and the user uses the site's default locale.
     351     *
     352     * @since 5.2.0
     353     * @ticket 44721
     354     * @group l10n
     355     */
     356    public function test_should_send_fulfillment_email_in_user_locale_when_admin_and_site_have_different_locales() {
     357        update_option( 'WPLANG', 'es_ES' );
     358        switch_to_locale( 'es_ES' );
     359
     360        update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     361        wp_set_current_user( self::$admin_user->ID );
     362
     363        _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     364        $mailer = tests_retrieve_phpmailer_instance();
     365
     366        $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     367    }
     368
     369    /**
     370     * The function should respect the user locale settings when the site is not en_US and both the
     371     * administrator and the user use different locales.
     372     *
     373     * @since 5.2.0
     374     * @ticket 44721
     375     * @group l10n
     376     */
     377    public function test_should_send_fulfillment_email_in_user_locale_when_both_have_different_locales_than_site() {
     378        update_option( 'WPLANG', 'es_ES' );
     379        switch_to_locale( 'es_ES' );
     380
     381        update_user_meta( self::$admin_user->ID, 'locale', 'en_US' );
     382        update_user_meta( self::$request_user->ID, 'locale', 'de_DE' );
     383
     384        wp_set_current_user( self::$admin_user->ID );
     385
     386        _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     387        $mailer = tests_retrieve_phpmailer_instance();
     388
     389        $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     390    }
     391
     392    /**
     393     * The function should respect the site's locale when the request is for an unregistered user and the
     394     * administrator does not use the site's locale.
     395     *
     396     * @since 5.2.0
     397     * @ticket 44721
     398     * @group l10n
     399     */
     400    public function test_should_send_fulfillment_email_in_site_locale() {
     401        update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' );
     402        wp_set_current_user( self::$admin_user->ID );
     403
     404        $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' );
     405        wp_update_post(
     406            array(
     407                'ID'          => $request_id,
     408                'post_status' => 'request-completed',
     409            )
     410        );
     411
     412        _wp_privacy_send_erasure_fulfillment_notification( $request_id );
     413        $mailer = tests_retrieve_phpmailer_instance();
     414
     415        $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
     416    }
     417
     418    /**
     419     * The function should respect the site's locale when it is not en_US, the request is for an
     420     * unregistered user, and the administrator does not use the site's default locale.
     421     *
     422     * @since 5.2.0
     423     * @ticket 44721
     424     * @group l10n
     425     */
     426    public function test_should_send_fulfillment_email_in_site_locale_when_not_en_us_and_admin_has_different_locale() {
     427        update_option( 'WPLANG', 'es_ES' );
     428        switch_to_locale( 'es_ES' );
     429
     430        update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' );
     431        wp_set_current_user( self::$admin_user->ID );
     432
     433        $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' );
     434        wp_update_post(
     435            array(
     436                'ID'          => $request_id,
     437                'post_status' => 'request-completed',
     438            )
     439        );
     440
     441        _wp_privacy_send_erasure_fulfillment_notification( $request_id );
     442        $mailer = tests_retrieve_phpmailer_instance();
     443
     444        $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     445    }
    279446}
Note: See TracChangeset for help on using the changeset viewer.