BuddyDev

Showing User role on BuddyPress Profile

Do you want to show user role on BuddyPress profile? One of our members asked me about the code to show use role on profile.

Before posting the code, you should remember

  • BuddyPress does not add user as subscriber on a multisite install(It just does not add the user to the main site at all), so the role won't be visible for him.

Now, the code

and here is how it looks.

Showing User role on profileHope that it helps πŸ™‚

15 Responses to Showing User role on BuddyPress Profile

  • For some reason my roles show as such:

    Administrator, Bbp_keymaster or Author, Bbp_participant (They all have that Bbp_xxx role.)

    I am running Buddypress 2.0 RC1 and WordPress 3.9 RC1 (not sure if that's causing it.) ?

    Anyway to get rid of that Bbp_xxxx part?

    Thanks!
    Charles

    • Hi Charles,
      Thank you for pointing.
      I used the role instead of role name in previous code. I have updated the code now. Can you please check. Instead of Bbp_participatnts It will show 'Participant' which is the role added by bbPress forum.

      • Works perfectly! You might want to add a space after the comma separator in join( ', (<—- add space here) as it formats better when you have multiple roles.

        Oh, and you have a minor typo in your blog post: "and here is how it looks." <- add an "s" at the end.

        Thank you so much!

        Charles

        • Thank you Charles.
          Fixed the typo and added the space πŸ™‚

  • Hi!

    This is exactly what I'm looking for. But I'm a bit new to BP so I'm still learning πŸ™‚ Could you please point me in the direction to where I should place this code?

    Thanks!
    Fredrik

  • Thanks for the code but not sure where to put it.

    • Hi Jason,
      You can put the code in your theme's functions.php or in the bp-custom.php inside the plugins directory.
      Hope that helps.

      Thanks
      Brajesh

      • Thanks that was a fast reply and it worked perfect!

      • Hi It is Jason again. My problem is it is showing many roles. I just want it to show the Buddypress role in profile. I do not want it to show the BBPress roles.

        • Hi jason,
          My apologies for not replying.
          1. There are no BuddyPress roles. it is either bbPress or WordPress.
          To avoid the bbPress roles, in the for each loop just skip the role which is bbPress.

  • Oli #

    i tryed it but it didnt work.
    i put the code into my theme function.php (hueman theme).
    i get a error message.

    i put it into my bp-custom.php but nothing happens.

    some tip for me ?

    • Hi Oli,
      If nothing happens, please check two things:-
      1. Is the User assigned some role in the WordPress backend. In case of Multisite with BuddyPress, there are issues, a user does not get a role automatically.
      2. If the above is matched, please check if your theme's member-header.php has this hook'bp_before_member_header_meta'

      Please let me know what you see there.

  • Thanks for the code! Very useful.

    I tried modified it without success, I wonder how I can show only bbPress role in the Buddypress Profile? May you advice me?

    Thanks

    • Hi Javier,
      can you please link me to your modified code. There are multiple ways to do it. either look specifically for predefined bbPress Roles in the user roles or skip the WordPress default roles.