WordPress.org

Make WordPress Core

Ticket #44501: 44501.3.diff

File 44501.3.diff, 12.5 KB (added by xkon, 10 months ago)

minor edit - correcting the descriptions of unit tests

  • src/wp-admin/includes/privacy-tools.php

    diff --git a/src/wp-admin/includes/privacy-tools.php b/src/wp-admin/includes/privacy-tools.php
    index efe46cce32..da05163a33 100644
    a b All at ###SITENAME### 
    595595        $content = str_replace( '###SITENAME###', $site_name, $content );
    596596        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    597597
    598         $mail_success = wp_mail( $request_email, $subject, $content );
     598        $headers = '';
     599
     600        /**
     601         * Filters the headers of the email sent with a personal data export file.
     602         *
     603         * @since 5.4.0
     604         *
     605         * @param string|array $headers    The email headers.
     606         * @param string       $subject    The email subject.
     607         * @param string       $content    The email content.
     608         * @param int          $request_id The request ID.
     609         * @param array        $email_data {
     610         *     Data relating to the account action email.
     611         *
     612         *     @type WP_User_Request $request           User request object.
     613         *     @type int             $expiration        The time in seconds until the export file expires.
     614         *     @type string          $expiration_date   The localized date and time when the export file expires.
     615         *     @type string          $message_recipient The address that the email will be sent to. Defaults
     616         *                                              to the value of `$request->email`, but can be changed
     617         *                                              by the `wp_privacy_personal_data_email_to` filter.
     618         *     @type string          $export_file_url   The export file URL.
     619         *     @type string          $sitename          The site name sending the mail.
     620         *     @type string          $siteurl           The site URL sending the mail.
     621         * }
     622         */
     623        $headers = apply_filters( 'wp_privacy_personal_data_email_headers', $headers, $subject, $content, $request_id, $email_data );
     624
     625        $mail_success = wp_mail( $request_email, $subject, $content, $headers );
    599626
    600627        if ( $switched_locale ) {
    601628                restore_previous_locale();
  • src/wp-includes/user.php

    diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
    index a1478679f6..f5c611ebec 100644
    a b All at ###SITENAME### 
    31783178         */
    31793179        $subject = apply_filters( 'user_request_confirmed_email_subject', $subject, $email_data['sitename'], $email_data );
    31803180
    3181         $email_sent = wp_mail( $email_data['admin_email'], $subject, $content );
     3181        $headers = '';
     3182
     3183        /**
     3184         * Filters the headers of the user request confirmation email.
     3185         *
     3186         * @since 5.4.0
     3187         *
     3188         * @param string|array $headers    The email headers.
     3189         * @param string       $subject    The email subject.
     3190         * @param string       $email_text The email content.
     3191         * @param int          $request_id The request ID.
     3192         * @param array        $email_data {
     3193         *     Data relating to the account action email.
     3194         *
     3195         *     @type WP_User_Request $request     User request object.
     3196         *     @type string          $email       The email address this is being sent to.
     3197         *     @type string          $description Description of the action being performed so the user knows what the email is for.
     3198         *     @type string          $confirm_url The link to click on to confirm the account action.
     3199         *     @type string          $sitename    The site name sending the mail.
     3200         *     @type string          $siteurl     The site URL sending the mail.
     3201         * }
     3202         */
     3203        $headers = apply_filters( 'user_request_confirmed_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3204
     3205        $email_sent = wp_mail( $email_data['admin_email'], $subject, $content, $headers );
    31823206
    31833207        if ( $email_sent ) {
    31843208                update_post_meta( $request_id, '_wp_admin_notified', true );
    All at ###SITENAME### 
    33243348        $content = str_replace( '###PRIVACY_POLICY_URL###', $email_data['privacy_policy_url'], $content );
    33253349        $content = str_replace( '###SITEURL###', esc_url_raw( $email_data['siteurl'] ), $content );
    33263350
    3327         $email_sent = wp_mail( $user_email, $subject, $content );
     3351        $headers = '';
     3352
     3353        /**
     3354         * Filters the headers of the user request confirmation email.
     3355         *
     3356         * @since 5.4.0
     3357         *
     3358         * @param string|array $headers    The email headers.
     3359         * @param string       $subject    The email subject.
     3360         * @param string       $content    The email content.
     3361         * @param int          $request_id The request ID.
     3362         * @param array        $email_data {
     3363         *     Data relating to the account action email.
     3364         *
     3365         *     @type WP_User_Request $request     User request object.
     3366         *     @type string          $email       The email address this is being sent to.
     3367         *     @type string          $description Description of the action being performed so the user knows what the email is for.
     3368         *     @type string          $confirm_url The link to click on to confirm the account action.
     3369         *     @type string          $sitename    The site name sending the mail.
     3370         *     @type string          $siteurl     The site URL sending the mail.
     3371         * }
     3372         */
     3373        $headers = apply_filters( 'user_erasure_complete_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3374
     3375        $email_sent = wp_mail( $user_email, $subject, $content, $headers );
    33283376
    33293377        if ( $switched_locale ) {
    33303378                restore_previous_locale();
    All at ###SITENAME### 
    35863634         */
    35873635        $subject = apply_filters( 'user_request_action_email_subject', $subject, $email_data['sitename'], $email_data );
    35883636
    3589         $email_sent = wp_mail( $email_data['email'], $subject, $content );
     3637        $headers = '';
     3638
     3639        /**
     3640         * Filters the headers of the email sent when an account action is attempted.
     3641         *
     3642         * @since 5.4.0
     3643         *
     3644         * @param string|array $headers    The email headers.
     3645         * @param string       $subject    The email subject.
     3646         * @param string       $email_text The email content.
     3647         * @param int          $request_id The request ID.
     3648         * @param array        $email_data {
     3649         *     Data relating to the account action email.
     3650         *
     3651         *     @type WP_User_Request $request     User request object.
     3652         *     @type string          $email       The email address this is being sent to.
     3653         *     @type string          $description Description of the action being performed so the user knows what the email is for.
     3654         *     @type string          $confirm_url The link to click on to confirm the account action.
     3655         *     @type string          $sitename    The site name sending the mail.
     3656         *     @type string          $siteurl     The site URL sending the mail.
     3657         * }
     3658         */
     3659        $headers = apply_filters( 'user_request_action_email_headers', $headers, $subject, $content, $request_id, $email_data );
     3660
     3661        $email_sent = wp_mail( $email_data['email'], $subject, $content, $headers );
    35903662
    35913663        if ( $switched_locale ) {
    35923664                restore_previous_locale();
  • tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php

    diff --git a/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php
    index 01c90ae3bc..5a2b1c62a4 100644
    a b class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT 
    256256                return 'Modified text';
    257257        }
    258258
     259        /**
     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
    259291        /**
    260292         * The function should not send an email when the request ID does not exist.
    261293         *
  • tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

    diff --git a/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php b/tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php
    index 13ee61a59d..f5fa6b4145 100644
    a b class Tests_Privacy_WpPrivacySendPersonalDataExportEmail extends WP_UnitTestCase 
    252252                return 'Custom content for request ID: ' . $request_id;
    253253        }
    254254
     255        /**
     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
    255287        /**
    256288         * The email content should be filterable using the $email_data
    257289         *
  • tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php

    diff --git a/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php b/tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php
    index 09aa8305a5..6f50c2226d 100644
    a b class Tests_User_WpPrivacySendRequestConfirmationNotification extends WP_UnitTes 
    207207                return $email_text;
    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}
  • tests/phpunit/tests/user/wpSendUserRequest.php

    diff --git a/tests/phpunit/tests/user/wpSendUserRequest.php b/tests/phpunit/tests/user/wpSendUserRequest.php
    index 2ccbe19e28..3f240545fc 100644
    a b class Tests_User_WpSendUserRequest extends WP_UnitTestCase { 
    228228                return 'Custom Email Content.';
    229229        }
    230230
     231        /**
     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
    231265        /**
    232266         * The function should error when the email was not sent.
    233267         *