clean_dirsize_cache() WordPress Function

The clean_dirsize_cache() function is used to clean the cached directory size information for the specified user. This is useful if the user's home directory has been changed or if the cached information is no longer accurate.

clean_dirsize_cache( string $path ) #

Cleans directory size cache used by recurse_dirsize().


Description

Removes the current directory and all parent directories from the dirsize_cache transient.


Top ↑

Parameters

$path

(string)(Required)Full path of a directory or file.


Top ↑

Source

File: wp-includes/functions.php

function clean_dirsize_cache( $path ) {
	if ( ! is_string( $path ) || empty( $path ) ) {
		trigger_error(
			sprintf(
				/* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */
				__( '%1$s only accepts a non-empty path string, received %2$s.' ),
				'<code>clean_dirsize_cache()</code>',
				'<code>' . gettype( $path ) . '</code>'
			)
		);
		return;
	}

	$directory_cache = get_transient( 'dirsize_cache' );

	if ( empty( $directory_cache ) ) {
		return;
	}

	if (
		strpos( $path, '/' ) === false &&
		strpos( $path, '\\' ) === false
	) {
		unset( $directory_cache[ $path ] );
		set_transient( 'dirsize_cache', $directory_cache );
		return;
	}

	$last_path = null;
	$path      = untrailingslashit( $path );
	unset( $directory_cache[ $path ] );

	while (
		$last_path !== $path &&
		DIRECTORY_SEPARATOR !== $path &&
		'.' !== $path &&
		'..' !== $path
	) {
		$last_path = $path;
		$path      = dirname( $path );
		unset( $directory_cache[ $path ] );
	}

	set_transient( 'dirsize_cache', $directory_cache );
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Added input validation with a notice for invalid input.
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More