Do human anal glands have any function?
They are vital if not incredibly useful in many other mammals but not humans. People have tried to look for a role and seen that they activate in times of stress or anxiety. However this probably only serves to heighten both stress and anxiety as you now also don't smell that great either. There is no identifiable role in humans apart from causing a variety of disorders such as an abcess.

When physically examining a patient with a very painful condition, doing something that greatly provokes symptoms will often cause the anal glands to secrete. As a doctor, I interpret it as a clear warning that the patient is in distress, and that I need to exercise greater caution. I don't know of any science supporting this, but the function seems self-evident.