Skip to:
Content
Pages
Categories
Search
Top
Bottom

BadgeOS points under username in forum


  • florianm
    Participant

    @florianm

    For our restricted members bbPress forum, I would like to display a user’s BadgeOS points below their username next to their posts/replies. I already found some code to display these points but I am not sure if it’s correct and how to make it show below the username.

    function badgeos_get_users_points( $user_id = 0 ) {
    // Use current user’s ID if none specified
    if ( ! $user_id )
    $user_id = wp_get_current_user()->ID;
    // Return our user’s points as an integer (sanely falls back to 0 if empty)
    return absint( get_user_meta( $user_id, ‘_badgeos_points’, true ) );
    }

    Any help would be much appreciated!

    FYI: we also use the latest versions of BuddyPress and the Boss theme.

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

  • Robin W
    Moderator

    @robin-w

    BadgeOS is a plugin so I can’t comment on whether your code would work – it looks fine from a technical point of view.

    I’ve tweaked it so that it shows the points for each user rather than the current user and added the function to get it below the author name, so if the function is correct this code should work.

    add_action ('bbp_theme_after_reply_author_details', 'badgeos_show_users_points') ;
    
    function badgeos_show_users_points( $user_id = 0 ) {
     $user_id = bbp_get_reply_author_id();
     // echo our user’s points as an integer (sanely falls back to 0 if empty)
     $points = absint( get_user_meta( $user_id, '_badgeos_points', true ) );
     echo $points ;
     }

    let me know if it works


    Robin W
    Moderator

    @robin-w

    although you may want to alter the last line to something like

    echo 'Points: '.$points ;

    so that more than just a number appears !


    florianm
    Participant

    @florianm

    It works! awesome… thank you very much 🙂


    florianm
    Participant

    @florianm

    One last question… Is it possible to add some class or id to it so that I can style it easily with CSS?


    Robin W
    Moderator

    @robin-w

    glad it works

    yes just change that line to

    echo '<div class="badge-os"> Points: '.$points.'</div>' ;

    change the class name to anything you want.

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