Make WordPress Core

Ticket #44133: 44133.2.diff

File 44133.2.diff, 4.2 KB (added by birgire, 7 years ago)
  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index b00752e..f35aa0b 100644
    function wp_privacy_generate_personal_data_export_file( $request_id ) { 
    21842184}
    21852185
    21862186/**
    2187  * Send an email to the user with a link to the personal data export file
     2187 * Send an email to the user with a link to the personal data export file, if available.
    21882188 *
    21892189 * @since 4.9.6
    21902190 *
    2191  * @param int  $request_id  The request ID for this personal data export.
    2192  * @return true|WP_Error    True on success or `WP_Error` on failure.
     2191 * @param  int           $request_id       The request ID for this personal data export.
     2192 * @param  bool          $has_export_data  Whether there is any personal data to export.
     2193 * @return true|WP_Error                   True on success or `WP_Error` on failure.
    21932194 */
    2194 function wp_privacy_send_personal_data_export_email( $request_id ) {
     2195function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) {
    21952196        // Get the request data.
    21962197        $request = wp_get_user_request_data( $request_id );
    21972198
    function wp_privacy_send_personal_data_export_email( $request_id ) { 
    22032204        $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    22042205        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    22052206
    2206 /* translators: Do not translate EXPIRATION, LINK, EMAIL, SITENAME, SITEURL: those are placeholders. */
    2207 $email_text = __(
     2207        if ( $has_export_data ) {
     2208
     2209                /* translators: Do not translate EXPIRATION, LINK, EMAIL, SITENAME, SITEURL: those are placeholders. */
     2210        $email_text = __(
    22082211'Howdy,
    22092212
    22102213Your request for an export of personal data has been completed. You may
    All at ###SITENAME### 
    22212224###SITEURL###'
    22222225);
    22232226
     2227        } else {
     2228
     2229                /* translators: Do not translate EMAIL, SITENAME, SITEURL: those are placeholders. */
     2230                $email_text = __(
     2231'Howdy,
     2232
     2233Your request for an export of personal data has been completed.
     2234
     2235No personal data was found.
     2236
     2237This email has been sent to ###EMAIL###.
     2238
     2239Regards,
     2240All at ###SITENAME###
     2241###SITEURL###'
     2242);
     2243        }
     2244
    22242245        /**
    22252246         * Filters the text of the email sent with a personal data export file.
    22262247         *
    All at ###SITENAME### 
    22332254         *
    22342255         * @since 4.9.6
    22352256         *
    2236          * @param string $email_text     Text in the email.
    2237          * @param int    $request_id     The request ID for this personal data export.
     2257         * @param string $email_text      Text in the email.
     2258         * @param int    $request_id      The request ID for this personal data export.
     2259         * @param  bool  $has_export_data Whether there is any personal data to export.
    22382260         */
    2239         $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
     2261        $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
    22402262
    22412263        $email_address = $request->email;
    22422264        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    function wp_privacy_process_personal_data_export_page( $response, $exporter_inde 
    23562378        delete_post_meta( $request_id, '_export_data_raw' );
    23572379        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23582380
    2359         // Generate the export file from the collected, grouped personal data.
    2360         do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2381        $has_export_data = ! empty( $groups );
     2382
     2383        if ( $has_export_data ) {
     2384                // Generate the export file from the collected, grouped personal data.
     2385                do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2386        }
    23612387
    23622388        // Clear the grouped data now that it is no longer needed.
    23632389        delete_post_meta( $request_id, '_export_data_grouped' );
    23642390
    23652391        // If the destination is email, send it now.
    23662392        if ( $send_as_email ) {
    2367                 $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
     2393                $mail_success = wp_privacy_send_personal_data_export_email( $request_id, $has_export_data );
    23682394                if ( is_wp_error( $mail_success ) ) {
    23692395                        wp_send_json_error( $mail_success->get_error_message() );
    23702396                }
    2371         } else {
     2397        } elseif ( $has_export_data ) {
    23722398                // Modify the response to include the URL of the export file so the browser can fetch it.
    23732399                $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    23742400                if ( ! empty( $export_file_url ) ) {