wppaste
WordPress

WP_Upgrader::clear_destination( string $remote_destination ): true|WP_Error

Since
4.3.0
Source
wp-admin/includes/class-wp-upgrader.php:440
Clears the directory where this item is going to be installed into.

Compatibility

WordPress
since 4.3.0
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.

Parameters

$remote_destinationstring
The location on the remote filesystem to be cleared.

Return value

true|WP_Error
True upon success, WP_Error on failure.

Performance profile

How much work a call to WP_Upgrader::clear_destination() 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

Reaches the database via ->delete().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
11–33

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • sqldatabase query->delete()called directly

What one call costs · 3 distinct outcomes

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

WhenInstructionsCalls it makes
$files === false11->dirlist()
$files !== false && empty($unwritable_files)25–33->dirlist(), ->flatten_dirlist(), ->delete()
$files !== false && !empty($unwritable_files)29–30->dirlist(), ->flatten_dirlist()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7011–338
8.57011–338
8.47011–3383 fewer instructions than PHP 8.3
8.37311–338
8.27311–338
8.17311–3382 fewer instructions than PHP 7.4
7.47511–338

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.

Uses · 2

Used by · 1

Source code

	public function clear_destination( $remote_destination ) {		global $wp_filesystem; 		$files = $wp_filesystem->dirlist( $remote_destination, true, true ); 		// False indicates that the $remote_destination doesn't exist.		if ( false === $files ) {			return true;		} 		// Flatten the file list to iterate over.		$files = $this->flatten_dirlist( $files ); 		// Check all files are writable before attempting to clear the destination.		$unwritable_files = array(); 		// Check writability.		foreach ( $files as $filename => $file_details ) {			if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {				// Attempt to alter permissions to allow writes and try again.				$wp_filesystem->chmod( $remote_destination . $filename, ( 'd' === $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) );				if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {					$unwritable_files[] = $filename;				}			}		} 		if ( ! empty( $unwritable_files ) ) {			return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );		} 		if ( ! $wp_filesystem->delete( $remote_destination, true ) ) {			return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );		} 		return true;	}

Changelog

Introduced in 4.3.0. 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-admin/includes/class-wp-upgrader.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.