Filter hook 'pre_recurse_dirsize'

in WP Core File wp-includes/functions.php at line 8765

View Source

pre_recurse_dirsize

Filter Hook
Description
Filters the amount of storage space used by one directory and all its children, in megabytes. 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.

Hook Information

File Location wp-includes/functions.php View on GitHub
Hook Type Filter
Line Number 8765

Hook Parameters

Type Name Description
int|false $space_used The amount of used space, in bytes. Default false.
string $directory Full path of a directory.
string|string[]|null $exclude Full path of a subdirectory to exclude from the total, or array of paths.
int $max_execution_time Maximum time to run before giving up. In seconds.
array $directory_cache Array of cached directory paths.

Usage Examples

Basic Usage
<?php
// Hook into pre_recurse_dirsize
add_filter('pre_recurse_dirsize', 'my_custom_filter', 10, 5);

function my_custom_filter($space_used, $directory, $exclude, $max_execution_time, $directory_cache) {
    // Your custom filtering logic here
    return $space_used;
}

Source Code Context

wp-includes/functions.php:8765 - How this hook is used in WordPress core
<?php
8760  	 * @param string|string[]|null $exclude            Full path of a subdirectory to exclude from the total,
8761  	 *                                                 or array of paths.
8762  	 * @param int                  $max_execution_time Maximum time to run before giving up. In seconds.
8763  	 * @param array                $directory_cache    Array of cached directory paths.
8764  	 */
8765  	$size = apply_filters( 'pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache );
8766  
8767  	if ( false === $size ) {
8768  		$size = 0;
8769  
8770  		$handle = opendir( $directory );

PHP Documentation

<?php
/**
	 * Filters the amount of storage space used by one directory and all its children, in megabytes.
	 *
	 * 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.
	 *
	 * @since 5.6.0
	 *
	 * @param int|false            $space_used         The amount of used space, in bytes. Default false.
	 * @param string               $directory          Full path of a directory.
	 * @param string|string[]|null $exclude            Full path of a subdirectory to exclude from the total,
	 *                                                 or array of paths.
	 * @param int                  $max_execution_time Maximum time to run before giving up. In seconds.
	 * @param array                $directory_cache    Array of cached directory paths.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 5
  • File: wp-includes/functions.php
Related Hooks

Related hooks will be displayed here in future updates.