Find Answers and Get Support › Forums › Armadon – Gaming Community WordPress Theme › Popular Features › Forums › Member/Forum Roles – An Update
- This topic has 1 reply, 2 voices, and was last updated 2 years, 8 months ago by
Manathan.
-
AuthorPosts
-
Darbii RueParticipant@darbiirue
- 4 Topics
- 13 Posts
Hi everyone! I had an original question posted prior to this asking for help and I was directed to BuddyDev to find out if they could help me with the specifics of my ask.
What I wanted was for the member roles that you set up in Member Types to display, rather than the Author Types the site uses by default. In my example picture, you’ll see that originally it showed Keymaster, now it shows Guild Leader.
This piece of code will allow you to show the Member Types in your forum:
/** * BuddyPress Member Types for Forum */ 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 );
To remove the Author Types from showing, and showing only Member Types that you’ve created, add this code:
/** * 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 );
This is all thanks to Brajesh and Ravi over at the BuddyDev forums.
June 16, 2022 at 15:44 #41151@themodactyl- 0 Topics
- 6690 Posts
Hi Darbii,
We thank you very much for sharing this awesome solution with us. I’m sure it will help other users facing the same request. By doing this, you’re making a great contribution to this forum, and we thank you very much for that! #SharingIsCaring 💪🏻
Thank you again! 🙏🏼
June 17, 2022 at 09:27 #41165 -
AuthorPosts
Hi there,
This topic has been inactive for a while now so we will be closing it to keep the forum tidy. Don't hesitate to create a new topic if you still need help and we'll be glad to help you!
Best regards,
The Themosaurus team.
The topic ‘Member/Forum Roles – An Update’ is closed to new replies.