Created
December 14, 2017 16:02
-
-
Save dcavins/31c2f264d0e56cd2832cb3c63a994b97 to your computer and use it in GitHub Desktop.
Add the user's roles to the classes applied to a BuddyPress avatar.
This file contains hidden or 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
<?php | |
add_filter( 'bp_get_member_avatar', 'my_add_user_level_to_avatars', 10, 2 ); | |
/** | |
* @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. | |
* @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}. | |
*/ | |
function my_add_user_level_to_avatars( $value, $r ) { | |
global $members_template; | |
// The args have already been parsed in bp_get_member_avatar. We'll use them except for the css class. | |
$class = array( $r['class'] ); | |
// Get user roles. | |
$user_info = get_userdata( $members_template->member->id ); | |
if ( ! empty( $user_info->roles ) ) { | |
$class = array_merge( $class, $user_info->roles ); | |
} | |
// Convert array to space-separated string. | |
$class = implode( ' ', $class ); | |
return bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $r['type'], 'alt' => $r['alt'], 'css_id' => $r['id'], 'class' => $class, 'width' => $r['width'], 'height' => $r['height'], 'email' => $members_template->member->user_email ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment