Skip to:

Roles under username (.bbp-author-role)

  • tommysvr



    Iโ€™m not sure if this would be considered a request or perhaps just a modification I could make, so forgive me if this is the wrong section.

    I would like to be able to display an image based on a users role. That is, if theyโ€™re a subscriber, the would have a the relevant subscriber image. The same for mods, admin etc. I feel the easiest way to do this would be with CSS, but unfortunately the role underneath a username on a post only has the class .bbp-author-role. Would it be possible to add another class such as .bbp-author-role-subscriber to allow further customisation?

    Iโ€™m a bit of a php novice, so Iโ€™m completely sure where to start with it. I also feel this could be beneficial to others.

    Thanks in advance.

    • This topic was modified 11 years, 7 months ago by tommysvr.
    • This topic was modified 11 years, 7 months ago by tommysvr.
    • This topic was modified 11 years, 7 months ago by tommysvr.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi, I can help you with this. I am doing the same and needed to figure it out as well. Hopefully they’ll add this in updated versions… Seems like a basic feature that can add awesome visual option via CSS. Anyways, I will assume you know a bit of CSS. For the PHP, I recommend that you create a folder “bbpress” inside your WP theme folder, i.e. wp-content/themes/yourtheme/bbpress Then go to /plugins/bbpress/bbp-theme-compat/bbpress and copy/paste the file “loop-single-reply.php” to your newly created bbpress folder from above. What this does is now make bbPress use that file instead of the default one. Now you can make changes to it and not worry about updates to bbPress overwriting your changes. On line ~ 30, you’ll see an opening DIV with id=”post-*some php”…

    On the next line, enter this:

    $reply_id = bbp_get_reply_id( $reply_id );
    $abc_role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );

    Then the next line that’s already there should be:

    div class="bbp-reply-author"

    Turn it into this:

    div class="bbp-reply-author ?php echo $abc_role ?>"

    Add the bracket < before the first ?php in that above statment… I dont know why its not letting me show it.

    And there you have it. The CSS class name will now contain the verbatim user role… This means that "Key Master" will actually be in the class.. No problem, just use:

    div.Key { color: #abc }

    to target the admin. Sure, “Master” will be in there but, but it’ll be taken as 2 different classes, “Key” and “Master”. With additional pvp, you could turn it into “keymaster” but its not necessary for 99.9% of applications and would just run more PHP. I’m literally doing this right now, so i havent checked other template files, but it’s the same thing.. So for instance, if you want to change the css in the index for only admins, to have lets say a special color link, find the template file that displays the index, add that same snippet in, and it will work the same. have fun. ๐Ÿ™‚



    Genius! Thank you very much!



    Perfect solution – thanks a bunch!



    @synergywp1 I can’t get this to work…Can you post the whole code on and share it? I would really appreciate it.



    Still no clue where to add `$reply_id = bbp_get_reply_id( $reply_id );
    $abc_role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );`

    I tried on the location where u said, like this:

    <div id="post-<?php bbp_reply_id(); ?>" class="bbp-reply-header">
    $reply_id = bbp_get_reply_id( $reply_id );
    $abc_role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );
    	<div class="bbp-meta">
    		<span class="bbp-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    		<?php if ( bbp_is_single_user_replies() ) : ?>
    			<span class="bbp-header">
    				<?php _e( 'in reply to: ', 'bbpress' ); ?>
    				<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink( bbp_get_reply_topic_id() ); ?>"><?php bbp_topic_title( bbp_get_reply_topic_id() ); ?></a>
    		<?php endif; ?>
    		<a href="<?php bbp_reply_url(); ?>" class="bbp-reply-permalink">#<?php bbp_reply_id(); ?></a>
    		<?php do_action( 'bbp_theme_before_reply_admin_links' ); ?>
    		<?php bbp_reply_admin_links(); ?>
    		<?php do_action( 'bbp_theme_after_reply_admin_links' ); ?>
    	</div><!-- .bbp-meta -->
    </div><!-- #post-<?php bbp_reply_id();?>-->

    But this just shows the custom code on the website instead of running it.

    please help on this ๐Ÿ™‚

    See the code I just posted here, add’s the CSS classes without template modifications ๐Ÿ™‚

    Topic background color depending on role

    Also going to close this, rather than others bumping it in the future ๐Ÿ˜‰

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Roles under username (.bbp-author-role)’ is closed to new replies.
Skip to toolbar