Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mohsinrasool/2dc751e938871e2fc473 to your computer and use it in GitHub Desktop.
Save mohsinrasool/2dc751e938871e2fc473 to your computer and use it in GitHub Desktop.
This gists adds User's badges earned with badgeos plugin under his avatar in topics and replies of bbpress.
<?php
add_filter( 'bbp_get_reply_author_link', 'my_append_badges_via_filter', 10, 2 );
function my_append_badges_via_filter($author_link = '', $args) {
# Needed to get the user ID of the person intended to be displayed.
$user_id = bbp_get_reply_author_id( $args['post_id'] );
#Construct your output here.
$badge_output = '';
$achievements = badgeos_get_user_achievements( array( 'user_id' => $user_id ) );
if ( !empty( $achievements ) ) {
$badge_output .= '<div class="achievements">';
foreach ( $achievements as $achievement ) {
if($achievement->post_type != 'badges')
continue;
$badge_output .= '<div class="achievement achievement-' . $achievement->post_type . '">';
//echo '<h2>' . get_the_title( $achievement->ID ) . '</h2>';
$badge_output .= get_the_post_thumbnail( $achievement->ID, 'thumbnail', array('title'=>get_the_title( $achievement->ID ) ) );
//echo __( 'Earned on: ', 'text-domain' ) . date( get_option( 'date_format' ), $achievement->date_earned ) ;
$badge_output .= '</div>';
}
$badge_output .= '</div>';
}
return $author_link . $badge_output;
}
@DivvyPT
Copy link

DivvyPT commented Sep 8, 2017

Thank you a lot my friend, I was looking for this :)

Is it possible to show only under avatar?
Currently is showing in my main forums page (next to date), in forum page (next to date) and in message notice (above topic)

Would be great too to change width to look more smaller, example 40px.
And a link to achievements tab page :)

Thanks!!

@DivvyPT
Copy link

DivvyPT commented Sep 9, 2017

To make badge smaller I added this CSS code:

.achievement.achievement-badges{width:40px;}

Any idea how to add link in badges to archivements tab page?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment