WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2019 07:24:20 PM (8 weeks 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/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    r45063 r46265  
    176176
    177177    /**
     178     * The email address of the recipient of the personal data export notification should be filterable.
     179     *
     180     * @ticket 46303
     181     */
     182    public function test_email_address_of_recipient_should_be_filterable() {
     183        add_filter( 'wp_privacy_personal_data_email_to', array( $this, 'filter_email_address' ) );
     184        wp_privacy_send_personal_data_export_email( self::$request_id );
     185
     186        $mailer = tests_retrieve_phpmailer_instance();
     187
     188        $this->assertSame( 'modified-' . self::$requester_email, $mailer->get_recipient( 'to' )->address );
     189    }
     190
     191    /**
     192     * Filter callback that modifies the email address of the recipient of the personal data export notification.
     193     *
     194     * @since 5.3.0
     195     *
     196     * @param  string $user_email The email address of the notification recipient.
     197     * @return string $user_email The modified email address of the notification recipient.
     198     */
     199    public function filter_email_address( $user_email ) {
     200        return 'modified-' . $user_email;
     201    }
     202
     203    /**
     204     * The email subject of the personal data export notification should be filterable.
     205     *
     206     * @ticket 46303
     207     */
     208    public function test_email_subject_should_be_filterable() {
     209        add_filter( 'wp_privacy_personal_data_email_subject', array( $this, 'filter_email_subject' ) );
     210        wp_privacy_send_personal_data_export_email( self::$request_id );
     211
     212        $mailer = tests_retrieve_phpmailer_instance();
     213
     214        $this->assertSame( 'Modified subject', $mailer->get_sent()->subject );
     215    }
     216
     217    /**
     218     * Filter callback that modifies the email subject of the data erasure fulfillment notification.
     219     *
     220     * @since 5.3.0
     221     *
     222     * @param string $subject The email subject.
     223     * @return string $subject The email subject.
     224     */
     225    public function filter_email_subject( $subject ) {
     226        return 'Modified subject';
     227    }
     228
     229    /**
    178230     * The email content should be filterable.
    179231     *
     
    202254
    203255    /**
     256     * The email content should be filterable using the $email_data
     257     *
     258     * @ticket 46303
     259     */
     260    public function test_email_content_should_be_filterable_using_email_data() {
     261        add_filter( 'wp_privacy_personal_data_email_content', array( $this, 'modify_email_content_with_email_data' ), 10, 3 );
     262        wp_privacy_send_personal_data_export_email( self::$request_id );
     263
     264        $site_url = home_url();
     265        $mailer   = tests_retrieve_phpmailer_instance();
     266        $this->assertContains( 'Custom content using the $site_url of $email_data: ' . $site_url, $mailer->get_sent()->body );
     267    }
     268
     269    /**
     270     * Filter callback that modifies the text of the email by using the $email_data sent with a personal data export file.
     271     *
     272     * @since 5.3.0
     273     *
     274     * @param string $email_text Text in the email.
     275     * @param int    $request_id The request ID for this personal data export.
     276     * @param array  $email_data {
     277     *     Data relating to the account action email.
     278     *
     279     *     @type WP_User_Request $request           User request object.
     280     *     @type int             $expiration        The time in seconds until the export file expires.
     281     *     @type string          $expiration_date   The localized date and time when the export file expires.
     282     *     @type string          $message_recipient The address that the email will be sent to. Defaults
     283     *                                              to the value of `$request->email`, but can be changed
     284     *                                              by the `wp_privacy_personal_data_email_to` filter.
     285     *     @type string          $export_file_url   The export file URL.
     286     *     @type string          $sitename          The site name sending the mail.
     287     *     @type string          $siteurl           The site URL sending the mail.
     288     * }
     289     *
     290     * @return string $email_text Text in the email.
     291     */
     292    public function modify_email_content_with_email_data( $email_text, $request_id, $email_data ) {
     293        return 'Custom content using the $site_url of $email_data: ' . $email_data['siteurl'];
     294    }
     295
     296    /**
    204297     * The function should respect the user locale settings when the site uses the default locale.
    205298     *
Note: See TracChangeset for help on using the changeset viewer.