WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14142 closed defect (bug) (invalid)

Custom Walker class for navigation menus

Reported by: dennis.winter Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords:
Focuses: Cc:

Description

I have tried to extend the Walker_Nav_Menu class, I just needed to overwrite the start_el method. So i added "walker"=>"My_Walker" to wp_nav_menu, I've got an error message, that the method "walk" could not be accessed statically. After a short look at the code in "nav-menu-template", I realized that in the method "walk_nav_menu_tree" the object initializer "new" is missing.

My solution can be found in the attached file.

As you can see, I've just added a "new" in front of $r->walker

And it works

Attachments (1)

nav-menu-template.diff (572 bytes) - added by dennis.winter 4 years ago.
Diff file

Download all attachments as: .zip

Change History (7)

comment:1 filosofo4 years ago

"walker" should be an instantiated object, not a class name.

dennis.winter4 years ago

Diff file

comment:2 follow-up: dennis.winter4 years ago

Ok, then the documentation has to be changed! "(string) (optional) Custom walker to use" this implies a String has to be used!

comment:3 in reply to: ↑ 2 filosofo4 years ago

Replying to dennis.winter:

Ok, then the documentation has to be changed! "(string) (optional) Custom walker to use" this implies a String has to be used!

Where does it say this?

comment:5 filosofo4 years ago

  • Keywords has-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Severity changed from major to normal
  • Status changed from new to closed

The Codex is a wiki, so any logged-in user can edit it. I just changed it to say "object."

comment:6 dennis.winter4 years ago

Ah, ok, next time i will change it by myself ;) Thx

Note: See TracTickets for help on using tickets.