WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#39849 closed defect (bug) (fixed)

Filter `nav_menu_items_{$post_type_name}_recent` passes base args, not recent

Reported by: eclev91 Owned by: welcher
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.7.2
Component: Menus Keywords: has-patch
Focuses: administration Cc:

Description

On line 434 of nav-menu.php, the nav_menu_items_{$post_type_name}_recent filter is passing the base $args rather than the adjusted $recent_args set on line 418. Could be expected, but seemed odd to me and I ended up reapplying those arguments in my filter function.

If someone can confirm this is a bug and not as expected, I'd be happy to attach a patch.

Attachments (2)

39849.diff (944 bytes) - added by welcher 3 years ago.
39849.2.diff (1.0 KB) - added by welcher 3 years ago.
Adding recent_args as a fourth param

Download all attachments as: .zip

Change History (9)

#1 @welcher
3 years ago

  • Focuses administration added
  • Keywords needs-patch added

@eclev91 thanks for reporting!

This does seem unexpected to me as well. It seems to me that the filter should have all of the args available to it.

This ticket was mentioned in Slack in #core by welcher. View the logs.


3 years ago

@welcher
3 years ago

#3 follow-up: @welcher
3 years ago

@eclev91 I've added an initial patch and @johnbillion reviewed it with me.

The concern with my approach is that $args['walker'] is overridden after the array merge and doesn't exist in the $recent_args array. We both agreed that it may be better to add a fourth argument to the filter that holds $recent_args instead.

Last edited 3 years ago by welcher (previous) (diff)

#4 in reply to: ↑ 3 @eclev91
3 years ago

While it's been a while since I ran into this, I think the proposed solution makes sense. As long as those arguments are available and how to get them is documented.

@welcher
3 years ago

Adding recent_args as a fourth param

#5 @welcher
3 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.9
  • Owner set to welcher
  • Status changed from new to assigned

This ticket was mentioned in Slack in #core by welcher. View the logs.


3 years ago

#7 @SergeyBiryukov
3 years ago

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

In 41941:

Menus: Pass $recent_args parameter to nav_menu_items_{$post_type_name}_recent filter.

Props welcher, eclev91.
Fixes #39849.

Note: See TracTickets for help on using tickets.