Only friends able to comment on profiles

Hello there –

I’m working on eliminating places where spammers can post inappropriate messages. I found the bit of code in this post really helpful in removing the ability to leave comments in public groups if you are not a member.

Now, I’d like to remove the ability to comment on members’ profiles if they are not your friend.