Under the hood, get_dirsize()
uses recurse_dirsize()
which uses a transient called dirsize_cache
. Try clearing that transient and check again.
To do so, you can use one of the following methods:
- call
delete_transient('dirsize_cache');
- use WP CLI’s
wp transient delete
- use a plugin
Looking further through the source code, I think it should be possible to use recurse_dirsize()
directly in your code and telling it not to cache like so:
$upload_dir = wp_upload_dir();
$size = recurse_dirsize($upload_dir['basedir'], null, null, []);
By passing an empty array []
as the fourth argument, it should circumvent the cache because the !isset($directory_cache)
now returns a different result.