Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active April 6, 2022 03:46
Show Gist options
  • Save ronalfy/265bd1e42bd3ce2513ef68f9c561b2fd to your computer and use it in GitHub Desktop.
Save ronalfy/265bd1e42bd3ce2513ef68f9c561b2fd to your computer and use it in GitHub Desktop.
User Profile Picture With BuddyPress
add_filter( 'bp_core_fetch_avatar', 'mpp_bp_avatar', 10, 2 );
function mpp_bp_avatar( $img, $params ) {
// Determine if user has an avatar override
$avatar_override = get_user_option( 'metronet_avatar_override', $params[ 'item_id' ] );
if ( !$avatar_override || $avatar_override != 'on' ) return $img;
$profile_post_id = absint( get_user_option( 'metronet_post_id', $params[ 'item_id' ] ) );
if ( 0 === $profile_post_id || 'mt_pp' !== get_post_type( $profile_post_id ) ) {
return $img;
}
if ( has_post_thumbnail( $profile_post_id ) ) {
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $profile_post_id ), array( $params[ 'width' ], $params[ 'height' ] ) , false, '' );
//Get custom filter classes
$mpp_img = sprintf( '<img src="%s" width="%d" height="%d" alt="%s" class="%s" />', esc_url( $thumb_src[ 0 ] ), absint( $params[ 'width' ] ), absint( $params[ 'height' ] ), esc_attr( $params[ 'alt' ] ), esc_attr( $params[ 'class' ] ) );
return $mpp_img;
}
return $img;
}
@sarankxbczjn
Copy link

mpp-bp.php

@sarankxbczjn
Copy link

gist

@sarankxbczjn
Copy link

mpp-bp.php

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