Make WordPress Core

Ticket #44133: 44133.9.diff

File 44133.9.diff, 7.8 KB (added by xkon, 6 years ago)

Inform the user within mail and export file that there are no personal data found.

  • src/wp-admin/includes/admin-filters.php

     
    133133// Privacy hooks
    134134add_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 );
    135135add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
    136 add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
     136add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10, 3 );
    137137add_action( 'wp_privacy_personal_data_erased', '_wp_privacy_send_erasure_fulfillment_notification', 10 );
    138138
    139139// Privacy policy text changes check.
  • src/wp-admin/includes/file.php

     
    19921992 *
    19931993 * @param int $request_id The export request ID.
    19941994 */
    1995 function wp_privacy_generate_personal_data_export_file( $request_id ) {
     1995function wp_privacy_generate_personal_data_export_file( $request_id, $request, $has_export_data ) {
    19961996        if ( ! class_exists( 'ZipArchive' ) ) {
    19971997                wp_send_json_error( __( 'Unable to generate export file. ZipArchive not available.' ) );
    19981998        }
     
    21082108                fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) );
    21092109        }
    21102110
     2111        if ( ! $has_export_data ) {
     2112                fwrite( $file, '<strong>' . esc_html__( 'No personal data found.' ) . '</strong>' );
     2113        }
     2114
    21112115        fwrite( $file, "</body>\n" );
    21122116
    21132117        // Close HTML.
     
    21742178/**
    21752179 * Send an email to the user with a link to the personal data export file
    21762180 *
     2181 * The link to the export file is only included in the email content when there
     2182 * is personal data to export.
     2183 *
    21772184 * @since 4.9.6
     2185 * @since 5.2 Added the $has_export_data parameter.
    21782186 *
    2179  * @param int $request_id The request ID for this personal data export.
     2187 * @param int  $request_id      The request ID for this personal data export.
     2188 * @param bool $has_export_data Whether personal data exists to export.
     2189 *
    21802190 * @return true|WP_Error True on success or `WP_Error` on failure.
    21812191 */
    2182 function wp_privacy_send_personal_data_export_email( $request_id ) {
     2192function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) {
    21832193        // Get the request data.
    21842194        $request = wp_get_user_request_data( $request_id );
    21852195
     
    21922202        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    21932203
    21942204        /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
    2195         $email_text = __(
    2196                 'Howdy,
     2205        if ( $has_export_data ) {
     2206                $email_text = __( 'Howdy,
    21972207
    21982208Your request for an export of personal data has been completed. You may
    21992209download your personal data by clicking on the link below. For privacy
     
    22042214
    22052215Regards,
    22062216All at ###SITENAME###
    2207 ###SITEURL###'
    2208         );
     2217###SITEURL###' );
    22092218
    2210         /**
    2211          * Filters the text of the email sent with a personal data export file.
    2212          *
    2213          * The following strings have a special meaning and will get replaced dynamically:
    2214          * ###EXPIRATION###         The date when the URL will be automatically deleted.
    2215          * ###LINK###               URL of the personal data export file for the user.
    2216          * ###SITENAME###           The name of the site.
    2217          * ###SITEURL###            The URL to the site.
    2218          *
    2219          * @since 4.9.6
    2220          *
    2221          * @param string $email_text     Text in the email.
    2222          * @param int    $request_id     The request ID for this personal data export.
    2223          */
    2224         $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id );
     2219                /**
     2220                 * Filters the text of the email sent with a personal data export file.
     2221                 *
     2222                 * The following strings have a special meaning and will get replaced dynamically:
     2223                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2224                 * ###LINK###               URL of the personal data export file for the user.
     2225                 * ###SITENAME###           The name of the site.
     2226                 * ###SITEURL###            The URL to the site.
     2227                 *
     2228                 * @since 4.9.6
     2229                 * @since 5.2 $has_export_data argument added.
     2230                 *
     2231                 * @param string $email_text      Text in the email.
     2232                 * @param int    $request_id      The request ID for this personal data export.
     2233                 * @param bool   $has_export_data Whether personal data exists to export.
     2234                 */
     2235                $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
     2236        } else {
     2237                /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
     2238                $email_text = __( 'Howdy,
     2239Your request for an export of personal data has been completed.
    22252240
     2241###SITENAME### has identified no personal data associated with this email address.
     2242
     2243You may download your personal data by clicking on the link below. For privacy
     2244and security, we will automatically delete the file on ###EXPIRATION###,
     2245so please download it before then.
     2246
     2247###LINK###
     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 5.2
     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
    22262270        $email_address   = $request->email;
    22272271        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    22282272        $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     
    22302274
    22312275        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    22322276        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    2233         $content = str_replace( '###EMAIL###', $email_address, $content );
    22342277        $content = str_replace( '###SITENAME###', $site_name, $content );
    22352278        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    22362279
     
    23422385        delete_post_meta( $request_id, '_export_data_raw' );
    23432386        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23442387
     2388        $has_export_data = ! empty( $groups );
     2389
    23452390        /**
    23462391         * Generate the export file from the collected, grouped personal data.
    23472392         *
    23482393         * @since 4.9.6
     2394         * @since 5.2 Added the $request parameter.
     2395         * @since 5.2 Added the $has_export_data parameter.
    23492396         *
    2350          * @param int $request_id The export request ID.
     2397         * @param int             $request_id      The export request ID.
     2398         * @param WP_User_Request $request         The export request.
     2399         * @param bool            $has_export_data Wether there are personal data to export.
    23512400         */
    2352         do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2401        do_action( 'wp_privacy_personal_data_export_file', $request_id, $request, $has_export_data );
    23532402
    23542403        // Clear the grouped data now that it is no longer needed.
    23552404        delete_post_meta( $request_id, '_export_data_grouped' );
     
    23562405
    23572406        // If the destination is email, send it now.
    23582407        if ( $send_as_email ) {
    2359                 $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
     2408                $mail_success = wp_privacy_send_personal_data_export_email( $request_id, $has_export_data );
    23602409                if ( is_wp_error( $mail_success ) ) {
    23612410                        wp_send_json_error( $mail_success->get_error_message() );
    23622411                }