From 4c10cb2ec50799dc478681ef9f77b5938bc05fc4 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Mon, 3 Mar 2014 20:42:21 +0000 Subject: [PATCH] Add the ability to short-circuit wp_nav_menu() via the `pre_wp_nav_menu` hook. props kasparsd, DrewAPicture, Rarst. fixes #23627. git-svn-id: https://develop.svn.wordpress.org/trunk@27386 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/nav-menu-template.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php index e69e1f5b3d..b1b8db1ed5 100644 --- a/src/wp-includes/nav-menu-template.php +++ b/src/wp-includes/nav-menu-template.php @@ -245,6 +245,31 @@ function wp_nav_menu( $args = array() ) { $args = apply_filters( 'wp_nav_menu_args', $args ); $args = (object) $args; + /** + * Filter whether to short-circuit the wp_nav_menu() output. + * + * Returning a non-null value to the filter will short-circuit + * wp_nav_menu(), echoing that value if $args->echo is true, + * returning that value otherwise. + * + * @since 3.9.0 + * + * @see wp_nav_menu() + * + * @param string|null $output Nav menu output to short-circuit with. Default null. + * @param object $args An object containing wp_nav_menu() arguments. + */ + $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args ); + + if ( null !== $nav_menu ) { + if ( $args->echo ) { + echo $nav_menu; + return; + } + + return $nav_menu; + } + // Get the nav menu based on the requested menu $menu = wp_get_nav_menu_object( $args->menu );