1

When I look at $user like this

global $user
dpm($user);

I do not see the user account fields I added. How can I access them?

6

You need to use:

$account = user_load($user->uid);

Then, dump the $account object and you will see profile field.

1

The global variable $user doesn't contain all the properties you would find in a user object; in particular, it doesn't contain the fields associated with the user entity. If you need the complete user object, you need to use the following code.

$account = user_uid_optional_load();

Without any argument, user_uid_optional_load() returns the user object loaded from the database for the currently logged in user. If you have a user ID (e.g. you don't need the user object for the currently logged in user, but the user ID is passed to your function as parameter), then it is better to use the following code.

$account = user_load($uid);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.