Make WordPress Core

Ticket #44133: 44133.3.diff

File 44133.3.diff, 5.4 KB (added by birgire, 6 years ago)
  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index 4535684..696e5bb 100644
    function wp_privacy_generate_personal_data_export_file( $request_id ) { 
    21832183}
    21842184
    21852185/**
    2186  * Send an email to the user with a link to the personal data export file
     2186 * Send an email to the user with a link to the personal data export file.
    21872187 *
    2188  * @since 4.9.6
     2188 * The link to the export file is only included in the content of the email,
     2189 * if any personal data is exported.
    21892190 *
    2190  * @param int $request_id The request ID for this personal data export.
    2191  * @return true|WP_Error True on success or `WP_Error` on failure.
     2191 * @since 4.9.7
     2192 *
     2193 * @param  int           $request_id       The request ID for this personal data export.
     2194 * @param  bool          $has_export_data  Whether there is any personal data to export.
     2195 * @return true|WP_Error                   True on success or `WP_Error` on failure.
    21922196 */
    2193 function wp_privacy_send_personal_data_export_email( $request_id ) {
     2197function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) {
    21942198        // Get the request data.
    21952199        $request = wp_get_user_request_data( $request_id );
    21962200
    function wp_privacy_send_personal_data_export_email( $request_id ) { 
    22022206        $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    22032207        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    22042208
    2205 /* translators: Do not translate EXPIRATION, LINK, EMAIL, SITENAME, SITEURL: those are placeholders. */
    2206 $email_text = __(
    2207 'Howdy,
     2209        if ( $has_export_data ) {
     2210
     2211                /* translators: Do not translate EXPIRATION, LINK, EMAIL, SITENAME, SITEURL: those are placeholders. */
     2212                $email_text = __(
     2213                        'Howdy,
    22082214
    22092215Your request for an export of personal data has been completed. You may
    22102216download your personal data by clicking on the link below. For privacy
    This email has been sent to ###EMAIL###. 
    22182224Regards,
    22192225All at ###SITENAME###
    22202226###SITEURL###'
    2221 );
     2227                );
     2228
     2229        } else {
     2230
     2231                /* translators: Do not translate EMAIL, SITENAME, SITEURL: those are placeholders. */
     2232                $email_text = __(
     2233                        'Howdy,
     2234
     2235Your request for an export of personal data has been completed.
     2236
     2237No personal data was found.
     2238
     2239This email has been sent to ###EMAIL###.
     2240
     2241Regards,
     2242All at ###SITENAME###
     2243###SITEURL###'
     2244                );
     2245        }
    22222246
    22232247        /**
    22242248         * Filters the text of the email sent with a personal data export file.
    All at ###SITENAME### 
    22322256         *
    22332257         * @since 4.9.6
    22342258         *
    2235          * @param string $email_text     Text in the email.
    2236          * @param int    $request_id     The request ID for this personal data export.
     2259         * @param string $email_text      Text in the email.
     2260         * @param int    $request_id      The request ID for this personal data export.
     2261         * @param bool   $has_export_data Whether there is any personal data to export.
    22372262         */
    2238         $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
     2263        $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
    22392264
    2240         $email_address = $request->email;
     2265        $email_address   = $request->email;
    22412266        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    2242         $site_name = is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' );
    2243         $site_url = network_home_url();
     2267        $site_name       = is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' );
     2268        $site_url        = network_home_url();
    22442269
    22452270        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    22462271        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    All at ###SITENAME### 
    22512276        $mail_success = wp_mail(
    22522277                $email_address,
    22532278                sprintf(
     2279                        /* translators: %s Site name. */
    22542280                        __( '[%s] Personal Data Export' ),
    22552281                        wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
    22562282                ),
    function wp_privacy_process_personal_data_export_page( $response, $exporter_inde 
    23562382        delete_post_meta( $request_id, '_export_data_raw' );
    23572383        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23582384
    2359         /**
    2360          * Generate the export file from the collected, grouped personal data.
    2361          *
    2362          * @since 4.9.6
    2363          *
    2364          * @param int $request_id The export request ID.
    2365          */
    2366         do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2385        $has_export_data = ! empty( $groups );
     2386
     2387        if ( $has_export_data ) {
     2388
     2389                /**
     2390                * Generate the export file from the collected, grouped personal data.
     2391                *
     2392                * @since 4.9.6
     2393                *
     2394                * @param int $request_id The export request ID.
     2395                */
     2396                do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2397        }
    23672398
    23682399        // Clear the grouped data now that it is no longer needed.
    23692400        delete_post_meta( $request_id, '_export_data_grouped' );
    23702401
    23712402        // If the destination is email, send it now.
    23722403        if ( $send_as_email ) {
    2373                 $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
     2404                $mail_success = wp_privacy_send_personal_data_export_email( $request_id, $has_export_data );
    23742405                if ( is_wp_error( $mail_success ) ) {
    23752406                        wp_send_json_error( $mail_success->get_error_message() );
    23762407                }
    2377         } else {
     2408        } elseif ( $has_export_data ) {
    23782409                // Modify the response to include the URL of the export file so the browser can fetch it.
    23792410                $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    23802411                if ( ! empty( $export_file_url ) ) {