• Resolved janak Kaneriya

    (@janak007)


    Hi,

    I have checked the code of the plugin found that the plugin hook into the avatar filter of BuddyPress plugin.

    Code explanation.

    return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    This plugin hook on preparing the avatar image tag and it’s working fine.

    But when I want just avatar URL of the user this plugin doesn’t hook on that filter here is the code of that.

    return apply_filters( 'bp_core_fetch_avatar_url', $gravatar, $params );

    Here is the code that you can add into your plugin.

    function oa_social_login_bp_custom_fetch_avatar_url( $text, $args ) {
    
    	//The social login settings
    	static $oa_social_login_avatars = null;
    	if ( is_null( $oa_social_login_avatars ) ) {
    		$oa_social_login_settings = get_option( 'oa_social_login_settings' );
    		$oa_social_login_avatars  = ( isset ( $oa_social_login_settings ['plugin_show_avatars_in_comments'] ) ? $oa_social_login_settings ['plugin_show_avatars_in_comments'] : 2 );
    	}
    
    	//Check if avatars are enabled
    	if ( ! empty ( $oa_social_login_avatars ) ) {
    		//Check arguments
    		if ( is_array( $args ) ) {
    			//User Object
    			if ( ! empty ( $args ['object'] ) AND strtolower( $args ['object'] ) == 'user' ) {
    
    				//User Identifier
    				if ( ! empty ( $args ['item_id'] ) AND is_numeric( $args ['item_id'] ) ) {
    
    					//Retrieve user
    					if ( ( $user_data = get_userdata( $args ['item_id'] ) ) !== false ) {
    						remove_filter( 'bp_core_fetch_avatar_url', 'oa_social_login_bp_custom_fetch_avatar_url', 10 );
    						//Only replace if the user has the default avatar (this will keep uploaded avatars)
    						if ( oa_social_login_has_bp_user_uploaded_avatar( $args ['item_id'] ) == false ) {
    
    							//Read the avatar
    							$user_meta_thumbnail = get_user_meta( $args ['item_id'],
    								'oa_social_login_user_thumbnail',
    								true );
    							$user_meta_picture   = get_user_meta( $args ['item_id'],
    								'oa_social_login_user_picture',
    								true );
    
    							//Use the picture if possible
    							if ( $oa_social_login_avatars == 2 ) {
    								$user_picture = ( ! empty ( $user_meta_picture ) ? $user_meta_picture : $user_meta_thumbnail );
    							} //Use the thumbnail if possible
    							else {
    								$user_picture = ( ! empty ( $user_meta_thumbnail ) ? $user_meta_thumbnail : $user_meta_picture );
    							}
    
    							//Avatar found?
    							if ( $user_picture !== false AND strlen( trim( $user_picture ) ) > 0 ) {
    								//Replace
    								$text = $user_picture;
    							}
    						}
    						add_filter( 'bp_core_fetch_avatar_url', 'oa_social_login_bp_custom_fetch_avatar_url', 10, 2 );
    					}
    				}
    			}
    		}
    	}
    
    	add_filter( 'clean_url', 'oa_social_login_bp_custom_fetch_avatar_url_esc', 10, 3 );
    
    	return $text;
    }
    add_filter( 'bp_core_fetch_avatar_url', 'oa_social_login_bp_custom_fetch_avatar_url', 10, 2 );
    
    function oa_social_login_bp_custom_fetch_avatar_url_esc( $good_protocol_url, $original_url, $_context ) {
    	return $original_url;
    }

    Please make sure above code is not tested. It should be tested thoroughly all the components of BuddyPress when the member avatar is displayed

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Plugin Author Claude

    (@claudeschlesser)

    Hello,

    thank you so much! We will add this code to the next release of the plugin. It should be released by this week.

    Best Regards,

Viewing 1 replies (of 1 total)
  • The topic ‘BuddPress and BuddyBoss Platform plugin support’ is closed to new replies.