Opened 15 years ago
Closed 3 years ago
#15550 closed enhancement (duplicate)
WP_Nav_Menu_Widget needs a filter for args
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.1 |
| Component: | Widgets | Keywords: | dev-feedback |
| Focuses: | Cc: |
Description
I have a very common need to change the walker of a menu printed by WP_Nav_Menu_Widget. The only way to do this is by injecting a new walker on the args array.
By so, I propose changing default-widgets.php:
function widget($args, $instance) {
// Get menu
$nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
if ( !$nav_menu )
return;
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
echo $args['before_widget'];
if ( !empty($instance['title']) )
echo $args['before_title'] . $instance['title'] . $args['after_title'];
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
echo $args['after_widget'];
}
To:
function widget($args, $instance) {
// Filter for args
$args = apply_filters('nav_manu_widget_args', $args);
// Get menu
$nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
if ( !$nav_menu )
return;
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
echo $args['before_widget'];
if ( !empty($instance['title']) )
echo $args['before_title'] . $instance['title'] . $args['after_title'];
wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
echo $args['after_widget'];
}
Change History (6)
#1
@
15 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
11 years ago
- Keywords widget nav_menu filter hook needs-patch removed
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from new to closed
Closing as wontfix as there hasn't been any activity here in four years and I don't think I've ever seen a similar hook suggested elsewhere.
#4
@
10 years ago
- Resolution wontfix deleted
- Status changed from closed to reopened
I'd like to have this ticket reconsidered, since I also needed the same thing as the OP.
If two people mentioned wanting something chances are that there are more.
Plus having a filter around is better that not, since some people, like myself, would have create a widget that's very similar to the existing one just to be able to modify the $args parameter.
How about we change
$instance = apply_filters('widget_display_callback', $instance, $this, $args); ... do_action( 'the_widget', $widget, $instance, $args );to use
apply_filters_ref_array()anddo_action_ref_array(). Or maybe better: add a new ref_array action near those points.