Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

  • @robkk

    Moderator

    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 14 replies - 1 through 14 (of 14 total)
  • @robin-w

    Moderator

    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

    Moderator

    @robin-w the code doesnt work for me

    @robin-w

    Moderator

    ok, i’ll load it on my test site

    @robin-w

    Moderator

    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

    Moderator

    @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

    Moderator

    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

    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

    Moderator

    @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

    Great – glad you’re fixed !

    @izzyian

    Participant

    This works for me :

    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' )
    

    BUT

    It removes the avatar from showing and the “last post by” name, on the Forums topic post lists. How can I fix this ?

    @robin-w

    Moderator

    try

    function role_show ($args) {
    

    as your first line

    @izzyian

    Participant

    @robin-w

    Hi, no this does not work :

    function role_show ($args) {
    $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' )

    This is a screen shot of that result :
    http://bitfiu.com/wp-content/uploads/2014/11/functions-picture.png

    @robkk

    Moderator

    @izzyian

    you just do it like how i did it.

    by editing the template loop-single-reply.php that was in my bbpress folder in my child theme

    separate the role from the rest of the bbp_reply_author_link

    like this

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

    <?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 bbp_reply_author_link( array( 'show_role' => true, 'type' => 'role' ) );
    	
             }
    ?>

    @izzyian

    Participant

    @robkk , That worked ! Thank you so much for breaking it down for me. you have no idea how long iv been trying to make this work 🙂

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