The clean_dirsize_cache() WordPress PHP function clears the directory size cache used by recurse_dirsize(). It removes the current directory and all its parent directories from the dirsize_cache transient.
Usage
Here’s how you would use the function:
clean_dirsize_cache('/path/to/your/directory');
This command will clean the directory size cache for ‘/path/to/your/directory’ and all its parent directories.
Parameters
- $path (string) – Required. This is the full path of a directory or file you want to clean the cache for.
More information
See WordPress Developer Resources: clean_dirsize_cache()
This function is a part of WordPress core since version 3.5.1. It’s used primarily in the context of multisite installations to ensure accurate space usage tracking.
Examples
Cleaning cache for a specific directory
In this case, we’re cleaning the cache for ‘/path/to/your/directory’.
$path = '/path/to/your/directory'; clean_dirsize_cache($path); // Cleans the cache for the directory
Cleaning cache after a file upload
This can be useful after uploading a file to a directory.
$path = '/path/to/your/uploaded/file'; clean_dirsize_cache($path); // Cleans the cache for the file's directory
Cleaning cache for the WordPress uploads directory
This example demonstrates how you can clean the cache for the default WordPress uploads directory.
$path = wp_upload_dir()['basedir']; clean_dirsize_cache($path); // Cleans the cache for the uploads directory
Cleaning cache for a theme’s directory
Here, we’re cleaning the cache for a theme’s directory.
$path = get_template_directory(); clean_dirsize_cache($path); // Cleans the cache for the theme's directory
Cleaning cache for a plugin’s directory
In this case, we’re cleaning the cache for a specific plugin’s directory.
$path = plugin_dir_path(__FILE__); clean_dirsize_cache($path); // Cleans the cache for the plugin's directory