Skip to:

Re: Global Variable – Username not ID

Burt Adsit


Howdy, We\\\’ve got several ways of referring to a user:

In code:

1) The user id from the wp_users table.

2) The users *login* username

Pretty stuff that gets displayed:

3) The user name that wp has for the user (Display name publicly as: in wp profile)

4) The bp user\\\’s full name

bp uses the user id in most cases to refer to a user. Most of the core template tags take a user id as a parameter. The var $bp->loggedin_user->username doesn\\\’t exist. Nor does the var $bp->displayed_user->username. They aren\\\’t currently being set to anything.

I\\\’m kinda guessing you were shooting for the login username there. The global wp var $userdata->user_login and $current_user->user_login have what you want there.

One thing you have to be aware of is that the $bp->loggedin_user is available throughout bp no matter where you are. The var $bp->displayed_user is only available when the user is in the member theme.

Instead of using the vars directly it might be best to use the template tags in bp-core.php that are like bp_get_user<somthing>() or the template tags in bp-core-templatetags.php for some other user related items: bp_loggedinuser_<somthing>() functions. If things change in bp and the vars change then the wrapper functions just mentioned should shield you from rewriting code.

Skip to toolbar