Support » Plugins » Hacks » Overriding display_element in Walker class?

  • In my process of learning how to work with the Walker class, I’ve come across a lot of online guides (including in generally high-quality venues like these forums and StackOverflow) that encourage overriding its display_element method. (Example, example, example, example.)

    However, in the Codex’s reference for the Walker class, when you look up the display_element method, it says (in bold, no less!):

    This method should be considered private and should not be called directly.

    I generally steer away hard from solutions that require making use of private/undocumented APIs, for the simple reason that such APIs tend to change with little or no warning, which can ruin your whole day. But I have yet to find any examples in this case of someone suggesting overriding this method and anyone responding that doing so is a terrible idea, despite what seems to be a very clear warning in the Codex.

    So: I wanted to check in with the community to see if this is a case of a bad practice that’s just gotten accepted by people, or if it’s a case of something that used to be bad not being so bad anymore and the Codex just being out of sync with the Walker class as it currently works/exists.

    Any thoughts?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    I have no real qualifications that enables me to give an authoritative answer, but here’s my thoughts FWIW.

    If the method was really intended to not be overridden, it could have been declared private. Instead, warnings are placed all over to not call it directly. But there are no warnings about not overriding it.

    I believe it is acceptable to override it when required, but it is never acceptable to call it directly, no matter how it was overridden. I see no conflict between what is common practice and what is officially documented. ‘Call’ and ‘override’ are not the same things at all.

Viewing 1 replies (of 1 total)
  • The topic ‘Overriding display_element in Walker class?’ is closed to new replies.