WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#32629 closed feature request (fixed)

Introduce filter for wp_get_nav_menu_object()

Reported by: westonruter Owned by: ocean90
Milestone: 4.3 Priority: normal
Severity: normal Version: 2.3
Component: Menus Keywords: has-patch
Focuses: Cc:

Description (last modified by westonruter)

For Menu Customizer (#32576) we need a filter which can filter the return value for wp_get_nav_menu_object() to supply with the pending nav_menu term that is currently being previewed. This can be seen in action in the Menu Customizer plugin: class-wp-customize-nav-menu-setting.php. See attached for patch.

Change History (8)

#1 @westonruter
4 years ago

  • Keywords has-patch added
  • Owner set to boonebgorges
  • Status changed from new to reviewing

#2 follow-up: @boonebgorges
4 years ago

A bypass filter for get_term() is a very powerful tool. I'm concerned that (a) it's liable to be misused, and (b) if we introduce such a filter here, we'll be asked for similar filters elsewhere in the taxonomy component (wp_update_term(), get_terms(), etc) as well as for objects like posts.

Looking at how you're using the filter, it seems like a filter on the return value of wp_get_nav_menu_object() would actually work better for your purposes. Does that seem right?

Last edited 4 years ago by boonebgorges (previous) (diff)

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


4 years ago

#4 in reply to: ↑ 2 @westonruter
4 years ago

  • Component changed from Taxonomy to Menus
  • Description modified (diff)
  • Summary changed from Introduce pre_get_term filter to Introduce filter for wp_get_nav_menu_object()

Replying to boonebgorges:

Looking at how you're using the filter, it seems like a filter on the return value of wp_get_nav_menu_object() would actually work better for your purposes. Does that seem right?

Good call. It seems to work fine if the filter is moved higher in the stack, to wp_get_nav_menu_object(). See 32629.2.diff.

Changes applied to Menu Customizer: 3738806e

#5 @ocean90
4 years ago

  • Owner changed from boonebgorges to ocean90
  • Status changed from reviewing to accepted

#6 @ocean90
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 32764:

Nav menus: Introduce a wp_get_nav_menu_object filter in wp_get_nav_menu_object() to filter the retrieved nav_menu term.

props westonruter.
fixes #32629.

Note: See TracTickets for help on using tickets.