I have a module called “packages”. I want to store information on what package the user is using upon log in. I.e. Where, using which hook, or at what point, can I run this code:
$user[packages] = packages_get_user_packages($user->uid);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit
kiamlaluno’s solution is far better, and you should use that, not what follows.
Rather than storing it when they log in, you should store it in the
$userobject as soon as you know what packages belong to the user. This will stay with the user, so you only have to do it once instead of every time they log in:Then, forever after, you merely have to call
$user->packagesto get the information.If you really can only save the information when they log in, you can do it in
hook_boot(), which runs on every page:Using
hook_boot()should really be used as a last resort: there’s a lot of stuff still not loaded whenhook_boot()is invoked, and your module might not have what it needs.Note that
$useris an object, not an array:$user['packages']will not work.