pre_recurse_dirsize
云策文档标注
概述
pre_recurse_dirsize 是一个 WordPress 过滤器,用于拦截和修改目录及其子目录的存储空间计算过程,以优化性能或集成外部系统。
关键要点
- 过滤器允许开发者自定义目录大小计算逻辑,例如通过 CDN API 或操作系统工具替代默认的递归 PHP 计算。
- 参数包括 $space_used(已用空间字节数)、$directory(目录路径)、$exclude(排除路径)、$max_execution_time(最大执行时间)和 $directory_cache(缓存数组)。
- 在 recurse_dirsize() 函数中被调用,用于获取目录的递归大小。
- 自 WordPress 5.6.0 版本引入。
代码示例
$size = apply_filters( 'pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache );
原文内容
Filters the amount of storage space used by one directory and all its children, in megabytes.
Description
Return the actual used space to short-circuit the recursive PHP file size calculation and use something else, like a CDN API or native operating system tools for better performance.
Parameters
$space_usedint|false-
The amount of used space, in bytes. Default false.
$directorystring-
Full path of a directory.
$excludestring|string[]|null-
Full path of a subdirectory to exclude from the total, or array of paths.
$max_execution_timeint-
Maximum time to run before giving up. In seconds.
$directory_cachearray-
Array of cached directory paths.
Source
$size = apply_filters( 'pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache );
Changelog
| Version | Description |
|---|---|
| 5.6.0 | Introduced. |