[wp-trac] [WordPress Trac] #15550: WP_Nav_Menu_Widget needs a filter for args

WordPress Trac wp-trac at lists.automattic.com
Tue Nov 23 21:48:58 UTC 2010


#15550: WP_Nav_Menu_Widget needs a filter for args
-------------------------+--------------------------------------------------
 Reporter:  brodock      |       Owner:                             
     Type:  enhancement  |      Status:  new                        
 Priority:  normal       |   Milestone:  Awaiting Review            
Component:  Widgets      |     Version:  3.1                        
 Severity:  normal       |    Keywords:  widget nav_menu filter hook
-------------------------+--------------------------------------------------
 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'];
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15550>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list