wppaste
WordPress

Language_Pack_Upgrader::clear_destination( string $remote_destination ): bool|WP_Error

Since
5.1.0
Source
wp-admin/includes/class-language-pack-upgrader.php:410
Clears existing translations where this item is going to be installed into.

Compatibility

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

bool|WP_Error
True upon success, WP_Error on failure.

Performance profile

How much work a call to Language_Pack_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

Reads or writes the filesystem via glob().

Scaling
Scales with input

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

Instructions
55–108

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

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

What it touches

  • filesystemfilesystem accessglob()called directly
  • 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 Language_Pack_Upgrader::clear_destination() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always55–97glob()
!empty($unwritable_files)69–103glob(), array_filter()
empty($unwritable_files) && !$files && !->delete()74–108glob(), ->delete()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev18755–10816
8.518755–10816
8.418755–108169 fewer instructions than PHP 8.3
8.319655–10816
8.219655–10816
8.119655–10816
7.419655–10816

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 · 1

Source code

	public function clear_destination( $remote_destination ) {		global $wp_filesystem; 		$language_update    = $this->skin->language_update;		$language_directory = WP_LANG_DIR . '/'; // Local path for use with glob(). 		if ( 'core' === $language_update->type ) {			$files = array(				$remote_destination . $language_update->language . '.po',				$remote_destination . $language_update->language . '.mo',				$remote_destination . $language_update->language . '.l10n.php',				$remote_destination . 'admin-' . $language_update->language . '.po',				$remote_destination . 'admin-' . $language_update->language . '.mo',				$remote_destination . 'admin-' . $language_update->language . '.l10n.php',				$remote_destination . 'admin-network-' . $language_update->language . '.po',				$remote_destination . 'admin-network-' . $language_update->language . '.mo',				$remote_destination . 'admin-network-' . $language_update->language . '.l10n.php',				$remote_destination . 'continents-cities-' . $language_update->language . '.po',				$remote_destination . 'continents-cities-' . $language_update->language . '.mo',				$remote_destination . 'continents-cities-' . $language_update->language . '.l10n.php',			); 			$json_translation_files = glob( $language_directory . $language_update->language . '-*.json' );			if ( $json_translation_files ) {				foreach ( $json_translation_files as $json_translation_file ) {					$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );				}			}		} else {			$files = array(				$remote_destination . $language_update->slug . '-' . $language_update->language . '.po',				$remote_destination . $language_update->slug . '-' . $language_update->language . '.mo',				$remote_destination . $language_update->slug . '-' . $language_update->language . '.l10n.php',			); 			$language_directory     = $language_directory . $language_update->type . 's/';			$json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' );			if ( $json_translation_files ) {				foreach ( $json_translation_files as $json_translation_file ) {					$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );				}			}		} 		$files = array_filter( $files, array( $wp_filesystem, 'exists' ) ); 		// No files to delete.		if ( ! $files ) {			return true;		} 		// Check all files are writable before attempting to clear the destination.		$unwritable_files = array(); 		// Check writability.		foreach ( $files as $file ) {			if ( ! $wp_filesystem->is_writable( $file ) ) {				// Attempt to alter permissions to allow writes and try again.				$wp_filesystem->chmod( $file, FS_CHMOD_FILE );				if ( ! $wp_filesystem->is_writable( $file ) ) {					$unwritable_files[] = $file;				}			}		} 		if ( ! empty( $unwritable_files ) ) {			return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );		} 		foreach ( $files as $file ) {			if ( ! $wp_filesystem->delete( $file ) ) {				return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );			}		} 		return true;	}

Changelog

Introduced in 5.1.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.9.7 tag, from src/wp-admin/includes/class-language-pack-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.