Yes that's right. User_load is not called all the time, but only when a module decides it needs all the users profile information, etc.
So in the module that needs access to this, it should call user_load($user->uid) in order to make sure it gets all profile fields, and your hook_user code is executed.
If you truly need this data populated every page load, and are coding for 5.x, you can move your code into hook menu (!$may_cache section) in a module to modify the global $user object instead. Hook init could be used but you'll find not all the drupal api functions are available cause drupal hasn't fully bootsrapped yet (particularly when caching is enabled).
In 6.x hook_init is a more appropriate place to do "every page" loading of data into the global user object.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Marc Poris Sent: Wednesday, March 05, 2008 9:48 AM To: support@drupal.org Subject: Re: [support] Add some info to $user
You probably need to call user_load() -- please read through this issue and the issues that it references:
- Marc
Davide Michel 'ZioBudda' Morelli wrote:
Hi all. I need to add some infos to $user variable. I have thinked
that
hook_user() is my "hook" :)
So I have write a function that add the infos to the $account:
function mw_livelloUtenti_user($op, &$edit, &$account, $category =
NULL) {
switch ($op) { case "login" : case "load" : if ($account->uid != NULL || $account->uid != 0) { $tmp = db_query("SELECT mw.* FROM mw_lU AS mw LEFT
JOIN
mw_lU_user AS mwu ON mw.luid = mwu.luid WHERE mwu.uid =
%d",$account->uid);
$account->level = db_fetch_array($tmp); //print_r($account); //Ok, data are inserted (fields:level, data1, data2) } break; } }
Now, why when one of my other module try to access to $user->account this field is NULL ? Plz help me.
M.