Make WordPress Core

Changeset 47279


Ignore:
Timestamp:
02/11/2020 09:41:26 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Introduce filters for the headers of all the privacy-related e-mails:

  • wp_privacy_personal_data_email_headers
  • user_request_confirmed_email_headers
  • user_erasure_complete_email_headers
  • user_request_action_email_headers

Props xkon, garrett-eclipse, zaffarn, desrosj.
Fixes #44501.

Location:
trunk
Files:
7 edited

Legend:

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

    r47278 r47279  
    659659        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    660660
    661         $mail_success = wp_mail( $request_email, $subject, $content );
     661        $headers = '';
     662
     663        /**
     664         * Filters the headers of the email sent with a personal data export file.
     665         *
     666         * @since 5.4.0
     667         *
     668         * @param string|array $headers    The email headers.
     669         * @param string       $subject    The email subject.
     670         * @param string       $content    The email content.
     671         * @param int          $request_id The request ID.
     672         * @param array        $email_data {
     673         *     Data relating to the account action email.
     674         *
     675         *     @type WP_User_Request $request           User request object.
     676         *     @type int             $expiration        The time in seconds until the export file expires.
     677         *     @type string          $expiration_date   The localized date and time when the export file expires.
     678         *     @type string          $message_recipient The address that the email will be sent to. Defaults
     679         *                                              to the value of `$request->email`, but can be changed
     680         *                                              by the `wp_privacy_personal_data_email_to` filter.
     681         *     @type string          $export_file_url   The export file URL.
     682         *     @type string          $sitename          The site name sending the mail.
     683         *     @type string          $siteurl           The site URL sending the mail.
     684         * }
     685         */
     686        $headers = apply_filters( 'wp_privacy_personal_data_email_headers', $headers, $subject, $content, $request_id, $email_data );
     687
     688        $mail_success = wp_mail( $request_email, $subject, $content, $headers );
    662689
    663690        if ( $switched_locale ) {
  • trunk/src/wp-includes/user.php

    r47277 r47279  
    32953295        $subject = apply_filters( 'user_request_confirmed_email_subject', $subject, $email_data['sitename'], $email_data );
    32963296
    3297         $email_sent = wp_mail( $email_data['admin_email'], $subject, $content );
     3297        $headers = '';
     3298
     3299        /**
     3300         * Filters the headers of the user request confirmation email.
     3301         *
     3302         * @since 5.4.0
     3303         *
     3304         * @param string|array $headers    The email headers.
     3305         * @param string       $subject    The email subject.
     3306         * @param string       $content    The email content.
     3307         * @param int          $request_id The request ID.
     3308         * @param array        $email_data {
     3309         *     Data relating to the account action email.
     3310         *
     3311         *     @type WP_User_Request $request     User request object.
     3312         *     @type string          $user_email  The email address confirming a request
     3313         *     @type string          $description Description of the action being performed so the user knows what the email is for.
     3314         *     @type string          $manage_url  The link to click manage privacy requests of this type.
     3315         *     @type string          $sitename    The site name sending the mail.
     3316         *     @type string          $siteurl     The site URL sending the mail.
     3317         *     @type string          $admin_email The administrator email receiving the mail.
     3318         * }
     3319         */
     3320        $headers = apply_filters( 'user_request_confirmed_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3321
     3322        $email_sent = wp_mail( $email_data['admin_email'], $subject, $content, $headers );
    32983323
    32993324        if ( $email_sent ) {
     
    34413466        $content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content );
    34423467
    3443         $email_sent = wp_mail( $user_email, $subject, $content );
     3468        $headers = '';
     3469
     3470        /**
     3471         * Filters the headers of the data erasure fulfillment notification.
     3472         *
     3473         * @since 5.4.0
     3474         *
     3475         * @param string|array $headers    The email headers.
     3476         * @param string       $subject    The email subject.
     3477         * @param string       $content    The email content.
     3478         * @param int          $request_id The request ID.
     3479         * @param array        $email_data {
     3480         *     Data relating to the account action email.
     3481         *
     3482         *     @type WP_User_Request $request            User request object.
     3483         *     @type string          $message_recipient  The address that the email will be sent to. Defaults
     3484         *                                               to the value of `$request->email`, but can be changed
     3485         *                                               by the `user_erasure_fulfillment_email_to` filter.
     3486         *     @type string          $privacy_policy_url Privacy policy URL.
     3487         *     @type string          $sitename           The site name sending the mail.
     3488         *     @type string          $siteurl            The site URL sending the mail.
     3489         * }
     3490         */
     3491        $headers = apply_filters( 'user_erasure_complete_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3492
     3493        $email_sent = wp_mail( $user_email, $subject, $content, $headers );
    34443494
    34453495        if ( $switched_locale ) {
     
    37033753        $subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data );
    37043754
    3705         $email_sent = wp_mail( $email_data['email'], $subject, $content );
     3755        $headers = '';
     3756
     3757        /**
     3758         * Filters the headers of the email sent when an account action is attempted.
     3759         *
     3760         * @since 5.4.0
     3761         *
     3762         * @param string|array $headers    The email headers.
     3763         * @param string       $subject    The email subject.
     3764         * @param string       $content    The email content.
     3765         * @param int          $request_id The request ID.
     3766         * @param array        $email_data {
     3767         *     Data relating to the account action email.
     3768         *
     3769         *     @type WP_User_Request $request     User request object.
     3770         *     @type string          $email       The email address this is being sent to.
     3771         *     @type string          $description Description of the action being performed so the user knows what the email is for.
     3772         *     @type string          $confirm_url The link to click on to confirm the account action.
     3773         *     @type string          $sitename    The site name sending the mail.
     3774         *     @type string          $siteurl     The site URL sending the mail.
     3775         * }
     3776         */
     3777        $headers = apply_filters( 'user_request_action_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3778
     3779        $email_sent = wp_mail( $email_data['email'], $subject, $content, $headers );
    37063780
    37073781        if ( $switched_locale ) {
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php

    r46586 r47279  
    258258
    259259        /**
     260         * The email headers of the fulfillment notification should be filterable.
     261         *
     262         * @since 5.4.0
     263         *
     264         * @ticket 44501
     265         */
     266        public function test_email_headers_should_be_filterable() {
     267                add_filter( 'user_erasure_complete_email_headers', array( $this, 'modify_email_headers' ) );
     268                _wp_privacy_send_erasure_fulfillment_notification( self::$request_id );
     269
     270                $mailer = tests_retrieve_phpmailer_instance();
     271
     272                $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     273        }
     274
     275        /**
     276         * Filter callback that modifies the email headers of the data erasure fulfillment notification.
     277         *
     278         * @since 5.4.0
     279         *
     280         * @param string|array $headers The email headers.
     281         * @return array       $headers The new email headers.
     282         */
     283        public function modify_email_headers( $headers ) {
     284                $headers = array(
     285                        'From: Tester <tester@example.com>',
     286                );
     287
     288                return $headers;
     289        }
     290
     291        /**
    260292         * The function should not send an email when the request ID does not exist.
    261293         *
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    r47144 r47279  
    254254
    255255        /**
     256         * The email headers should be filterable.
     257         *
     258         * @since 5.4.0
     259         *
     260         * @ticket 44501
     261         */
     262        public function test_email_headers_should_be_filterable() {
     263                add_filter( 'wp_privacy_personal_data_email_headers', array( $this, 'modify_email_headers' ) );
     264                wp_privacy_send_personal_data_export_email( self::$request_id );
     265
     266                $mailer = tests_retrieve_phpmailer_instance();
     267
     268                $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     269        }
     270
     271        /**
     272         * Filter callback to modify the headers of the email sent with a personal data export file.
     273         *
     274         * @since 5.4.0
     275         *
     276         * @param string|array $headers The email headers.
     277         * @return array       $headers The new email headers.
     278         */
     279        public function modify_email_headers( $headers ) {
     280                $headers = array(
     281                        'From: Tester <tester@example.com>',
     282                );
     283
     284                return $headers;
     285        }
     286
     287        /**
    256288         * The email content should be filterable using the $email_data
    257289         *
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php

    r47246 r47279  
    208208        }
    209209
     210        /**
     211         * The email headers should be filterable.
     212         *
     213         * @since 5.4.0
     214         *
     215         * @ticket 44501
     216         */
     217        public function test_email_headers_should_be_filterable() {
     218                $email      = 'export.request.from.unregistered.user@example.com';
     219                $request_id = wp_create_user_request( $email, 'export_personal_data' );
     220
     221                _wp_privacy_account_request_confirmed( $request_id );
     222
     223                add_filter( 'user_request_confirmed_email_headers', array( $this, 'modify_email_headers' ) );
     224                _wp_privacy_send_request_confirmation_notification( $request_id );
     225                remove_filter( 'user_request_confirmed_email_headers', array( $this, 'modify_email_headers' ) );
     226
     227                $mailer = tests_retrieve_phpmailer_instance();
     228
     229                $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     230        }
     231
     232        /**
     233         * Filter callback that modifies the headers of the user request confirmation email.
     234         *
     235         * @since 5.4.0
     236         *
     237         * @param string|array $headers The email headers.
     238         * @return array       $headers The new email headers.
     239         */
     240        public function modify_email_headers( $headers ) {
     241                $headers = array(
     242                        'From: Tester <tester@example.com>',
     243                );
     244
     245                return $headers;
     246        }
     247
    210248}
  • trunk/tests/phpunit/tests/user.php

    r47270 r47279  
    17991799         * Testing the `wp_privacy_additional_user_profile_data` filter works.
    18001800         *
     1801         * @since 5.4.0
     1802         *
    18011803         * @ticket 47509
    18021804         */
     
    18821884         * Filter callback to add additional profile data to the User Group on Export Requests.
    18831885         *
     1886         * @since 5.4.0
     1887         *
    18841888         * @ticket 47509
    18851889         *
     
    19021906         *
    19031907         * This callback should generate a `_doing_it_wrong()`.
     1908         *
     1909         * @since 5.4.0
    19041910         *
    19051911         * @ticket 47509
  • trunk/tests/phpunit/tests/user/wpSendUserRequest.php

    r46586 r47279  
    230230
    231231        /**
     232         * The email headers should be filterable.
     233         *
     234         * @since 5.4.0
     235         *
     236         * @ticket 44501
     237         */
     238        public function test_email_headers_should_be_filterable() {
     239                $request_id = wp_create_user_request( self::$test_user->user_email, 'remove_personal_data' );
     240
     241                add_filter( 'user_request_action_email_headers', array( $this, 'modify_email_headers' ) );
     242                $result = wp_send_user_request( $request_id );
     243
     244                $mailer = tests_retrieve_phpmailer_instance();
     245
     246                $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     247        }
     248
     249        /**
     250         * Filter callback to modify the headers of the email sent when an account action is attempted.
     251         *
     252         * @since 5.4.0
     253         *
     254         * @param string|array $headers The email headers.
     255         * @return array       $headers The new email headers.
     256         */
     257        public function modify_email_headers( $headers ) {
     258                $headers = array(
     259                        'From: Tester <tester@example.com>',
     260                );
     261
     262                return $headers;
     263        }
     264
     265        /**
    232266         * The function should error when the email was not sent.
    233267         *
Note: See TracChangeset for help on using the changeset viewer.