Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do you display user roles in BuddyPress public profiles?

  • @curiousrabbit

    Member

    I needed certain BuddyPress members to have specific member levels, such as bronze, silver, and gold. To create these new user roles, I installed Justin Tadlock’s Members plugin: http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin

    How would I go about displaying the user role on each user’s public profile page, such as under their name (and above their status)? I’m more of an xhtml/css person rather than PHP, so I’m a bit lost. I’ve read the WordPress support topic for how to display certain icons based on user role, but it didn’t help much: http://wordpress.org/support/topic/313901

    It doesn’t seem like a super complicated thing, but I have yet to find any real documentation on it with BuddyPress. Any help would be greatly appreciated. Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • @hippo1010

    Participant

    Hi!

    I’m looking for the same thing and I wonder if you were able to figure this out. help, anyone?

    @designodyssey

    Participant

    I’m no guru, so I hope someone else comes along to help more. However, what Justin indicated in his post should work for BP just like WP. In fact the “role” is created in WP through Members Plugin anyway.

    I would play with echoing the member role name (assuming you’ve assigned one). Once that is echoed, you should be able to use a function based off the thread to assign a ‘$role’.’.png’ file for the icon. It shouldn’t matter that it’s the profile page unless there is a loop problem with that page.

    If you have an appropriate development environment, Justin will probably help you get the Members plugin to echo the role on a WP page , but he’s not a BP guru, so you may be back here for the second step.

    @erich73

    Participant

    @bpisimone

    Participant

    I’m trying to do the same thing. No one seems to uderstand or is able to help out though. If I ever figure this out, I’ll post it in here.

    @xevo

    Participant

    Make a plugin or put it in your functions.php.

    function pc_get_userrole ($user_id) {
    $user = new WP_User($user_id);
    $userclean = $user->roles[0];
    return $userclean;
    }

    Call it like this.

    echo pc_get_userrole(bp_current_user_id());

    Not sure how well it works, but it worked well enough for me.

    @bpisimone

    Participant

    Exactly what I needed, thanks Xevo.

    @peeld

    Participant

    I’ve got this working, but I’d like to customize it further. I’m using S2Member, so the output from the echo statement looks like this: S2member_level1 or whatever.
    How can I set it so that if the member is this level, different text appears? For example:
    s2member_level1 = Auditor
    s2member_level2 = Worker

    I don’t really know anything about code, seems like there should be some sort of “if they’re this level, display this text” or something? And where to put that statement?

    Thanks!

    @peeld

    Participant

    Actually, it only kind of works. It shows administrator, and s2member_level1, and s2member_level3, but not s2member_level2, or anything else. Weird.

    @asoldier

    Participant

    Now I’m trying to take
    `function pc_get_userrole ($user_id) {

    $user = new WP_User($user_id);

    $userclean = $user->roles[0];

    return $userclean;

    }`

    and
    `echo pc_get_userrole(bp_current_user_id()); `

    and I want to add some custom CSS based on the role.

    @asoldier

    Participant

    I also found `user_id );

    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    foreach ( $user->roles as $role )
    echo “display_name}’ />”;
    }?>`

    but it doesn’t want to work in the profile

    @hnla

    Participant

    Please start a fresh topic rather than resurrecting 3 year old ones which may well have little relevance code wise as the app iterates through new versions.

     

    Also you need to explain a little further what you are trying to do; custom CSS ? So what do you propose you hook that css onto?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How do you display user roles in BuddyPress public profiles?’ is closed to new replies.
Skip to toolbar