get_avatar filter in WordPress 4.4, how to filter properly

Hopefully this will help someone else in the future.

Number of Parameters

Change the number of parameters in the set_avatar method to 6. The $args was added as the 6th.

Fix the options-discussion.php page

Next, the options-discussion.php page wasn’t showing avatars properly and so the is_admin block of code needed to be added.

    public function set_avatar( $avatar, $id_or_email, $size="96", $default="", $alt = false, $args ) {

        if ( ! get_option( 'show_avatars' ) ) {
             return false;
        }

        // Properly show Avatars and Gravatars on the options-discussion.php page
        if ( is_admin() ) {
            $screen = get_current_screen();
            if ( is_object( $screen ) && in_array( $screen->id, array( 'dashboard', 'options-discussion' ) ) && ( $default != 'XenForo' ) ) {
                return $avatar;
            }
        }
    }

Debug in many places to check is_numeric, is_object, etc.

Next, a Zend_debug showed $id_or_email an object was being returned and this helped tremendously. In each of the conditionals, work to the $id.

After the conditional, use the $id to grab userinfo, and ultimately the URL ($out).

Return $avatar

The return $avatar is important, therefore, the ending lines require setting a url ($out).

        $avatar = "<img alt="{$safe_alt}" src="https://wordpress.stackexchange.com/questions/213892/{$out}" class="avatar avatar-{$size} photo" height="{$size}" width="{$size}" />";
        return $avatar;

I hope this helps others trying to filter avatars rather than replace the get_avatar.