Make WordPress Core

Ticket #44133: 44133.8.diff

File 44133.8.diff, 6.6 KB (added by xkon, 6 years ago)

refresh of 44133.7

  • wp-admin/includes/file.php

     
    21742174/**
    21752175 * Send an email to the user with a link to the personal data export file
    21762176 *
     2177 * The link to the export file is only included in the email content when there
     2178 * is personal data to export.
     2179 *
    21772180 * @since 4.9.6
     2181 * @since 5.2 Added the $has_export_data parameter.
    21782182 *
    2179  * @param int $request_id The request ID for this personal data export.
     2183 * @param int  $request_id      The request ID for this personal data export.
     2184 * @param bool $has_export_data Whether personal data exists to export.
     2185 *
    21802186 * @return true|WP_Error True on success or `WP_Error` on failure.
    21812187 */
    2182 function wp_privacy_send_personal_data_export_email( $request_id ) {
     2188function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) {
    21832189        // Get the request data.
    21842190        $request = wp_get_user_request_data( $request_id );
    21852191
     
    21922198        $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    21932199
    21942200        /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
    2195         $email_text = __(
    2196                 'Howdy,
     2201        if ( $has_export_data ) {
     2202                $email_text = __( 'Howdy,
    21972203
    21982204Your request for an export of personal data has been completed. You may
    21992205download your personal data by clicking on the link below. For privacy
     
    22042210
    22052211Regards,
    22062212All at ###SITENAME###
    2207 ###SITEURL###'
    2208         );
     2213###SITEURL###' );
    22092214
    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 );
     2215                /**
     2216                 * Filters the text of the email sent with a personal data export file.
     2217                 *
     2218                 * The following strings have a special meaning and will get replaced dynamically:
     2219                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2220                 * ###LINK###               URL of the personal data export file for the user.
     2221                 * ###SITENAME###           The name of the site.
     2222                 * ###SITEURL###            The URL to the site.
     2223                 *
     2224                 * @since 4.9.6
     2225                 * @since 5.2 $has_export_data argument added.
     2226                 *
     2227                 * @param string $email_text      Text in the email.
     2228                 * @param int    $request_id      The request ID for this personal data export.
     2229                 * @param bool   $has_export_data Whether personal data exists to export.
     2230                 */
     2231                $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data );
     2232        } else {
     2233                /* translators: Do not translate SITENAME, SITEURL: those are placeholders. */
     2234                $email_text = __( 'Howdy,
     2235Your request for an export of personal data has been completed.
    22252236
     2237###SITENAME### has identified no personal data associated with this email address.
     2238
     2239Regards,
     2240All at ###SITENAME###
     2241###SITEURL###' );
     2242
     2243                /**
     2244                 * Filters the text of the email sent when no personal data exists to export.
     2245                 *
     2246                 * The following strings have a special meaning and will get replaced dynamically:
     2247                 * ###EXPIRATION###         The date when the URL will be automatically deleted.
     2248                 * ###SITENAME###           The name of the site.
     2249                 * ###SITEURL###            The URL to the site.
     2250                 *
     2251                 * @since 5.2
     2252                 *
     2253                 * @param string $email_text      Text in the email.
     2254                 * @param int    $request_id      The request ID for this personal data export.
     2255                 * @param bool   $has_export_data Whether personal data exists to export.
     2256                 */
     2257                $content = apply_filters( 'wp_privacy_personal_data_email_content_no_data', $email_text, $request_id, $has_export_data );
     2258        }
     2259
    22262260        $email_address   = $request->email;
    22272261        $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    22282262        $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     
    22302264
    22312265        $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
    22322266        $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
    2233         $content = str_replace( '###EMAIL###', $email_address, $content );
    22342267        $content = str_replace( '###SITENAME###', $site_name, $content );
    22352268        $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
    22362269
     
    23422375        delete_post_meta( $request_id, '_export_data_raw' );
    23432376        update_post_meta( $request_id, '_export_data_grouped', $groups );
    23442377
    2345         /**
    2346          * Generate the export file from the collected, grouped personal data.
    2347          *
    2348          * @since 4.9.6
    2349          *
    2350          * @param int $request_id The export request ID.
    2351          */
    2352         do_action( 'wp_privacy_personal_data_export_file', $request_id );
     2378        $has_export_data = ! empty( $groups );
    23532379
     2380        if ( $has_export_data ) {
     2381                /**
     2382                 * Generate the export file from the collected, grouped personal data.
     2383                 *
     2384                 * @since 4.9.6
     2385                 * @since 5.2 Added the $request parameter.
     2386                 *
     2387                 * @param int             $request_id The export request ID.
     2388                 * @param WP_User_Request $request    The export request.
     2389                 */
     2390                do_action( 'wp_privacy_personal_data_export_file', $request_id, $request );
     2391        } else {
     2392                /**
     2393                 * Fires when no personal data is found for exporting.
     2394                 *
     2395                 * @since 5.2
     2396                 *
     2397                 * @param int             $request_id The export request ID.
     2398                 * @param WP_User_Request $request    The export request.
     2399                 */
     2400                do_action( 'wp_privacy_personal_data_export_no_data', $request_id, $request );
     2401        }
     2402
    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                }
    2363         } else {
     2412        } elseif ( $has_export_data ) {
    23642413                // Modify the response to include the URL of the export file so the browser can fetch it.
    23652414                $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
    23662415                if ( ! empty( $export_file_url ) ) {