get_dirsize( string $directory, int $max_execution_time = null )

Gets the size of a directory.


Description

A helper function that is used primarily to check whether a blog has exceeded its allowed upload space.


Parameters

$directory

(Required) Full path of a directory.

$max_execution_time

(Optional) Maximum time to run before giving up. In seconds.<br> The timeout is global and is measured from the moment WordPress started to load.

Default value: null


Return

(int|false|null) Size in bytes if a valid directory. False if not. Null if timeout.


Source

File: wp-includes/functions.php

function get_dirsize( $directory ) {
	$dirsize = get_transient( 'dirsize_cache' );
	if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) )
		return $dirsize[ $directory ][ 'size' ];

	if ( ! is_array( $dirsize ) )
		$dirsize = array();

	// Exclude individual site directories from the total when checking the main site,
	// as they are subdirectories and should not be counted.
	if ( is_main_site() ) {
		$dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' );
	} else {
		$dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory );
	}

	set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
	return $dirsize[ $directory ][ 'size' ];
}

Changelog

Changelog
Version Description
5.2.0 $max_execution_time parameter added.
MU (3.0.0) Introduced. MU (3.0.0)