WordPress.org

Make WordPress Core

Ticket #23627: add-pre_wp_nav_menu-filter.23627.diff

File add-pre_wp_nav_menu-filter.23627.diff, 663 bytes (added by kasparsd, 5 years ago)

Patch

  • wp-includes/nav-menu-template.php

    diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php
    index bd04542..2fd0967 100644
    function wp_nav_menu( $args = array() ) { 
    144144        $args = apply_filters( 'wp_nav_menu_args', $args );
    145145        $args = (object) $args;
    146146
     147        // Allow plugins to short-circuit menu output
     148        $nav_menu = apply_filters( 'pre_wp_nav_menu', '', $args );
     149
     150        if ( ! empty( $nav_menu ) && $args->echo )
     151                echo $nav_menu;
     152        elseif ( ! empty( $nav_menu ) )
     153                return $nav_menu;
     154
    147155        // Get the nav menu based on the requested menu
    148156        $menu = wp_get_nav_menu_object( $args->menu );
    149157