WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/03/2018 09:00:16 PM (16 months 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • 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
Note: See TracChangeset for help on using the changeset viewer.