[wp-trac] [WordPress Trac] #48015: Unexpected results from wp_nav_menu()
WordPress Trac
noreply at wordpress.org
Wed Sep 11 13:01:16 UTC 2019
#48015: Unexpected results from wp_nav_menu()
----------------------------+-----------------------------
Reporter: ChiefAlchemist | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 5.2.3
Severity: major | Keywords:
Focuses: |
----------------------------+-----------------------------
I'm using wp_nav_menu() in a shortcode. That is, I'm creating / placing a
menu within a page (or post) and using a shortcode to that (as opposed to
hardcoding it into the theme in a specific place). Specifically, I'm
placing that shortcode via the core Gutenberg block for such things, but I
don't believe that matters.
- If I pass in an empty array - wp_nav_menu([]) - it **echos** (?) a
random menu, and return null.
- If I start with the default args for the function and unset both
'theme_location' and 'menu' and then pass that array in -
wp_nav_menu([$args]) - , a random menu (same as the one echo'ed) is
returned. How can it return an menu when none were specified.
- If I specify an invalid menu name / location (i.e., it's not
registered), it returns a random array.
- For the menu it is returning, Admin > Appearance > Menus, I've unchecked
all the Display Locations. That is, the menu does exit, but it's not
associated with any locations. Still, wp_nav_menu() returns this menu.
I've done some other variations on the above trying to get empty or null
back and I get a menu.
Long to short, I'm getting results when - afaik - I shouldn't be getting
anything at all.
I'm going to add a check against the global $_wp_registered_nav_menus
before I do anything with wp_nav_menu(), perhaps wp_nav_menu() should
do similar?
I assigned a Severity = major mainly because this is a common function
that gets used A LOT. I would think / hope it should, at this point, work
flawlessly.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48015>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list