Un motore di ricerca WordPress per sviluppatori e autori di temi



get_dirsize ›

Da5.2.0
Deprecaton/a
get_dirsize ( $directory, $max_execution_time = null )
Parametri: (2)
  • (string) $directory Full path of a directory.
    Richiesto:
  • (int) $max_execution_time Maximum time to run before giving up. In seconds. The timeout is global and is measured from the moment WordPress started to load.
    Richiesto: No
    Default: null
Ritorna:
  • (int|false|null) Size in bytes if a valid directory. False if not. Null if timeout.
Definito a:
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.



Sorgenti

function get_dirsize( $directory, $max_execution_time = null ) {
	$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 of a network
	// as they are subdirectories and should not be counted.
	if ( is_multisite() && is_main_site() ) {
		$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time );
	} else {
		$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, null, $max_execution_time );
	}

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