Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_dirsize ›

Seit3.0.0
Veraltetn/v
get_dirsize ( $directory )
Parameter:
  • (string) $directory Full path of a directory.
    Erforderlich: Ja
Gibt zurück:
  • (int) Size of the directory in MB.
Definiert in:
Codex:
Changelog:
  • MU

Get the size of a directory.

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



Quellcode

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' ];
}