Update to Get Avatar Function – Change ID based off user role/capabilities
-
Wanted to add different color borders around admin avatars, moderators, premium members, free members, etc to allow for easy identification of community roles. Unfortunately there are no CSS selectors in the avatars natively to do this…
As a solution I updated the function bp_get_member_avatar(), it now gives an ID to each avatar depending on the user’s role/capabilities
function bp_get_member_avatar( $args = '' ) { global $members_template; $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name; $defaults = array( 'type' => 'thumb', 'width' => false, 'height' => false, 'class' => 'avatar', 'id' => false, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ) ); //START EDIT HERE $user = get_user_by('login', $members_template->member->user_login); //RETREIVE WP USER OBJECT if($user){ if (user_can($user,'edit_users')){ //CHECK USER CAPABILIRY $defaults['id'] = 'admin_avatar'; //ASSIGN ID BASED OFF USER ROLE } elseif (check_role($user->ID,'moderator')){//CHECK USER ROLE $defaults['id'] = 'mod_avatar'; } elseif (user_can($user,'premium_member')){ $defaults['id'] = 'prem_avatar'; } else { $defaults['id'] ='free_avatar'; } } $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) ); }
Note: This can be made much more flexible by turning it into it’s own function, but I have no need for that right not (lots of other stuff to configure).
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Update to Get Avatar Function – Change ID based off user role/capabilities’ is closed to new replies.