clean_dirsize_cache( string $path )
- Since
- 5.6.0, 5.9.0
- Source
wp-includes/functions.php:8791
Cleans directory size cache used by recurse_dirsize().
Description
Removes the current directory and all parent directories from the
dirsize_cache transient.Parameters
$pathstring- Full path of a directory or file.
Uses · 7
- wp_trigger_error()Generates a user-level error/warning/notice/deprecation message.
- __()Retrieves the translation of $text.
- get_transient()Retrieves the value of a transient.
- wp_using_ext_object_cache()Toggles `$_wp_using_ext_object_cache` on and off without directly touching global.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- set_transient()Sets/updates the value of a transient.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
Used by · 3
- _wp_handle_upload()Handles PHP uploads in WordPress.
- wp_delete_attachment()Trashes or deletes an attachment.
- wp_upload_bits()Creates a file in the upload folder with given content.
Source
function clean_dirsize_cache( $path ) { if ( ! is_string( $path ) || empty( $path ) ) { wp_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; } $expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS; if ( ! str_contains( $path, '/' ) && ! str_contains( $path, '\\' ) ) { unset( $directory_cache[ $path ] ); set_transient( 'dirsize_cache', $directory_cache, $expiration ); 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, $expiration );}History
Introduced in 5.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
5.9.0
Added input validation with a notice for invalid input.from the docblock
5.6.0
Introduced.from the docblock
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.