Make WordPress Core

Changeset 43614 for branches/4.9


Ignore:
Timestamp:
09/03/2018 09:00:16 PM (8 years ago)
Author:
SergeyBiryukov
Message:

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.
Merges [43568] to the 4.9 branch.
Fixes #43985.

Location:
branches/4.9
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/file.php

    r43528 r43614  
    20602060
    20612061        if ( ! $request || 'export_personal_data' !== $request->action_name ) {
    2062                 return new WP_Error( 'invalid', __( 'Invalid request ID when sending personal data export email.' ) );
     2062                return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
    20632063        }
    20642064
     
    21202120
    21212121        if ( ! $mail_success ) {
    2122                 return new WP_Error( 'error', __( 'Unable to send personal data export email.' ) );
     2122                return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) );
    21232123        }
    21242124
  • branches/4.9/src/wp-includes/user.php

    r43488 r43614  
    32803280 *
    32813281 * @param string $request_id ID of the request created via wp_create_user_request().
    3282  * @return WP_Error|bool Will return true/false based on the success of sending the email, or a WP_Error object.
     3282 * @return bool|WP_Error True on success, `WP_Error` on failure.
    32833283 */
    32843284function wp_send_user_request( $request_id ) {
     
    32873287
    32883288        if ( ! $request ) {
    3289                 return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
    3290         }
     3289                return new WP_Error( 'invalid_request', __( 'Invalid user request.' ) );
     3290        }
     3291
     3292        // Localize message content for user; fallback to site default for visitors.
     3293        if ( ! empty( $request->user_id ) ) {
     3294                $locale = get_user_locale( $request->user_id );
     3295        } else {
     3296                $locale = get_locale();
     3297        }
     3298
     3299        $switched_locale = switch_to_locale( $locale );
    32913300
    32923301        $email_data = array(
     
    33773386        $subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data );
    33783387
    3379         return wp_mail( $email_data['email'], $subject, $content );
     3388        $email_sent = wp_mail( $email_data['email'], $subject, $content );
     3389
     3390        if ( $switched_locale ) {
     3391                restore_previous_locale();
     3392        }
     3393
     3394        if ( ! $email_sent ) {
     3395                return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) );
     3396        }
     3397
     3398        return true;
    33803399}
    33813400
     
    34273446
    34283447        if ( ! $request ) {
    3429                 return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
     3448                return new WP_Error( 'invalid_request', __( 'Invalid request.' ) );
    34303449        }
    34313450
     
    35143533         * @var int
    35153534         */
    3516 
    35173535        public $user_id = 0;
    35183536
  • branches/4.9/tests/phpunit/data/languages/de_DE.po

    r38930 r43614  
    1 # Translation of 4.6.x in German
    2 # This file is distributed under the same license as the 4.6.x package.
     1# Translation of 4.9.x in German
     2# This file is distributed under the same license as the 4.9.x package.
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2016-10-25 18:27+0200\n"
     5"PO-Revision-Date: 2018-08-13 19:19+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 1.8.10\n"
    11 "Project-Id-Version: 4.6.x\n"
     10"X-Generator: Poedit 2.1.1\n"
     11"Project-Id-Version: Development (4.9.x)\n"
    1212"Language: de_DE\n"
     13"POT-Creation-Date: \n"
     14"Last-Translator: \n"
     15"Language-Team: \n"
    1316
    1417#. translators: Translate this to the correct language tag for your locale, see
     
    4144msgid "Update %s now"
    4245msgstr "Jetzt %s aktualisieren"
     46
     47#. translators: Privacy data request subject. 1: Site name, 2: Name of the action
     48#: wp-includes/user.php:3445
     49msgid "[%1$s] Confirm Action: %2$s"
     50msgstr "[%1$s] Aktion bestätigen: %2$s"
  • branches/4.9/tests/phpunit/data/languages/es_ES.po

    r38930 r43614  
    1 # Translation of Development (4.4.x) in Spanish (Spain)
    2 # This file is distributed under the same license as the Development (4.4.x) package.
     1# Translation of Development (4.9.x) in Spanish (Spain)
     2# This file is distributed under the same license as the Development (4.9.x) package.
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2016-10-25 18:28+0200\n"
     5"PO-Revision-Date: 2018-08-13 19:19+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 1.8.10\n"
    11 "Project-Id-Version: Development (4.4.x)\n"
     10"X-Generator: Poedit 2.1.1\n"
     11"Project-Id-Version: Development (4.9.x)\n"
    1212"Language: es_ES\n"
     13"POT-Creation-Date: \n"
     14"Last-Translator: \n"
     15"Language-Team: \n"
    1316
    1417#. translators: 'rtl' or 'ltr'. This sets the text direction for WordPress.
     
    3740msgid "(Currently set to: %s)"
    3841msgstr "(Actualmente fijado en: %s)"
     42
     43#. translators: Privacy data request subject. 1: Site name, 2: Name of the action
     44#: wp-includes/user.php:3445
     45msgid "[%1$s] Confirm Action: %2$s"
     46msgstr "[%1$s] Confirma la acción: %2$s"
  • branches/4.9/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    r43612 r43614  
    4040         * @since 4.9.6
    4141         */
    42         function setUp() {
     42        public function setUp() {
    4343                parent::setUp();
    4444                reset_phpmailer_instance();
     
    5050         * @since 4.9.6
    5151         */
    52         function tearDown() {
     52        public function tearDown() {
    5353                reset_phpmailer_instance();
    5454                parent::tearDown();
     
    9696                $email_sent = wp_privacy_send_personal_data_export_email( $request_id );
    9797                $this->assertWPError( $email_sent );
    98                 $this->assertSame( 'invalid', $email_sent->get_error_code() );
     98                $this->assertSame( 'invalid_request', $email_sent->get_error_code() );
    9999
    100100                $request_id = PHP_INT_MAX;
    101101                $email_sent = wp_privacy_send_personal_data_export_email( $request_id );
    102102                $this->assertWPError( $email_sent );
    103                 $this->assertSame( 'invalid', $email_sent->get_error_code() );
     103                $this->assertSame( 'invalid_request', $email_sent->get_error_code() );
    104104        }
    105105
     
    112112                add_filter( 'wp_mail_from', '__return_empty_string' ); // Cause `wp_mail()` to return false.
    113113                $email_sent = wp_privacy_send_personal_data_export_email( self::$request_id );
    114                 remove_filter( 'wp_mail_from', '__return_empty_string' );
    115114
    116115                $this->assertWPError( $email_sent );
    117                 $this->assertSame( 'error', $email_sent->get_error_code() );
     116                $this->assertSame( 'privacy_email_error', $email_sent->get_error_code() );
    118117        }
    119118
     
    126125                add_filter( 'wp_privacy_export_expiration', array( $this, 'modify_export_expiration' ) );
    127126                wp_privacy_send_personal_data_export_email( self::$request_id );
    128                 remove_filter( 'wp_privacy_export_expiration', array( $this, 'modify_export_expiration' ) );
    129127
    130128                $mailer = tests_retrieve_phpmailer_instance();
     
    153151                add_filter( 'wp_privacy_personal_data_email_content', array( $this, 'modify_email_content' ), 10, 2 );
    154152                wp_privacy_send_personal_data_export_email( self::$request_id );
    155                 remove_filter( 'wp_privacy_personal_data_email_content', array( $this, 'modify_email_content' ) );
    156153
    157154                $mailer = tests_retrieve_phpmailer_instance();
Note: See TracChangeset for help on using the changeset viewer.