maybe validate_user_storage_space
is firing too early or its too late. try wrapping this function inside another function then hook second function with one of below action hook
init
or after_setup_theme
or plugins_loaded
like below.
add_action( 'init', 'validate_user_init' ); //after_setup_theme plugins_loaded
function validate_user_init(){
add_filter('wp_handle_upload_prefilter', 'validate_user_storage_space', 1);
add_filter('wp_handle_sideload_prefilter', 'validate_user_storage_space', 1);
}
function validate_user_storage_space( $file ) {
//your stuff
}