Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Show bbPress User Role on BP Profile Page?


  • laddi
    Participant

    @laddi

    Hello to all the BuddyPress Scientists out there.

    I am almost mad about to show bbPress User Role on BuddyPress Profile Page. And I am currently using this code, but it is not perfect and correct.

    
    function show_user_role () 
    		{
    		global $bp;
    		$reply_id = bbp_get_reply_id( $reply_id );
    		$abc_role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );
    		echo '<span class="profile-role ' . $abc_role . '"><i class="fa fa-star"></i> <em>';
    		echo $abc_role;
    		echo '</em></span>';
    	}
    add_action( 'bp_before_member_header_meta', 'show_user_role' );
    

    The demo output can be seen on http://www.punjabi.cc/ website by visiting any members profile.

    First problem with this code is, it does not show correct name for dynamic roles when user is not logged in.

    Second problem, the users who are blocked also tagged ‘Member’ not ‘Blocked’.

    Please either correct it or provide me a another perfect piece of code, I will be highly thankful.

    Regards,
    Laddi

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

  • shanebp
    Moderator

    @shanebp

    Try:
    $abc_role = bbp_get_user_display_role( bp_displayed_user_id() );


    laddi
    Participant

    @laddi

    I am sorry shanebp, its not working… 🙁

    no effect at all


    shanebp
    Moderator

    @shanebp

    This works properly on my test install, put in bp-custom.php

    function laddi_show_user_role () {
    	$abc_role = bbp_get_user_display_role( bp_displayed_user_id() );
    	echo '<br/><span class="profile-role ' . $abc_role . '"><i class="fa fa-star"></i><em>';
    	echo $abc_role;
    	echo '</em></span>';
    }
    add_action( 'bp_before_member_header_meta', 'laddi_show_user_role' );

    Stagger Lee
    Participant

    @stagger-lee

    add_action( 'bp_before_member_header_meta', 'devb_show_role_on_profile');
    function devb_show_role_on_profile(){
     global $wp_roles;
     
    $user_id = bp_displayed_user_id();
     
    $user = get_userdata( $user_id );
     
    $roles = $user->roles;
     
     if( !$roles)
     return ;
     
     if ( !isset( $wp_roles ) )
     $wp_roles = new WP_Roles();
     
     $named_roles = array();
     
    foreach( $roles as $role ){
     
    $named_roles [] = $wp_roles->role_names[$role];
     }
     
    if( $named_roles )
     echo '<span class="user-role activity">'. join( ', ', $named_roles ) . '</span>';
     
    }

    Showing User role on BuddyPress Profile

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to Show bbPress User Role on BP Profile Page?’ is closed to new replies.
Skip to toolbar