Support only during business hours : Monday to friday, from 8:30 am – 5:30 pm CEST

Due to the decrease in our staff due to vacations, our response time may be longer.

Be sure we're doing our best to manage your topic as soon as possible.

Member/Forum Roles – An Update

This topic is resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Darbii Rue
    Participant
    • 4 Topics
    • 13 Posts
    @darbiirue

    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.

    Manathan
    Keymaster
    Themosaurus Support
    • 0 Topics
    • 6690 Posts
    @themodactyl

    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! 🙏🏼

Roboraptor 🦖
Themosaurus Topic Closer

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.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Member/Forum Roles – An Update’ is closed to new replies.

Troubleshooting Demo Imports

You're trying to setup your theme but you're experiencing errors when importing the demo content? Or you've just followed the setup guide but your website doesn't look exactly like our demo? These are common issues for which you can find easy and quick fixes.

Happy With our Support So Far?

Feel free to review our theme on Themeforest! It helps us making our products more known to new potential customers, which allow us more time to improve the quality and develop new features. #SharingIsCaring ❤️

Discover MatchPress

Skip • Like • Super-Like

Add powerful matching features like Member likes, skips, super likes, conditional private messaging and much more.

Setup Your Cera or Gwangi powered Community Website and Turn it into an iOS and Android App

15% discount for Cera users

To unleash the full power of your Cera or Gwangi theme, we have partnered with the Zipline team. Your community website can now be fully setup and turned into your very own custom app for iOS and Android.

Whether you've newly acquired the theme or already got your site up and running, Zipline got you covered. And we got you an incredible discount.

Holiday, Weather & Festive effects
to pimp your WordPress Site