WordPress.org

Make WordPress Core

Ticket #46303: 46303.5.diff

File 46303.5.diff, 9.7 KB (added by garrett-eclipse, 22 months ago)

Adjusted the phpdoc to codequote the $email_data variable.

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

     
    493493        $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    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        $subject = sprintf(
     522                /* translators: %s: Site name. */
     523                __( '[%s] Personal Data Export' ),
     524                $site_name
     525        );
     526
     527        /**
     528         * Filters the subject of the email sent when an export request is completed.
     529         *
     530         * @since 5.3.0
     531         *
     532         * @param string $subject    The email subject.
     533         * @param string $sitename   The name of the site.
     534         * @param array  $email_data {
     535         *     Data relating to the account action email.
     536         *
     537         *     @type WP_User_Request $request           User request object.
     538         *     @type int             $expiration        The time in seconds until the export file expires.
     539         *     @type string          $expiration_date   The localized date and time when the export file expires.
     540         *     @type string          $message_recipient The address that the email will be sent to. Defaults
     541         *                                              to the value of `$request->email`, but can be changed
     542         *                                              by the `wp_privacy_personal_data_email_to` filter.
     543         *     @type string          $export_file_url   The export file URL.
     544         *     @type string          $sitename          The site name sending the mail.
     545         *     @type string          $siteurl           The site URL sending the mail.
     546         * }
     547         */
     548        $subject = apply_filters( 'wp_privacy_personal_data_email_subject', $subject, $site_name, $email_data );
     549
    496550        /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
    497551        $email_text = __(
    498552                'Howdy,
     
    519573         * ###SITEURL###            The URL to the site.
    520574         *
    521575         * @since 4.9.6
     576         * @since 5.3.0 Introduced the `$email_data` array.
    522577         *
    523          * @param string $email_text     Text in the email.
    524          * @param int    $request_id     The request ID for this personal data export.
     578         * @param string $email_text Text in the email.
     579         * @param int    $request_id The request ID for this personal data export.
     580         * @param array  $email_data {
     581         *     Data relating to the account action email.
     582         *
     583         *     @type WP_User_Request $request           User request object.
     584         *     @type int             $expiration        The time in seconds until the export file expires.
     585         *     @type string          $expiration_date   The localized date and time when the export file expires.
     586         *     @type string          $message_recipient The address that the email will be sent to. Defaults
     587         *                                              to the value of `$request->email`, but can be changed
     588         *                                              by the `wp_privacy_personal_data_email_to` filter.
     589         *     @type string          $export_file_url   The export file URL.
     590         *     @type string          $sitename          The site name sending the mail.
     591         *     @type string          $siteurl           The site URL sending the mail.
    525592         */
    526         $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
     593        $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $email_data );
    527594
    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();
    532 
    533595        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    534596        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    535         $content = str_replace( '###EMAIL###', $email_address, $content );
     597        $content = str_replace( '###EMAIL###', $request_email, $content );
    536598        $content = str_replace( '###SITENAME###', $site_name, $content );
    537599        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    538600
    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         );
     601        $mail_success = wp_mail( $request_email, $subject, $content );
    548602
    549603        if ( $switched_locale ) {
    550604                restore_previous_locale();
  • tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php

     
    175175        }
    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         *
    180232         * @since 4.9.6
     
    201253        }
    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         *
    206299         * @since 5.2.0