Using WordPress ‘pre_get_space_used’ PHP filter

pre_get_space_used is a WordPress PHP filter that allows you to modify the amount of storage space used by the current site, measured in megabytes.

Usage

add_filter('pre_get_space_used', 'your_custom_function', 10, 1);

function your_custom_function($space_used) {
    // your custom code here
    return $space_used;
}

Parameters

  • $space_used (int|false) – The amount of used space, in megabytes. Default is false.

More information

See WordPress Developer Resources: https://developer.wordpress.org/reference/hooks/pre_get_space_used/

Examples

Decrease reported space used by 100MB

Reduce the reported space used by the current site by 100MB.

add_filter('pre_get_space_used', 'decrease_space_used', 10, 1);

function decrease_space_used($space_used) {
    $space_used -= 100;
    return max($space_used, 0);
}

Increase reported space used by 50MB

Increase the reported space used by the current site by 50MB.

add_filter('pre_get_space_used', 'increase_space_used', 10, 1);

function increase_space_used($space_used) {
    $space_used += 50;
    return $space_used;
}

Set a custom space used value

Set the reported space used by the current site to a custom value of 500MB.

add_filter('pre_get_space_used', 'set_custom_space_used', 10, 1);

function set_custom_space_used($space_used) {
    $space_used = 500;
    return $space_used;
}

Double the reported space used

Double the amount of reported space used by the current site.

add_filter('pre_get_space_used', 'double_space_used', 10, 1);

function double_space_used($space_used) {
    $space_used *= 2;
    return $space_used;
}

Set space used to zero for specific user roles

Set the reported space used by the current site to zero for specific user roles, such as “editor”.

add_filter('pre_get_space_used', 'zero_space_used_for_editors', 10, 1);
function zero_space_used_for_editors($space_used) {
$user = wp_get_current_user();
if (in_array('editor', $user->roles)) {
return 0;
}
return $space_used;
}