Document user_load must be called to get fully realized user object
Chris Johnson - April 4, 2006 - 16:35
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | documentation |
| Category: | task |
| Priority: | normal |
| Assigned: | Chris Johnson |
| Status: | active |
Jump to:
Description
The global $user object that exists on each page is not a complete user object, contrary to what one might think. The only time the user object is complete is after user_load() is called, because user_load() fires (calls) all of the hook_user() hooks, allowing modules to add whatever data they wish to the user object. Without user_load() being called, none of the module-added data for the user object will exist.
This task is to add documentation about this inconsistent and potentially misleading situation to the contrib/docs/core.php documentation.

#1
Interestingly, with the addition of some
watchdog()calls I see thathook_user()is being fired in my module during a normal request. However, any fields added to the $user object inhook_user()seem to disappear at some later point (confirmed by creating a page node that simply dumps the contents of $user).#2
#3
Changed the component to reflect the new component categorization. See http://drupal.org/node/301443.
#4
I've noticed the same thing as g011um. If it's getting fired anyway, why not just write it to the global, because you're not saving any time if it's happening at some point. Either that or just don't ever run it until you need it.