Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#25263 closed defect (bug) (fixed)

Use wp_get_nav_menus() instead of get_terms('nav_menu') in WP_Nav_Menu_Widget

Reported by: Frank Klein Owned by: wonderboymusic
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.0
Component: Widgets Keywords: has-patch commit
Focuses: Cc:


The wp_get_nav_menus() function has a wp_get_nav_menus filter that allows you to filter the array of menu objects returned by the function.

The WP_Nav_Menu_Widget class however uses a direct call to get_terms('nav_menu') to render the widget form. As such, the wp_get_nav_menus filter is not applied to the menus available on the widget configuration screen.

The attached patch fixes this by using the wp_get_nav_menus() function.

Attachments (1)

25263.patch (545 bytes) - added by Frank Klein 2 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 @SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.7

This should probably be wp_get_nav_menus( array( 'orderby' => 'name' ) ) to keep the current ordering (unlike get_terms(), wp_get_nav_menus() uses 'none' by default).

@Frank Klein2 years ago

comment:2 @Frank Klein2 years ago

Thanks, I updated the patch accordingly.

comment:3 @SergeyBiryukov2 years ago

  • Keywords commit added

When uploading a new version of a patch, please don't overwrite the old one, so that context is preserved.

comment:4 @DrewAPicture2 years ago

Tested 25263.patch by filtering on the wp_get_nav_menus hook before and after.

Works for me.

comment:5 @wonderboymusic2 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 25332:

Use wp_get_nav_menus() instead of get_terms('nav_menu') in WP_Nav_Menu_Widget to preserve use of `wp_get_nav_menus' filter.

Props Frank Klein.
Fixes #25263.

Note: See TracTickets for help on using tickets.