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 bbPress 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 2 replies - 1 through 2 (of 2 total)

  • 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


    laddi
    Participant

    @laddi

    Really thankful for valuable reply and code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar