WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13371 closed defect (bug) (fixed)

Nav menu items should be filterable, regardless of context

Reported by: nathanrice Owned by: nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: menus, nav menus, has-patch
Focuses: Cc:
PR Number:

Description

It's kind of weird that in order for a plugin/theme to filter the nav menu items, the $args->context needs to be 'frontend'.

For example, since the $args object is passed through the wp_nav_menu_items filter, the user-defined filter can do the contextual checks. For instance ...

add_filter('wp_nav_menu_items', 'my_nav_menu_items_filter', 10, 2);
function my_nav_menu_items_filter($items, $args) {
    if( $args->context != 'frontend' )
        return $items;

    // proceed with the filter
}

Plus, I can see plenty of reasons why a plugin/theme might want to filter the items regardless of context.

Either way, it should be up to the plugin/theme author, shouldn't it?

I've attached a patch.

Attachments (1)

nav-menu-template.php.diff (800 bytes) - added by nathanrice 10 years ago.

Download all attachments as: .zip

Change History (5)

#1 follow-up: @nacin
10 years ago

  • Owner set to nacin
  • Status changed from new to accepted

This is a bit of a rabbit hole. OTOH, since we're already giving them access via the wp_nav_menu filter, I'd rather not tie plugin authors' hands and force them to regex through HTML to do that they need.

#2 in reply to: ↑ 1 @nathanrice
10 years ago

Replying to nacin:

This is a bit of a rabbit hole. OTOH, since we're already giving them access via the wp_nav_menu filter, I'd rather not tie plugin authors' hands and force them to regex through HTML to do that they need.

My thoughts exactly. Seems like the only way to do it, if the context isn't 'frontend'.

#3 follow-up: @nacin
10 years ago

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

This didn't make it through to Trac: [14592]

#4 in reply to: ↑ 3 @nathanrice
10 years ago

Replying to nacin:

This didn't make it through to Trac: [14592]

Cool, thanks!

Note: See TracTickets for help on using tickets.