WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/13/2018 04:31:31 PM (13 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.
Fixes #43985.

File:
1 edited

Legend:

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

    r43477 r43568  
    33583358 *
    33593359 * @param string $request_id ID of the request created via wp_create_user_request().
    3360  * @return WP_Error|bool Will return true/false based on the success of sending the email, or a WP_Error object.
     3360 * @return bool|WP_Error True on success, `WP_Error` on failure.
    33613361 */
    33623362function wp_send_user_request( $request_id ) {
     
    33653365
    33663366    if ( ! $request ) {
    3367         return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
    3368     }
     3367        return new WP_Error( 'invalid_request', __( 'Invalid user request.' ) );
     3368    }
     3369
     3370    // Localize message content for user; fallback to site default for visitors.
     3371    if ( ! empty( $request->user_id ) ) {
     3372        $locale = get_user_locale( $request->user_id );
     3373    } else {
     3374        $locale = get_locale();
     3375    }
     3376
     3377    $switched_locale = switch_to_locale( $locale );
    33693378
    33703379    $email_data = array(
     
    34553464    $subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data );
    34563465
    3457     return wp_mail( $email_data['email'], $subject, $content );
     3466    $email_sent = wp_mail( $email_data['email'], $subject, $content );
     3467
     3468    if ( $switched_locale ) {
     3469        restore_previous_locale();
     3470    }
     3471
     3472    if ( ! $email_sent ) {
     3473        return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) );
     3474    }
     3475
     3476    return true;
    34583477}
    34593478
     
    35053524
    35063525    if ( ! $request ) {
    3507         return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
     3526        return new WP_Error( 'invalid_request', __( 'Invalid request.' ) );
    35083527    }
    35093528
     
    35923611     * @var int
    35933612     */
    3594 
    35953613    public $user_id = 0;
    35963614
Note: See TracChangeset for help on using the changeset viewer.