This statement is part myth, part true. Allow me to dissect.
I went to the Oxford English Dictionary (the 13-volume 1961 edition at my local library) for this one and perused 3 dense pages of definitions for the word “bar.” It’s not as simple as it sounds. Under nouns, there are 3 main segments: 1) “a piece of any material long in proportion to its thickness or width.” 2) “That which confines, encloses, limits, or obstructs. (a material barrier.” and 3) “a rail or barrier.” The 28th definition under #3 says “in an inn or other place of refreshment”, the word can mean, “A barrier or counter over which drink or food is served out to customers in an inn, hotel, or tavern.” Earliest written usage comes in at 1592.
As a verb, the word “to bar” has no references that are specific to a tavern or inn. There is the phrase, “to bar out,” which I know well from the 17th and very early 18th centuries when it referred to students (male, of course) “barring out” the teacher at Christmas to force him to give them time away from classes. This barring out was often very violent, involving guns and hammer & nails, but seems to have had no relation to bartending.
I checked the 1972 OED supplement, which had nothing to offer as regards our query.
I surmise from this that the word “bar” originally meant the counter or barrier. If a taproom bar in the 17th or 18th centuries had a grill or cage to lower that kept people out when the tender of the bar wasn’t there, that did “bar out” people, but I don’t take that to mean the origin of the word–which is what some docents in taverns tell their guests. I believe the origin of the word is the barrier or counter.
I’m not going to the mat on this one, so if you disagree, let’s hear it!