WP Avatar not working anymore with the new BuddyPress
-
Hi,
I’m using BuddyPress on my website (gowc.fr) for several month, I was using a “hack” in functions.php to use my WP avatar in BuddyPress and it was working like a charm until the last version of BuddyPress. I have updated the plugin yesterday and now all my members have the default avatar instead of their custom avatar.The code I was using in functions.php :
add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );//late load function revert_to_default_wp_avatar( $img, $params, $item_id ){ //we are concerned only with users if( $params['object']!='user' ) return $img; //check if user has uploaded an avatar //if not then revert back to wordpress core get_avatar method //remove the filter first, or else it will go in infinite loop remove_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 ); if( !emi_user_has_avatar( $item_id ) ){ $width = $params['width']; // Set image width if ( false !== $width ) { $img_width = $width; } elseif ( 'thumb' == $width ) { $img_width = bp_core_avatar_thumb_width(); } else { $img_width = bp_core_avatar_full_width(); } $img = get_avatar( $item_id, $img_width ); } //add the filter back again add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 ); return $img; } /** * Check if the given user has an uploaded avatar * @return boolean */ function emi_user_has_avatar( $user_id=false ) { if( !$user_id ){ $user_id = bp_loggedin_user_id(); } if ( bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() ) return true; return false; }
Please help me to solve this annoying issue.
Thanks
- The topic ‘WP Avatar not working anymore with the new BuddyPress’ is closed to new replies.