WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2019 07:24:20 PM (2 months ago)
Author:
SergeyBiryukov
Message:

Privacy: Introduce wp_privacy_personal_data_email_to and wp_privacy_personal_data_email_subject filters.

Pass email data to the wp_privacy_personal_data_email_content filter.

Props garrett-eclipse, thakkarhardik, birgire.
Fixes #46303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/privacy-tools.php

    r46209 r46265  
    494494    $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    495495
     496    $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
     497    $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     498    $site_url        = home_url();
     499
     500    /**
     501     * Filters the recipient of the personal data export email notification.
     502     * Should be used with great caution to avoid sending the data export link to wrong emails.
     503     *
     504     * @since 5.3.0
     505     *
     506     * @param string          $request_email The email address of the notification recipient.
     507     * @param WP_User_Request $request       The request that is initiating the notification.
     508     */
     509    $request_email = apply_filters( 'wp_privacy_personal_data_email_to', $request->email, $request );
     510
     511    $email_data = array(
     512        'request'           => $request,
     513        'expiration'        => $expiration,
     514        'expiration_date'   => $expiration_date,
     515        'message_recipient' => $request_email,
     516        'export_file_url'   => $export_file_url,
     517        'sitename'          => $site_name,
     518        'siteurl'           => $site_url,
     519    );
     520
     521    /* translators: Personal data export notification email subject. %s: Site title. */
     522    $subject = sprintf( __( '[%s] Personal Data Export' ), $site_name );
     523
     524    /**
     525     * Filters the subject of the email sent when an export request is completed.
     526     *
     527     * @since 5.3.0
     528     *
     529     * @param string $subject    The email subject.
     530     * @param string $sitename   The name of the site.
     531     * @param array  $email_data {
     532     *     Data relating to the account action email.
     533     *
     534     *     @type WP_User_Request $request           User request object.
     535     *     @type int             $expiration        The time in seconds until the export file expires.
     536     *     @type string          $expiration_date   The localized date and time when the export file expires.
     537     *     @type string          $message_recipient The address that the email will be sent to. Defaults
     538     *                                              to the value of `$request->email`, but can be changed
     539     *                                              by the `wp_privacy_personal_data_email_to` filter.
     540     *     @type string          $export_file_url   The export file URL.
     541     *     @type string          $sitename          The site name sending the mail.
     542     *     @type string          $siteurl           The site URL sending the mail.
     543     * }
     544     */
     545    $subject = apply_filters( 'wp_privacy_personal_data_email_subject', $subject, $site_name, $email_data );
     546
    496547    /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
    497548    $email_text = __(
     
    520571     *
    521572     * @since 4.9.6
    522      *
    523      * @param string $email_text     Text in the email.
    524      * @param int    $request_id     The request ID for this personal data export.
     573     * @since 5.3.0 Introduced the `$email_data` array.
     574     *
     575     * @param string $email_text Text in the email.
     576     * @param int    $request_id The request ID for this personal data export.
     577     * @param array  $email_data {
     578     *     Data relating to the account action email.
     579     *
     580     *     @type WP_User_Request $request           User request object.
     581     *     @type int             $expiration        The time in seconds until the export file expires.
     582     *     @type string          $expiration_date   The localized date and time when the export file expires.
     583     *     @type string          $message_recipient The address that the email will be sent to. Defaults
     584     *                                              to the value of `$request->email`, but can be changed
     585     *                                              by the `wp_privacy_personal_data_email_to` filter.
     586     *     @type string          $export_file_url   The export file URL.
     587     *     @type string          $sitename          The site name sending the mail.
     588     *     @type string          $siteurl           The site URL sending the mail.
    525589     */
    526     $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
    527 
    528     $email_address   = $request->email;
    529     $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    530     $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    531     $site_url        = home_url();
     590    $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $email_data );
    532591
    533592    $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    534593    $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    535     $content = str_replace( '###EMAIL###', $email_address, $content );
     594    $content = str_replace( '###EMAIL###', $request_email, $content );
    536595    $content = str_replace( '###SITENAME###', $site_name, $content );
    537596    $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    538597
    539     $mail_success = wp_mail(
    540         $email_address,
    541         sprintf(
    542             /* translators: Personal data export notification email subject. %s: Site title. */
    543             __( '[%s] Personal Data Export' ),
    544             $site_name
    545         ),
    546         $content
    547     );
     598    $mail_success = wp_mail( $request_email, $subject, $content );
    548599
    549600    if ( $switched_locale ) {
Note: See TracChangeset for help on using the changeset viewer.