XF 2.0 Please don't use getUserRepo()->getVisitor(##)

Snog

Well-known member
Please don't use $this->getUserRepo()->getVisitor($userId) to get a user. That function is what XenForo itself uses to set up \XF::visitor(). And using it to get a user other than the current user can wreak havoc with any add-on that is using the visitor_setup listener and depends on the info being for the current visitor.

Use a finder or some other method, but please don't use that one. ;)
 
To supplement the above, you can grab any arbitrary user by ID like this instead:
PHP:
$with = []; // any relations you want to eager-load
$user = \XF::em()->find('XF:User', $userId, $with);

By default, the repository method eager-loads the following, should your code depend on any of them:
PHP:
$with = [
    'Option',
    'Profile',
    'Privacy',
    'PermissionCombination'
];

And of course, if you're just trying to get the current visitor, you can simply use \XF::visitor().
 
Back
Top Bottom