Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display the poster’s user role in forums for that specific group

  • Hello….. this little hack is probably very simple, or hard… but how do you put the forum poster’s user role under their avatar in a specific group?

    For example…. I have a group with 2 admins. So when they post in forums for that group, under their avatar is says “Administrator”

    And regular members just say “members” and Mods say “moderator”

    Thanks!

    p.s, i could hire someone to write this hack :)

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

  • Bigjimmysisco
    Member

    @bigjimmysisco

    +1


    Virtuali
    Participant

    @gunju2221

    I would have to give this a +1! :) Don’t you just love hacks? :D

    it would probably require some heavy data collecting if you want it to be just that specific group. Especially if you have a-lot of mods or admins


    Bigjimmysisco
    Member

    @bigjimmysisco

    Hacks??? are we breaking rules?


    r-a-y
    Keymaster

    @r-a-y

    Check out /buddypress/bp-groups/bp-groups-templatetags.php.

    In particular, here are the conditional functions you’re looking for:

    `bp_group_is_admin(); // will return true if the user is a group admin

    bp_group_is_mod(); // will return true if the user is a group mod`

    Use in a conditional statement and you’re good to go!

    eg.

    `if ( bp_group_is_mod() ) echo ‘Group Moderator’;`

    Thanks r-a-y. So I stick the second code where I want the text to appear right?

    The first code I am totally lost.


    r-a-y
    Keymaster

    @r-a-y

    Yeah, the second code; I was just trying to explain where you can find useful functions for groups ;)


    r-a-y
    Keymaster

    @r-a-y

    Try it!

    Be sure to wrap it around php tags though.

    @r-a-y, I put the second code below the

    but nothing appears..


    r-a-y
    Keymaster

    @r-a-y

    Sorry about that! I thought it would work. Looks like BP is missing some template tags for this.

    This will work.

    Add the following to your theme’s functions.php:

    `
    function bp_topic_poster_is_admin() {
    global $topic_template;
    return BP_Groups_Member::check_is_admin( $topic_template->post->poster_id, bp_get_the_topic_object_id() );
    }

    function bp_topic_poster_is_mod() {
    global $topic_template;
    return BP_Groups_Member::check_is_mod( $topic_template->post->poster_id, bp_get_the_topic_object_id() );
    }`

    Then use this in your template:

    `if ( function_exists( ‘bp_topic_poster_is_mod’ ) ) :
    if ( bp_topic_poster_is_mod() ) echo ‘Group Moderator’;
    endif;`

    Awesome! now if I could just style it enough to show up under the avatar…

    @r-a-y, I found a little incompatibility with your code, and with The “bp unread posts” plugin, it seems that this code is making it not to appear

    `function bp_unread_posts_record_activity() {
    global $bp;
    global $forum_template;
    if ( bp_has_forum_topic_posts() ) $bb_this_thread = $forum_template->topic->topic_id;
    if (empty($bb_this_thread)) {
    return $null;
    }
    $bbtype = ‘last_visits_user_’;
    $bbuser = $bp->loggedin_user->id;
    $bb_this_visit_time = strtotime($forum_template->topic->topic_time);
    $bb_last_visit = bb_get_topicmeta($bb_this_thread, $bbtype . $bbuser);
    if($bb_last_visit != $bb_this_visit_time) {
    bb_update_topicmeta($bb_this_thread, $bbtype . $bbuser, $bb_this_visit_time);
    }
    }`

    what is making it not appear?

    Im thinking it is this line: `if ( bp_has_forum_topic_posts() ) $bb_this_thread = $forum_template->topic->topic_id;`

    any ideas ray?


    r-a-y
    Keymaster

    @r-a-y

    Not sure. I haven’t used the BP Unread Posts plugin before, but if that plugin modifies the $topic_template global, then it will probably interfere with the code.

    is there a way around it? I would love both


    peeld
    Participant

    @peeld

    This code pretty much does exactly what I want, which is to display the user’s role/level in forums. I got it to work for Admin and Mod, but I’m a code idiot so I’m not sure how to get it to work with other levels? I’m using s2Member so I have levels that are written to BP/WP users like Working Student, Auditing Student, Free Subscriber, etc.

    Tips?

    TIA,
    Daisy


    peeld
    Participant

    @peeld

    Bump


    Jordash
    Participant

    @jordash

    I can’t get this to work, I added those functions to the functions.php file and put in the if statement, but it doesn’t detect whether they are a moderator or not.

    Any idea whats up?


    Jordash
    Participant

    @jordash

    Nvm got it working.

Viewing 19 replies - 1 through 19 (of 19 total)
  • The topic ‘How to display the poster’s user role in forums for that specific group’ is closed to new replies.
Skip to toolbar