Skip to:
Content
Pages
Categories
Search
Top
Bottom

Global Variable – Username not ID

Viewing 9 replies - 1 through 9 (of 9 total)

  • nicolagreco
    Participant

    @nicolagreco

    $bp->loggedin_user->fullname

    – Nicola

    $bp->loggedin_user->fullname

    $bp->loggedin_user->username

    $bp->loggedin_user->id

    $bp->displayed_user->fullname

    $bp->displayed_user->username

    $bp->displayed_user->id


    nicolagreco
    Participant

    @nicolagreco

    OK, Nicola – Andy 0-1

    Anyway that’s solved :)


    belogical
    Participant

    @belogical

    ok, this one is bizarre. i can\’t seem to get the username to display on either method. what could I be doing wrong?

    here is my test:

    echo \”1)\”;

    echo $bp->loggedin_user->fullname;

    echo \”2)\”;

    echo $bp->loggedin_user->username;

    echo \”3)\”;

    echo $bp->loggedin_user->id;

    echo \”4)\”;

    echo $bp->displayed_user->fullname;

    echo \”5)\”;

    echo $bp->displayed_user->username;

    echo \”6)\”;

    echo $bp->displayed_user->id ;

    here is the result:

    1)Andrea R.

    2)

    3)23

    4)Andrea R.

    5)

    6)23


    nicolagreco
    Participant

    @nicolagreco

    use fullname, username is

    global $current_user;

    $current_user->username;

    $current_user->nicename;

    $current_user->display_name;

    $current_user->loginname; <= this could be wrong, check the codex


    Burt Adsit
    Participant

    @burtadsit

    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.


    Burt Adsit
    Participant

    @burtadsit

    Posting around each other again aren’t we nicola? :)


    belogical
    Participant

    @belogical

    thanks all for the help, chewing on this now


    belogical
    Participant

    @belogical

    I ended up using this, which I assume is a WP variable in case anyone can use it.

    global $current_user;

    $username = $current_user->user_login;

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Global Variable – Username not ID’ is closed to new replies.
Skip to toolbar