From 675a350ff9efd3f86056c4a151c6f84f85745e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helen=20Hou-Sand=C3=AD?= Date: Mon, 3 Mar 2014 20:43:15 +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. Built from https://develop.svn.wordpress.org/trunk@27386 git-svn-id: http://core.svn.wordpress.org/trunk@27234 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu-template.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index e69e1f5b3d..b1b8db1ed5 100644 --- a/wp-includes/nav-menu-template.php +++ b/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 );