Make WordPress Core

Ticket #44133: 44133.5.diff

File 44133.5.diff, 6.9 KB (added by desrosj, 7 years ago)
  • src/wp-admin/includes/file.php

     
    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 * The link to the export file is only included in the email content when there
     2189 * is personal data to export.
     2190 *
    21882191 * @since 4.9.6
    21892192 *
    2190  * @param int $request_id The request ID for this personal data export.
     2193 * @param int  $request_id      The request ID for this personal data export.
     2194 * @param bool $has_export_data Whether personal data exists to export.
    21912195 * @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
     
    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, SITENAME, SITEURL: those are placeholders. */
    2206 $email_text = __(
    2207 'Howdy,
     2209        if ( $has_export_data ) {
     2210                /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
     2211                $email_text = __( 'Howdy,
    22082212
    22092213Your request for an export of personal data has been completed. You may
    22102214download your personal data by clicking on the link below. For privacy
     
    22152219
    22162220Regards,
    22172221All at ###SITENAME###
    2218 ###SITEURL###'
    2219 );
     2222###SITEURL###' );
    22202223
    2221         /**
    2222          * Filters the text of the email sent with a personal data export file.
    2223          *
    2224          * The following strings have a special meaning and will get replaced dynamically:
    2225          * ###EXPIRATION###         The date when the URL will be automatically deleted.
    2226          * ###LINK###               URL of the personal data export file for the user.
    2227          * ###SITENAME###           The name of the site.
    2228          * ###SITEURL###            The URL to the site.
    2229          *
    2230          * @since 4.9.6
    2231          *
    2232          * @param string $email_text     Text in the email.
    2233          * @param int    $request_id     The request ID for this personal data export.
    2234          */
    2235         $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
     2224                /**
     2225                 * Filters the text of the email sent with a personal data export file.
     2226                 *
     2227                 * The following strings have a special meaning and will get replaced dynamically:
     2228                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2229                 * ###LINK###               URL of the personal data export file for the user.
     2230                 * ###SITENAME###           The name of the site.
     2231                 * ###SITEURL###            The URL to the site.
     2232                 *
     2233                 * @since 4.9.6
     2234                 * @since 4.9.7 $has_export_data parameter added.
     2235                 *
     2236                 * @param string $email_text      Text in the email.
     2237                 * @param int    $request_id      The request ID for this personal data export.
     2238                 * @param bool   $has_export_data Whether personal data exists to export.
     2239                 */
     2240                $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
     2241        } else {
     2242                /* translators: Do not translate EXPIRATION, SITENAME, SITEURL: those are placeholders. */
     2243                $email_text = __( 'Howdy,
    22362244
    2237         $email_address = $request->email;
     2245Your request for an export of personal data has been completed.
     2246
     2247No personal data was found.
     2248
     2249Regards,
     2250All at ###SITENAME###
     2251###SITEURL###' );
     2252
     2253                /**
     2254                 * Filters the text of the email sent when no personal data exists to export.
     2255                 *
     2256                 * The following strings have a special meaning and will get replaced dynamically:
     2257                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2258                 * ###SITENAME###           The name of the site.
     2259                 * ###SITEURL###            The URL to the site.
     2260                 *
     2261                 * @since 4.9.7
     2262                 *
     2263                 * @param string $email_text      Text in the email.
     2264                 * @param int    $request_id      The request ID for this personal data export.
     2265                 * @param bool   $has_export_data Whether personal data exists to export.
     2266                 */
     2267                $content = apply_filters( 'wp_privacy_personal_data_email_content_no_data', $email_text, $request_id, $has_export_data );
     2268        }
     2269
     2270        $email_address   = $request->email;
    22382271        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    2239         $site_name = is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' );
    2240         $site_url = network_home_url();
     2272        $site_name       = is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' );
     2273        $site_url        = network_home_url();
    22412274
    22422275        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    22432276        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
     
    22482281        $mail_success = wp_mail(
    22492282                $email_address,
    22502283                sprintf(
     2284                        /* translators: %s Site name. */
    22512285                        __( '[%s] Personal Data Export' ),
    22522286                        wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
    22532287                ),
     
    23532387        delete_post_meta( $request_id, '_export_data_raw' );
    23542388        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23552389
    2356         /**
    2357          * Generate the export file from the collected, grouped personal data.
    2358          *
    2359          * @since 4.9.6
    2360          *
    2361          * @param int $request_id The export request ID.
    2362          */
    2363         do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2390        $has_export_data = ! empty( $groups );
    23642391
     2392        if ( $has_export_data ) {
     2393                /**
     2394                 * Generate the export file from the collected, grouped personal data.
     2395                 *
     2396                 * @since 4.9.6
     2397                 * @since 4.9.7 Added the $request parameter.
     2398                 *
     2399                 * @param int             $request_id The export request ID.
     2400                 * @param WP_User_Request $request    The export request.
     2401                 */
     2402                do_action( 'wp_privacy_personal_data_export_file', $request_id, $request );
     2403        } else {
     2404                /**
     2405                 * Fires when no personal data is found for exporting.
     2406                 *
     2407                 * @since 4.9.7
     2408                 *
     2409                 * @param int             $request_id The export request ID.
     2410                 * @param WP_User_Request $request    The export request.
     2411                 */
     2412                do_action( 'wp_privacy_personal_data_export_no_data', $request_id, $request );
     2413        }
     2414
    23652415        // Clear the grouped data now that it is no longer needed.
    23662416        delete_post_meta( $request_id, '_export_data_grouped' );
    23672417
    23682418        // If the destination is email, send it now.
    23692419        if ( $send_as_email ) {
    2370                 $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
     2420                $mail_success = wp_privacy_send_personal_data_export_email( $request_id, $has_export_data );
    23712421                if ( is_wp_error( $mail_success ) ) {
    23722422                        wp_send_json_error( $mail_success->get_error_message() );
    23732423                }
    2374         } else {
     2424        } elseif ( $has_export_data ) {
    23752425                // Modify the response to include the URL of the export file so the browser can fetch it.
    23762426                $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    23772427                if ( ! empty( $export_file_url ) ) {