Privacy: Rename exports folder to avoid deleting other files.

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
This commit is contained in:
iandunn 2018-05-15 20:22:20 +00:00
parent 534f732104
commit fdd5b8dacd
3 changed files with 50 additions and 6 deletions

View File

@ -2023,9 +2023,8 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
} }
// Create the exports folder if needed. // Create the exports folder if needed.
$upload_dir = wp_upload_dir(); $exports_dir = wp_privacy_exports_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' ); $exports_url = wp_privacy_exports_url();
$exports_url = trailingslashit( $upload_dir['baseurl'] . '/exports' );
$result = wp_mkdir_p( $exports_dir ); $result = wp_mkdir_p( $exports_dir );
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {

View File

@ -6248,6 +6248,52 @@ function wp_privacy_anonymize_data( $type, $data = '' ) {
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $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. * Schedule a `WP_Cron` job to delete expired export files.
* *
@ -6277,8 +6323,7 @@ function wp_schedule_delete_old_privacy_export_files() {
function wp_privacy_delete_old_export_files() { function wp_privacy_delete_old_export_files() {
require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' );
$upload_dir = wp_upload_dir(); $exports_dir = wp_privacy_exports_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) ); $export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.