Skip to content

Commit

Permalink
Privacy: Rename exports folder to avoid deleting other files.
Browse files Browse the repository at this point in the history
Previously, personal data exports were stored in `wp-content/uploads/exports`, which is generic enough that it's likely there are existing folders with that name, either created by plugins or manually by administrators. If that folder were reused by Core, then `wp_privacy_delete_old_export_files()` would delete all of the existing files inside it, which is almost certainly not what the site owner wants or expects.

To avoid that, the folder is being renamed to include a specific reference to Core, and a more verbose description of its purpose. With those factored in, it's very unlikely that there will be any conflicts with existing folders.

The `wp_privacy_exports_dir()` and `wp_privacy_exports_url()` functions were introduced to provide a canonical source for the location, and the `wp_privacy_exports_dir` and `wp_privacy_exports_url` filters were introduced to allow plugins to customize it.

Props johnjamesjacoby, allendav.
Fixes #44091.

Built from https://develop.svn.wordpress.org/trunk@43284


git-svn-id: http://core.svn.wordpress.org/trunk@43113 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
iandunn committed May 15, 2018
1 parent 534f732 commit fdd5b8d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
5 changes: 2 additions & 3 deletions wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,8 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
}

// Create the exports folder if needed.
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
$exports_url = trailingslashit( $upload_dir['baseurl'] . '/exports' );
$exports_dir = wp_privacy_exports_dir();
$exports_url = wp_privacy_exports_url();

$result = wp_mkdir_p( $exports_dir );
if ( is_wp_error( $result ) ) {
Expand Down
49 changes: 47 additions & 2 deletions wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6248,6 +6248,52 @@ function wp_privacy_anonymize_data( $type, $data = '' ) {
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
}

/**
* Returns the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_url
*
* @return string Exports directory.
*/
function wp_privacy_exports_dir() {
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';

/**
* Filters the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_dir Exports directory.
*/
return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
}

/**
* Returns the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_dir
*
* @return string Exports directory URL.
*/
function wp_privacy_exports_url() {
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';

/**
* Filters the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_url Exports directory URL.
*/
return apply_filters( 'wp_privacy_exports_url', $exports_url );
}

/**
* Schedule a `WP_Cron` job to delete expired export files.
*
Expand Down Expand Up @@ -6277,8 +6323,7 @@ function wp_schedule_delete_old_privacy_export_files() {
function wp_privacy_delete_old_export_files() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );

$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
$exports_dir = wp_privacy_exports_dir();
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );

/**
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43282';
$wp_version = '5.0-alpha-43284';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit fdd5b8d

Please sign in to comment.