Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying User role beside their replies


  • NickMackz
    Participant

    @nickmackz

    This is such an obvious feature (in my opinion) so that it is clear on forums who are the admins, moderators, and members.

    I decided to see if I could work out how to add it to my forums using my custom theme for bbPress 2.1.

    I managed to get it to work after a bit of experimentation and many errors by adding this:

    <?php

    $reply_user_id = bbp_get_reply_author_id();

    global $wp_roles;

    $reply_user = new WP_User( $reply_user_id );

    $roles = $reply_user->roles;

    $role = array_shift($roles);

    printf( isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false);

    ?>

    into loop-single-reply.php.

    Hope this is helpful to anyone else trying to do this.

    I believe it was a feature on the standalone version of bbPress so why was it dropped on the plugin version? Is this likely to be re-added at any point?

Viewing 11 replies - 1 through 11 (of 11 total)

  • Bowe
    Participant

    @bowromir

    Thank you for posting this Nick! Very helpful indeed :-) Just implemented this on our community forums!


    OC2PS
    Participant

    @sooskriszta


    POS2012
    Participant

    @pos2012

    Thank you for posting this :-)

    Added to my 2.1


    andrew55
    Participant

    @andrew55

    I’m very happy to have found this – very useful.

    Question – any suggestions on how to adjust the code to where subscribers can also view the role of other users.

    Thanks for any help.


    andrew55
    Participant

    @andrew55

    Got it – This seems to work for showing the first role:

    <?php
    $user = new WP_User( bbp_get_reply_author_id() );
    echo $user->roles[0];
    ?>

    Robkk
    Moderator

    @robkk

    @andrew55

    bbPress should do this now by default like this site has it.


    tarnvogL
    Participant

    @tarnvogl

    for me it doesn’t :/
    any suggestions why?


    tarnvogL
    Participant

    @tarnvogl

    @andrew55
    bbPress should do this now by default like this site has it.


    @robkk
    for me it doesn’t :/
    any suggestions why?


    tarnvogL
    Participant

    @tarnvogl

    @robkk for me it doesn’t :/
    any suggestions why?

    I have found the solution. I pasted the code from NickMackz into the area of the IP adress, which was only visible for admins.


    Robkk
    Moderator

    @robkk

    alright but by default it does show.

    in the default file of loop-single-reply.php

    you will see this

    <div class="bbp-reply-author">
    
    		<?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    
    		<?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
    
    		<?php if ( bbp_is_user_keymaster() ) : ?>
    
    			<?php do_action( 'bbp_theme_before_reply_author_admin_details' ); ?>
    
    			<div class="bbp-reply-ip"><?php bbp_author_ip( bbp_get_reply_id() ); ?></div>
    
    			<?php do_action( 'bbp_theme_after_reply_author_admin_details' ); ?>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>
    
    	</div><!-- .bbp-reply-author -->

    this is the code that shows it , hence the show role = true

    <?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>


    Rivaldo07
    Participant

    @rivaldo07

    Any way to show this with an image? And how? I’ve designed some user roles in Photoshop, and I would really like to use them instead of the text.

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