WordPress.org

Make WordPress Core

Ticket #36163: add_filter_nav_submenu_start_lvl.patch

File add_filter_nav_submenu_start_lvl.patch, 2.6 KB (added by darthaud, 4 years ago)

Add css filter and id filter to walker nav menu Class

  • wp-includes/class-walker-nav-menu.php

    From 99a49cb7d812580fb7dd07cd686fbc9c7eb418e7 Mon Sep 17 00:00:00 2001
    From: Daniel Arthaud <arthaud@gmail.com>
    Date: Sun, 19 Mar 2017 22:39:45 -0300
    Subject: [PATCH 1/2] Added css class filters to walker nav menu
    
    ---
     wp-includes/class-walker-nav-menu.php | 18 +++++++++++++++++-
     1 file changed, 17 insertions(+), 1 deletion(-)
    
    diff --git a/wp-includes/class-walker-nav-menu.php b/wp-includes/class-walker-nav-menu.php
    index 4c1a1f2..c9ec4dc 100644
    a b class Walker_Nav_Menu extends Walker { 
    5858                        $n = "\n";
    5959                }
    6060                $indent = str_repeat( $t, $depth );
    61                 $output .= "{$n}{$indent}<ul class=\"sub-menu\">{$n}";
     61
     62                /**
     63                 * Filters the CSS class(es) applied to a menu list element.
     64                 *
     65                 * @since 4.8.0
     66                 *
     67                 * @param array    $classes The CSS classes that are applied to the menu `<ul>` element.
     68                 * @param stdClass $args    An object of wp_nav_menu() arguments.
     69                 * @param int      $depth   Depth of menu item. Used for padding.
     70                 */
     71
     72                $classes = array( 'sub-menu' );
     73                $classes = apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth );
     74                $class_names = join( ' ', $classes );
     75                $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
     76
     77                $output .= "{$n}{$indent}<ul {$class_names}>{$n}";
    6278        }
    6379
    6480        /**
  • wp-includes/class-walker-nav-menu.php

    -- 
    2.7.4
    
    
    From c680ea3914bb54ce10be27d6132e4fb6e77d2cfa Mon Sep 17 00:00:00 2001
    From: Daniel Arthaud <arthaud@gmail.com>
    Date: Sun, 19 Mar 2017 22:42:03 -0300
    Subject: [PATCH 2/2] Added Id filter to walk nav menu
    
    ---
     wp-includes/class-walker-nav-menu.php | 14 +++++++++++++-
     1 file changed, 13 insertions(+), 1 deletion(-)
    
    diff --git a/wp-includes/class-walker-nav-menu.php b/wp-includes/class-walker-nav-menu.php
    index c9ec4dc..510851a 100644
    a b class Walker_Nav_Menu extends Walker { 
    7474                $class_names = join( ' ', $classes );
    7575                $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
    7676
    77                 $output .= "{$n}{$indent}<ul {$class_names}>{$n}";
     77                /**
     78                 * Filters the ID applied to a menu list element.
     79                 *
     80                 * @since 4.8.0
     81                 *
     82                 * @param string   $menu_id The ID that is applied to the menu `<ul>` element.
     83                 * @param stdClass $args    An object of wp_nav_menu() arguments.
     84                 * @param int      $depth   Depth of menu item. Used for padding.
     85                 */
     86                $id = apply_filters( 'nav_menu_submenu_id', '', $args, $depth );
     87                $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
     88
     89                $output .= "{$n}{$indent}<ul {$id} {$class_names}>{$n}";
    7890        }
    7991
    8092        /**