Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display user role only for keymasters and moderators??


  • Robkk
    Participant

    @robkk

    i want to only display user role on keymaster and moderators users.

    I dont want every participant to have the role shown , only the keymaster and moderators are important enough to me to show their role next to their avatar.

    How would i do that??

    im just using this code to display the users role

    <div class=reply-author-role><?php bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) ); ?></div>

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

  • Robin W
    Moderator

    @robin-w

    untested but the following bar typos should work – add to your functions file

    function role_show () {
    $role = bbp_get_user_role( $user_id );
    if ( bbp_is_user_keymaster() ||$role == 'bbp_moderator')  $args['show_role'] = true ;
    else $args['show_role'] = false ;
    return $args ;
    }
    
    add_filter ('bbp_before_get_reply_author_link_parse_args', 'role_show' ) ;
    

    Robkk
    Participant

    @robkk

    @robin-w the code doesnt work for me


    Robin W
    Moderator

    @robin-w

    ok, i’ll load it on my test site


    Robin W
    Moderator

    @robin-w

    wasn’t setting who the user was ! Try

    function role_show () {
    $displayed_user = bbp_get_reply_author_id() ;
    $role = bbp_get_user_role( $displayed_user);
    if ( bbp_is_user_keymaster($displayed_user) ||$role == 'bbp_moderator')  $args['show_role'] = true ;
    else $args['show_role'] = false ;
    return $args ;
    }
    add_filter ('bbp_before_get_reply_author_link_parse_args', 'role_show' ) ;
    

    Robkk
    Participant

    @robkk

    @robin-w

    ok this works great when i tryed it on a default theme.

    but on my custom bbpress theme , i seperated each item in the bbp_get_reply_author_link code and wrapped them in a class so i could better position each item.

    so im using

    <div class=bbp-reply-author-av><?php bbp_reply_author_link( array( 'show_role' => false, 'type' => 'avatar' ) ); ?></div>

    <div class=bbp-reply-author-name><?php bbp_reply_author_link( array( 'show_role' => false, 'type' => 'name' ) ); ?></div>

    <div class=reply-author-role><?php bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) ); ?></div>

    now i have 3 avatars, 3 author links, 3 author roles displaying on 1 reply now.

    how should the code be if i dont want to mess with the args and i just want to display this..

    <div class=reply-author-role><?php bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) ); ?></div>

    if the display user in the reply is only a keymaster and a moderator.

    something kind of like this but where it actually works for my bbpress custom theme.

    <?php 
    $displayed_user = bbp_get_reply_author_id() ;
    $role = bbp_get_user_role( $displayed_user);
    if ( bbp_is_user_keymaster($displayed_user) ||$role == 'bbp_moderator');
    
     echo " <div class=\"reply-author-role\">";
    	
    	echo bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) );
    	
    	echo "</div>";
    	
            else {
    
    }
    ?>
    

    Robkk
    Participant

    @robkk

    ok @robin-w i got it where it just shows for keymaster but how do i add moderator

    heres what i have

    <?php 
    $displayed_user = bbp_get_reply_author_id() ;
    if ( bbp_is_user_keymaster($displayed_user)  ) {
    
     echo " <div class=\"reply-author-role\">";
    	
    	echo bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) );
    	
    	echo "</div>";
    	
             }
            else {
    
    }
    ?>

    Robin W
    Moderator

    @robin-w

    yes that’ll do it, put the ‘or’ in and it should be fine eg

    <?php 
    $displayed_user = bbp_get_reply_author_id() ;
    $role = bbp_get_user_role( $displayed_user);
    if ( bbp_is_user_keymaster($displayed_user)  || $role == 'bbp_moderator'  ) {
    
     echo " <div class=\"reply-author-role\">";
    	
    	echo bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) );
    	
    	echo "</div>";
    	
             }
            else {
    
    }
    ?>
    
    

    The || is an ‘or’ argument, so the if line says ‘if user is keymaster or (||) moderator’ then…

    The else is not really needed, as I presume you’ll do nothing, as you only want it to display if…

    Come back and let us known that it worked.


    Robkk
    Participant

    @robkk

    @robin-w yeah worked great , and i will use the (||) if i want to add a special user role later , and yeah i took off the else too.

    Thank you.


    Robin W
    Moderator

    @robin-w

    Great – glad you’re fixed !

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

You must be logged in to reply to this topic.