get_dirsize

The timeline below displays how wordpress function get_dirsize has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Gets the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 * @since 5.2.0 $max_execution_time parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param 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.
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
 */
function get_dirsize($directory, $max_execution_time = null)
{
    /*
     * 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()) {
        $size = recurse_dirsize($directory, $directory . '/sites', $max_execution_time);
    } else {
        $size = recurse_dirsize($directory, null, $max_execution_time);
    }
    return $size;
}

WordPress Version: 6.1

/**
 * Gets the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 * @since 5.2.0 $max_execution_time parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param 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.
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
 */
function get_dirsize($directory, $max_execution_time = null)
{
    // 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()) {
        $size = recurse_dirsize($directory, $directory . '/sites', $max_execution_time);
    } else {
        $size = recurse_dirsize($directory, null, $max_execution_time);
    }
    return $size;
}

WordPress Version: 5.6

/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 * @since 5.2.0 $max_execution_time parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param 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.
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
 */
function get_dirsize($directory, $max_execution_time = null)
{
    // 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()) {
        $size = recurse_dirsize($directory, $directory . '/sites', $max_execution_time);
    } else {
        $size = recurse_dirsize($directory, null, $max_execution_time);
    }
    return $size;
}

WordPress Version: 5.4

/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 * @since 5.2.0 $max_execution_time parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param 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.
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
 */
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'];
}

WordPress Version: 5.2

/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 * @since 5.2.0 $max_execution_time parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param 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.
 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
 */
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'];
}

WordPress Version: 4.9

// Misc functions
/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU (3.0.0)
 *
 * @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');
    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'];
}

WordPress Version: 4.3

// Misc functions
/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU
 *
 * @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');
    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'];
}

WordPress Version: 4.1

// Misc functions
/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU
 *
 * @param string $directory
 * @return int
 */
function get_dirsize($directory)
{
    $dirsize = get_transient('dirsize_cache');
    if (is_array($dirsize) && isset($dirsize[$directory]['size'])) {
        return $dirsize[$directory]['size'];
    }
    if (false == is_array($dirsize)) {
        $dirsize = array();
    }
    $dirsize[$directory]['size'] = recurse_dirsize($directory);
    set_transient('dirsize_cache', $dirsize, HOUR_IN_SECONDS);
    return $dirsize[$directory]['size'];
}

WordPress Version: 3.7

// Misc functions
/**
 * Get the size of a directory.
 *
 * A helper function that is used primarily to check whether
 * a blog has exceeded its allowed upload space.
 *
 * @since MU
 * @uses recurse_dirsize()
 *
 * @param string $directory
 * @return int
 */
function get_dirsize($directory)
{
    $dirsize = get_transient('dirsize_cache');
    if (is_array($dirsize) && isset($dirsize[$directory]['size'])) {
        return $dirsize[$directory]['size'];
    }
    if (false == is_array($dirsize)) {
        $dirsize = array();
    }
    $dirsize[$directory]['size'] = recurse_dirsize($directory);
    set_transient('dirsize_cache', $dirsize, HOUR_IN_SECONDS);
    return $dirsize[$directory]['size'];
}