add_menu_classes

The WordPress Core add menu classes function.

Description

(array) add_menu_classes( (array) $menu ); 

Returns (array)

Parameters (1)

0. $menu (array)
The menu.

Usage

  1. if ( !function_exists( 'add_menu_classes' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/menu.php'; 
  3.  
  4. // The menu. 
  5. $menu = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = add_menu_classes($menu); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/menu.php  
  1. function add_menu_classes($menu) { 
  2. $first = $lastorder = false; 
  3. $i = 0; 
  4. $mc = count($menu); 
  5. foreach ( $menu as $order => $top ) { 
  6. $i++; 
  7.  
  8. if ( 0 == $order ) { // dashboard is always shown/single 
  9. $menu[0][4] = add_cssclass('menu-top-first', $top[4]); 
  10. $lastorder = 0; 
  11. continue; 
  12.  
  13. if ( 0 === strpos($top[2], 'separator') && false !== $lastorder ) { // if separator 
  14. $first = true; 
  15. $c = $menu[$lastorder][4]; 
  16. $menu[$lastorder][4] = add_cssclass('menu-top-last', $c); 
  17. continue; 
  18.  
  19. if ( $first ) { 
  20. $c = $menu[$order][4]; 
  21. $menu[$order][4] = add_cssclass('menu-top-first', $c); 
  22. $first = false; 
  23.  
  24. if ( $mc == $i ) { // last item 
  25. $c = $menu[$order][4]; 
  26. $menu[$order][4] = add_cssclass('menu-top-last', $c); 
  27.  
  28. $lastorder = $order; 
  29.  
  30. /** 
  31. * Filters administration menus array with classes added for top-level items. 
  32. * @since 2.7.0 
  33. * @param array $menu Associative array of administration menu items. 
  34. */ 
  35. return apply_filters( 'add_menu_classes', $menu );