wppaste
WordPress

wp_privacy_delete_old_export_files()

Since
4.9.6
Source
wp-includes/functions.php:8347
Cleans up export files older than three days old.

Description

The export files are stored in wp-content/uploads, and are therefore publicly accessible. A CSPRN is appended to the filename to mitigate the risk of an unauthorized person downloading the file, but it is still possible. Deleting the file after the data subject has had a chance to delete it adds an additional layer of protection.

Compatibility

WordPress
since 4.9.6
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to wp_privacy_delete_old_export_files() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via is_dir().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
8–28

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 42.

Plugin surface
1 hook

Third-party callbacks on 'wp_privacy_export_expiration' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • filesystemfilesystem accessis_dir()called directly

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_privacy_delete_old_export_files() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!is_dir()8wp_privacy_exports_dir(), is_dir()
is_dir()27–28wp_privacy_exports_dir(), is_dir(), list_files(), apply_filters()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 42 instructions, 8–28 executed per call, 4 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while wp_privacy_delete_old_export_files() runs, in this order:

  1. apply_filters( wp_privacy_export_expiration )filterline 8366 (+19 into the body)

    Filters the lifetime, in seconds, of a personal data export file.

Uses · 3

  • wp_privacy_exports_dir()Returns the directory used to store personal data export files.
  • list_files()Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source code

function wp_privacy_delete_old_export_files() {	$exports_dir = wp_privacy_exports_dir();	if ( ! is_dir( $exports_dir ) ) {		return;	} 	require_once ABSPATH . 'wp-admin/includes/file.php';	$export_files = list_files( $exports_dir, 100, array( 'index.php' ) ); 	/**	 * Filters the lifetime, in seconds, of a personal data export file.	 *	 * By default, the lifetime is 3 days. Once the file reaches that age, it will automatically	 * be deleted by a cron job.	 *	 * @since 4.9.6	 *	 * @param int $expiration The expiration age of the export, in seconds.	 */	$expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS ); 	foreach ( (array) $export_files as $export_file ) {		$file_age_in_seconds = time() - filemtime( $export_file ); 		if ( $expiration < $file_age_in_seconds ) {			unlink( $export_file );		}	}}

Changelog

Introduced in 4.9.6. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.