In XenForo 1, getting the user_id involved the getInstance and getUserId methods.
$user_id =XenForo_Visitor::getInstance()->getUserId();
In XenForo 2, it's a matter of using visitor().
$visitor = \XF::visitor();
$user_id = $visitor['user_id'];
Once the user_id is known then the $user...