函数原型
clean_dirsize_cache( string $path )
函数描述
Cleans directory size cache used by recurse_dirsize() .
是否弃用
未弃用
函数参数
-
$path
string
Required - Full path of a directory or file.
函数返回值
无
函数位置
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 5.9.0 | Added input validation with a notice for invalid input. |
| 5.6.0 | Introduced. |

