Make WordPress Core

Ticket #44133: 44133.7.diff

File 44133.7.diff, 7.2 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
     2192 * @since 4.9.8 Added the $has_export_data parameter.
    21892193 *
    2190  * @param int $request_id The request ID for this personal data export.
     2194 * @param int  $request_id      The request ID for this personal data export.
     2195 * @param bool $has_export_data Whether personal data exists to export.
    21912196 * @return true|WP_Error True on success or `WP_Error` on failure.
    21922197 */
    2193 function wp_privacy_send_personal_data_export_email( $request_id ) {
     2198function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) {
    21942199        // Get the request data.
    21952200        $request = wp_get_user_request_data( $request_id );
    21962201
     
    22022207        $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    22032208        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    22042209
    2205 /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
    2206 $email_text = __(
    2207 'Howdy,
     2210        if ( $has_export_data ) {
     2211                /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
     2212                $email_text = __( 'Howdy,
    22082213
    22092214Your request for an export of personal data has been completed. You may
    22102215download your personal data by clicking on the link below. For privacy
     
    22152220
    22162221Regards,
    22172222All at ###SITENAME###
    2218 ###SITEURL###'
    2219 );
     2223###SITEURL###' );
    22202224
    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 );
     2225                /**
     2226                 * Filters the text of the email sent with a personal data export file.
     2227                 *
     2228                 * The following strings have a special meaning and will get replaced dynamically:
     2229                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2230                 * ###LINK###               URL of the personal data export file for the user.
     2231                 * ###SITENAME###           The name of the site.
     2232                 * ###SITEURL###            The URL to the site.
     2233                 *
     2234                 * @since 4.9.6
     2235                 * @since 4.9.8 $has_export_data argument added.
     2236                 *
     2237                 * @param string $email_text      Text in the email.
     2238                 * @param int    $request_id      The request ID for this personal data export.
     2239                 * @param bool   $has_export_data Whether personal data exists to export.
     2240                 */
     2241                $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
     2242        } else {
     2243                /* translators: Do not translate SITENAME, SITEURL: those are placeholders. */
     2244                $email_text = __( 'Howdy,
    22362245
    2237         $email_address = $request->email;
     2246Your request for an export of personal data has been completed.
     2247
     2248###SITENAME### has identified no personal data associated with this email address.
     2249
     2250Regards,
     2251All at ###SITENAME###
     2252###SITEURL###' );
     2253
     2254                /**
     2255                 * Filters the text of the email sent when no personal data exists to export.
     2256                 *
     2257                 * The following strings have a special meaning and will get replaced dynamically:
     2258                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2259                 * ###SITENAME###           The name of the site.
     2260                 * ###SITEURL###            The URL to the site.
     2261                 *
     2262                 * @since 4.9.8
     2263                 *
     2264                 * @param string $email_text      Text in the email.
     2265                 * @param int    $request_id      The request ID for this personal data export.
     2266                 * @param bool   $has_export_data Whether personal data exists to export.
     2267                 */
     2268                $content = apply_filters( 'wp_privacy_personal_data_email_content_no_data', $email_text, $request_id, $has_export_data );
     2269        }
     2270
     2271        $email_address   = $request->email;
    22382272        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    2239         $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    2240         $site_url = home_url();
     2273        $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     2274        $site_url        = home_url();
    22412275
    22422276        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    22432277        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    2244         $content = str_replace( '###EMAIL###', $email_address, $content );
    22452278        $content = str_replace( '###SITENAME###', $site_name, $content );
    22462279        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    22472280
     
    22482281        $mail_success = wp_mail(
    22492282                $email_address,
    22502283                sprintf(
     2284                        /* translators: %s Site name. */
    22512285                        __( '[%s] Personal Data Export' ),
    22522286                        $site_name
    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.8 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 ) ) {