Last active
April 6, 2022 03:46
-
-
Save ronalfy/265bd1e42bd3ce2513ef68f9c561b2fd to your computer and use it in GitHub Desktop.
User Profile Picture With BuddyPress
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
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; | |
} |
gist
mpp-bp.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mpp-bp.php