BuddyPress – User Login instead of Full Name [closed]

The reason it’s not working in the sidebar is likely because the sidebar content is outside the Loop, and $post data, and thus, $post->post_author, are only available inside the Loop.

You could try setting a variable equal to $post->post_author while still inside the Loop, and then passing that variable to get_userdata() in your function call outside the Loop.