BuddyDev

Search

[Resolved] BuddyPress Member Types in bbPress Forums

  • Participant
    Level: Initiated
    Posts: 3
    Darbii Rue on #45097

    Hi there! New to this support forum and hoping to get some information on the BuddyPress Member Types plugin. I’m using the theme ‘Armadon’ by Themosaurus, which is super robust and includes a lot of Buddy plugins. After quite some time I figured out how to make Member Types (super thankful for the video on this), however, this theme, of course, doesn’t include the full paid version of the BuddyPress Member Types plugin. I’m considering purchasing it, but I’d like to know the following:

    Does this allow me to show the user’s Member Type in the forums? Currently, bbPress appears to only be showing the WP version of membership (so for instance, mine says ‘Keymaster’), but I don’t want them to display like this because it isn’t representative of our actual ranking system. I would rather mine said ‘Guild Leader.’

    Can the BuddyPress Member Types plugin achieve this? If not, is there something you would recommend that may?

    Thank you in advance!

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #45106

    Hi Darbii,
    Welcome to BuddyDev support forums.

    We do not have access to the theme but it is not difficult to show the member type in forum.

    You do not need to purchase the member type pro plugin for this. It will need couple of lines of code to achieve that.

    Ravi or I will share the code in the day tomorrow.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Darbii Rue on #45278

    Hi Brajesh,

    Thanks for getting back to me on this. I never did hear back with the code, so I thought I’d reach back out! It’s great news that it’s just a bit of code. I look forward to hearing back from you. 🙂

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2449
    Ravi on #45281

    Hello Darbii,

    Sorry for the delayed reply. Please use the following code in your ‘bp-custom.php’ file or active theme ‘functions.php’ file.

    
    
    add_filter( 'bbp_get_reply_author_role', function ( $author_role, $r, $args ) {
    
    	if ( ! function_exists( 'bp_get_member_type' ) ) {
    		return $author_role;
    	}
    
    	$reply_id    = bbp_get_reply_id( $r['reply_id'] );
    	$member_type = bp_get_member_type( bbp_get_reply_author_id( $reply_id ) );
    	$member_type = $member_type ? bp_get_member_type_object( $member_type )->labels['singular_name'] : '';
    
    	// Backwards compatibility with old 'class' argument.
    	if ( ! empty( $r['class'] ) ) {
    		$author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $member_type ), $r['after'] );
    	} else {
    		$author_role = $r['before'] . $member_type . $r['after'];
    	}
    
    	return $author_role;
    }, 10, 3 );
    
    

    It will show Member type on the single topic page. Please check

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 3
    Darbii Rue on #45402

    Thank you! I finally was able to take some time to create a child theme and install this code.

    Unfortunately, I’m still having some issues. On my forum, it now shows the first post I made as ‘Keymaster’ and the reply as ‘Guild Leader’ and I’m not sure why… I don’t want ‘Keymaster’ to show at all, ever, anywhere if possible.

    Can you please see this picture and let me know if you have any ideas?

    https://i.imgur.com/Eza6D5x.png

    Thanks!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2449
    Ravi on #45406

    Hello Darbii,

    Thank you for the acknowledgement. It seems your theme uses the topic author role as well. Please try the following code and let me know if it helps or not.

    
    /**
     * Replace author role with member type
     *
     * @param string $author_role Author role.
     * @param array  $r Args.
     *
     * @return string
     */
    function buddydev_bbp_replace_author_role_with_member_type( $author_role, $r ) {
    
    	if ( ! function_exists( 'bp_get_member_type' ) ) {
    		return $author_role;
    	}
    
    	$author_id = 0;
    	if ( ! empty( $r['reply_id'] ) ) {
    		$author_id = bbp_get_reply_author_id( $r['reply_id'] );
    	} elseif ( ! empty( $r['topic_id'] ) ) {
    		$author_id = bbp_get_topic_author_id( $r['topic_id'] );
    	}
    
    	if ( ! $author_id ) {
    		return $author_role;
    	}
    
    	$member_type = bp_get_member_type( $author_id );
    	$member_type = $member_type ? bp_get_member_type_object( $member_type )->labels['singular_name'] : '';
    
    	// Backwards compatibility with old 'class' argument.
    	if ( ! empty( $r['class'] ) ) {
    		$author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $member_type ), $r['after'] );
    	} else {
    		$author_role = $r['before'] . $member_type . $r['after'];
    	}
    
    	return $author_role;
    }
    
    add_filter( 'bbp_get_reply_author_role', 'buddydev_bbp_replace_author_role_with_member_type', 10, 2 );
    add_filter( 'bbp_get_topic_author_role', 'buddydev_bbp_replace_author_role_with_member_type', 10, 2 );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 3
    Darbii Rue on #45407

    You, my friend, are a genius!

    Thank you so much for your help with this. I appreciate it so much!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2449
    Ravi on #45410

    Hello Darbii,

    Thank you for the acknowledgement. I am glad that I could help.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved