WordPress.org

Make WordPress Core

Ticket #23627: pre_wp_nav_menu-3.23627.diff

File pre_wp_nav_menu-3.23627.diff, 857 bytes (added by kasparsd, 5 years ago)

Added documentation and used strict comparison for the short-circuit.

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

    diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php
    index b7683c3..361f9bb 100644
    function wp_nav_menu( $args = array() ) { 
    231231        $args = apply_filters( 'wp_nav_menu_args', $args );
    232232        $args = (object) $args;
    233233
     234        /**
     235         * Allow plugins to short-circuit menu output.
     236         *
     237         * @since 3.9.0
     238         *
     239         * @param string null Menu output if being overwritten by this filter.
     240         * @param array $args Arguments from {@see wp_nav_menu()}.
     241         */
     242        $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
     243
     244        if ( $nav_menu !== null && $args->echo ) {
     245                echo $nav_menu;
     246                return;
     247        } elseif ( $nav_menu !== null ) {
     248                return $nav_menu;
     249        }
     250
    234251        // Get the nav menu based on the requested menu
    235252        $menu = wp_get_nav_menu_object( $args->menu );
    236253