Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#33944 closed enhancement (fixed)

Add parameters to widget_nav_menu_args filter

Reported by: walterbarcelos's profile walterbarcelos Owned by: drewapicture's profile DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description

I want add parameters to widget_nav_menu_args filter so you can easier override the navigation options by widget basis.

Attachments (3)

33944.patch (1.1 KB) - added by walterbarcelos 10 years ago.
33944.2.patch (1.5 KB) - added by DrewAPicture 10 years ago.
With $this
33944.3.patch (1.0 KB) - added by DrewAPicture 10 years ago.

Download all attachments as: .zip

Change History (16)

#1 @swissspidy
10 years ago

  • Keywords has-patch added
  • Version 4.2 deleted

#2 @wonderboymusic
10 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to DrewAPicture
  • Status changed from new to assigned

#3 @DrewAPicture
10 years ago

  • Status changed from assigned to accepted

#4 @DrewAPicture
10 years ago

I think I'd much prefer to pass the entire WP_Nav_Menu_Widget instance instead of just the id_base value. That said, I'm not super excited about passing 5 parameters to this filter.

@DrewAPicture
10 years ago

With $this

#5 @DrewAPicture
10 years ago

See 33944.2.patch with $this added.

#6 @DrewAPicture
10 years ago

After considering 33944.2.patch a little bit, let's omit the fifth parameter. I don't see the merit in passing either the $this instance or the id_base for that matter. id_base is always going to be nav_menu for widgets of this type.

We can always add $this later if there's a demonstrated need.

Side note: I'm also having a bit of "buyer's remorse" on adding $nav_menu as a parameter in the first place when this hook was introduced, mostly because it's already passed as part of the $nav_menu_args array.

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


10 years ago

#8 @DrewAPicture
10 years ago

After talking to @johnbillion in Slack (linked above) about it a little bit, we decided the value in filtering by the widget title (which is afforded by passing $instance) is low, since the menu ID is already available via both the $nav_menu_args and $nav_menu parameters.

Therefore, passing $this provides the most value in directly targeting widget instances.

#9 @DrewAPicture
10 years ago

  • Keywords reporter-feedback added

@walterbarcelos: Can you provide a use-case for why you would want $instance passed to this hook?

#10 @DrewAPicture
10 years ago

  • Milestone changed from 4.4 to Awaiting Review

Waiting on reporter feedback from @walterbarcelos.

#11 @walterbarcelos
10 years ago

  • Keywords reporter-feedback removed

Hi @DrewAPicture.

Sorry for the delay and thank you very much for reviewing this patch.

After reading your comments I think you're totally right. I only need the $instance object to do what I'd like to do.

The idea is to add an action to in_widget_form, detect if it's a custom menu widget and if so, display a dropdown so the user can select any of the walkers I have implemented. Pretty much like the page template selection on the page's form.

I need $instance because when I filter widget_nav_menu_args I need to get the value selected on the dropdown, which is accessible through the widget settings, in order to create the walker object and assign it to $nav_menu_args['walker'].

Please let me know if you need more info.

Thanks,
Walter.

#12 @DrewAPicture
10 years ago

  • Milestone changed from Awaiting Review to 4.4

#13 @DrewAPicture
10 years ago

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

In 34662:

Widgets: Pass $instance to the widget_nav_menu_args filter in the Custom Menu widget.

Props walterbarcelos for the initial patch.
Fixes #33944.

Note: See TracTickets for help on using tickets.