sort_menu

The WordPress Core sort menu function.

Description

(int) sort_menu( (array) $a, (array) $b ); 

Returns (int)

Parameters (2)

0. $a (array)
The a.
1. $b (array)
The b.

Usage

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

Defined (1)

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

/wp-admin/includes/menu.php  
  1. function sort_menu($a, $b) { 
  2. global $menu_order, $default_menu_order; 
  3. $a = $a[2]; 
  4. $b = $b[2]; 
  5. if ( isset($menu_order[$a]) && !isset($menu_order[$b]) ) { 
  6. return -1; 
  7. } elseif ( !isset($menu_order[$a]) && isset($menu_order[$b]) ) { 
  8. return 1; 
  9. } elseif ( isset($menu_order[$a]) && isset($menu_order[$b]) ) { 
  10. if ( $menu_order[$a] == $menu_order[$b] ) 
  11. return 0; 
  12. return ($menu_order[$a] < $menu_order[$b]) ? -1 : 1; 
  13. } else { 
  14. return ($default_menu_order[$a] <= $default_menu_order[$b]) ? -1 : 1;