Exclude individual site directories when calculating space used for the main site.
* Add an `$exclude` parameter to `recurse_dirsize()`. * Use this parameter in `get_dirsize()` to exclude `/sites` when on the main site. * Add tests for main site and switched site. Props @earnjam, @jeremyfelt. Fixes #30202. Built from https://develop.svn.wordpress.org/trunk@33184 git-svn-id: http://core.svn.wordpress.org/trunk@33156 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1f7a3bc58d
commit
c122491c70
|
@ -1686,8 +1686,8 @@ function get_most_recent_post_of_user( $user_id ) {
|
|||
*
|
||||
* @since MU
|
||||
*
|
||||
* @param string $directory
|
||||
* @return int
|
||||
* @param string $directory Full path of a directory.
|
||||
* @return int Size of the directory in MB.
|
||||
*/
|
||||
function get_dirsize( $directory ) {
|
||||
$dirsize = get_transient( 'dirsize_cache' );
|
||||
|
@ -1697,7 +1697,13 @@ function get_dirsize( $directory ) {
|
|||
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' ];
|
||||
|
@ -1710,17 +1716,20 @@ function get_dirsize( $directory ) {
|
|||
* other directories.
|
||||
*
|
||||
* @since MU
|
||||
* @since 4.3.0 $exclude parameter added.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return int|false
|
||||
* @param string $directory Full path of a directory.
|
||||
* @param string $exclude Optional. Full path of a subdirectory to exclude from the total.
|
||||
* @return int|false Size in MB if a valid directory. False if not.
|
||||
*/
|
||||
function recurse_dirsize( $directory ) {
|
||||
function recurse_dirsize( $directory, $exclude = null ) {
|
||||
$size = 0;
|
||||
|
||||
$directory = untrailingslashit( $directory );
|
||||
|
||||
if ( !file_exists($directory) || !is_dir( $directory ) || !is_readable( $directory ) )
|
||||
if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($handle = opendir($directory)) {
|
||||
while(($file = readdir($handle)) !== false) {
|
||||
|
@ -1729,7 +1738,7 @@ function recurse_dirsize( $directory ) {
|
|||
if (is_file($path)) {
|
||||
$size += filesize($path);
|
||||
} elseif (is_dir($path)) {
|
||||
$handlesize = recurse_dirsize($path);
|
||||
$handlesize = recurse_dirsize( $path, $exclude );
|
||||
if ($handlesize > 0)
|
||||
$size += $handlesize;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-beta2-33183';
|
||||
$wp_version = '4.3-beta2-33184';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue