If you check the code that you just posted by itself, you’re missing a bunch of variables like $avatar_dir, $item_id, $object, which is why your code isn’t working.
Just declare them manually:
$avatar_dir = ‘avatars’;
$item_id = THE USER ID YOU’RE CHECKING
$object = ‘user’;