Can you add a variable to $visitor object?

Randall

Member
Is there a way to add a variable to the $visitor object? We are linking an external website account with a XenForo account and I'd like to store the API tokens in the $visitor object.
 
You could also store them temporarily in the user's session or permanently in the database. There's also a framework for storing and accessing external accounts data. We mostly use it for storing external authentication keys and associated data.
 
Thanks for the help guys. Can I just add something like the code below to my code event listener?

$visitor["api_token"] = "the token value";

Will the "api_token" value be available anytime you have the $visitor object?
 
Depends which event listener. If it's the visitor_setup event listener, yes, it should.
 
I'm using the visitor_setup event listener.

In the visitor_setup event listener function I have:

class Passport_Listener_Listener
{
public static function visitor_setup(XenForo_Visitor &$visitor)
{
$visitor["api_token"] = "abc123";
}
}

On our wordpress side of the site I have:
$visitor = XenForo_Visitor::getInstance()->toArray();
var_dump($visitor);

I log into XenForo and browse to wordpress side of our site and the var_dump doesn't have the "api_token" or it's value. So I'm missing something or it's not getting saved. A var_dump in the XenForo function shows it (of course).
 
If that code is being used on the WordPress side, I would guess that whatever is talking to XF from that side isn't initialising the complete set of XF dependencies, some of which would be initialising the various code event listeners.
 
Thank you Chris D. Once I looked over the wordpress side I did see they didn't load the dependencies. Thanks for all the help, really appreciate it.
 
Top Bottom