The $current_user
global isn’t setup until right before the 'init'
action is called. So any code using it shouldn’t be fired until that action or later.
I would also suggest using the get_current_user_id()
method instead of getting the global directly.