Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created April 25, 2022 15:54
Show Gist options
  • Save kimcoleman/4f343c0d5239ee5f9a0e9964d7a681e9 to your computer and use it in GitHub Desktop.
Save kimcoleman/4f343c0d5239ee5f9a0e9964d7a681e9 to your computer and use it in GitHub Desktop.
Filter to use the Basic User Avatar on the BuddyPress Profile.
<?php
/**
* Filter to use the Basic User Avatar on the BuddyPress Profile.
*/
function my_bua_bp_avatar( $image, $params ) {
// Determine if user has a local avatar
$local_avatar = get_user_meta( $params['item_id'], 'basic_user_avatar', true );
if ( empty( $local_avatar ) ) {
return $image;
}
if ( ! empty( $local_avatar ) ) {
$thumb_src = $local_avatar['128'];
$bua_img = sprintf( '<img src="%s" width="%d" height="%d" alt="%s" class="%s" />', esc_url( $thumb_src ), absint( $params[ 'width' ] ), absint( $params[ 'height' ] ), esc_attr( $params[ 'alt' ] ), esc_attr( $params[ 'class' ] ) );
return $bua_img;
}
return $image;
}
add_filter( 'bp_core_fetch_avatar', 'my_bua_bp_avatar', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment