Created
April 7, 2020 05:05
-
-
Save KaineLabs/b4c9b439da464cfb4dd4939c269c0711 to your computer and use it in GitHub Desktop.
Add Badges Beside Username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add Badges Beside Username | |
*/ | |
function add_badge_after_icon($username){ | |
$user_id = ! empty( $user_id ) ? $user_id : bp_displayed_user_id(); | |
$user_badges = mycred_get_users_badges( $user_id ); | |
$badges_nbr = count( $user_badges ); | |
if ( $badges_nbr <= 0 ) { | |
return $username; | |
} | |
$user_badges = array_slice( $user_badges, 0, $max_badges, true ); | |
foreach ( $user_badges as $badge_id => $level ) { | |
$badge = mycred_get_badge( $badge_id, $level ); | |
if ( $badge === false ) continue; | |
$badge->image_width = 25; | |
$badge->image_height = 25; | |
if ( $badge->level_image !== false ){ | |
$badges .= '<div style="margin-top: -3px; padding-left: 7px; height: 25px; padding-top: 6px;" data-yztooltip="'. $badge->title .'">'; | |
$badges .= apply_filters( 'mycred_the_badge', $badge->get_image( $level ), $badge_id, $badge, $user_id ); | |
$badges .= '</div>'; | |
} | |
} | |
return $username . $badges; | |
} | |
add_filter( 'yz_user_profile_username', 'add_badge_after_icon', 12 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment