[wp-trac] [WordPress Trac] #23627: Allow plugins to short-circuit wp_nav_menu, good for performance

WordPress Trac noreply at wordpress.org
Tue Feb 26 12:49:29 UTC 2013


#23627: Allow plugins to short-circuit wp_nav_menu, good for performance
-----------------------------+-------------------------
 Reporter:  kasparsd         |       Type:  enhancement
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Menus
  Version:  3.5.1            |   Severity:  normal
 Keywords:                   |
-----------------------------+-------------------------
 We already have short-circuit filters for
 [http://core.trac.wordpress.org/browser/tags/3.5.1/wp-
 includes/widgets.php#L180 widgets],
 [http://core.trac.wordpress.org/browser/tags/3.5.1/wp-
 includes/option.php#L40 options],
 [http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/link-
 template.php#L115 links] that all can be used for retrieving items from
 non-persistent data store. It would make a lot of sense if this feature
 was also available to `wp_nav_menu` which is particularly DB heavy.

 My suggestion is to add `pre_wp_nav_menu` right after `wp_nav_menu_args`,
 like so:

 {{{
         $args = wp_parse_args( $args, $defaults );
         $args = apply_filters( 'wp_nav_menu_args', $args );
         $args = (object) $args;

         // Allow plugins to short-circuit menu output
         $nav_menu = apply_filters( 'pre_wp_nav_menu', '', $args );

         if ( ! empty( $nav_menu ) && $args->echo )
                 echo $nav_menu;
         elseif ( ! empty( $nav_menu ) )
                 return $nav_menu;

         // Get the nav menu based on the requested menu
         $menu = wp_get_nav_menu_object( $args->menu );
 }}}

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


More information about the wp-trac mailing list