Make WordPress Core


Ignore:
Timestamp:
06/22/2020 10:38:11 PM (6 years ago)
Author:
whyisjake
Message:

Privacy: Use relative paths for exported personal data.

Ensures back-compat while moving to paths off of the /exports directory.

Fixes: #44038.

Props: allendav, mrTall, desrosj, garrett-eclipse, cameronamcintyre, nmenescardi, xkon, whyisjake, davidbaumwald.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/privacy-tools.php

    r48100 r48127  
    469469     * via email.
    470470     */
    471     $error            = false;
     471    $error = false;
     472
     473    // This postmeta is used from version 5.4.
     474    $archive_filename = get_post_meta( $request_id, '_export_file_name', true );
     475
     476    // These are used for backwards compatibility.
    472477    $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
    473478    $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
    474479
    475     if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
    476         $archive_filename = $file_basename . '.zip';
     480    // If archive_filename exists, make sure to remove deprecated postmeta.
     481    if ( ! empty( $archive_filename ) ) {
    477482        $archive_pathname = $exports_dir . $archive_filename;
    478483        $archive_url      = $exports_url . $archive_filename;
    479484
    480         update_post_meta( $request_id, '_export_file_url', $archive_url );
    481         update_post_meta( $request_id, '_export_file_path', wp_normalize_path( $archive_pathname ) );
     485        // Remove the deprecated postmeta.
     486        delete_post_meta( $request_id, '_export_file_url' );
     487        delete_post_meta( $request_id, '_export_file_path' );
     488    } elseif ( ! empty( $archive_pathname ) ) {
     489        // Check if archive_pathname exists. If not, create the new postmeta and remove the deprecated.
     490        $archive_filename = basename( $archive_pathname );
     491        $archive_url      = $exports_url . $archive_filename;
     492
     493        // Add the new postmeta that is used since version 5.4.
     494        update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
     495
     496        // Remove the deprecated postmeta.
     497        delete_post_meta( $request_id, '_export_file_url' );
     498        delete_post_meta( $request_id, '_export_file_path' );
     499    } else {
     500        // If there's no archive_filename or archive_pathname create a new one.
     501        $archive_filename = $file_basename . '.zip';
     502        $archive_url      = $exports_url . $archive_filename;
     503        $archive_pathname = $exports_dir . $archive_filename;
     504
     505        // Add the new postmeta that is used since version 5.4.
     506        update_post_meta( $request_id, '_export_file_name', wp_normalize_path( $archive_filename ) );
     507
     508        // Remove the deprecated postmeta.
     509        delete_post_meta( $request_id, '_export_file_url' );
     510        delete_post_meta( $request_id, '_export_file_path' );
    482511    }
    483512
     
    540569    $request = wp_get_user_request( $request_id );
    541570
     571    // Get the export file URL.
     572    $exports_url      = wp_privacy_exports_url();
     573    $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
     574
    542575    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
    543576        return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
     
    557590    $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
    558591
    559     $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
     592    $export_file_url = $exports_url . $export_file_name;
    560593    $site_name       = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    561594    $site_url        = home_url();
     
    821854    } else {
    822855        // Modify the response to include the URL of the export file so the browser can fetch it.
    823         $export_file_url = get_post_meta( $request_id, '_export_file_url', true );
     856        $exports_url      = wp_privacy_exports_url();
     857        $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
     858        $export_file_url  = $exports_url . $export_file_name;
     859
    824860        if ( ! empty( $export_file_url ) ) {
    825861            $response['url'] = $export_file_url;
Note: See TracChangeset for help on using the changeset viewer.