[wp-trac] [WordPress Trac] #9876: sort items in the admin menu

WordPress Trac wp-trac at lists.automattic.com
Tue May 19 13:20:35 GMT 2009


#9876: sort items in the admin menu
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:     
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  2.8
Component:  UI                 |     Version:  2.8
 Severity:  minor              |    Keywords:     
-------------------------------+--------------------------------------------
 it's desirable to keep the wp items to the top of the list. but the items
 added by plugins could arguably be sorted automatically using
 strnatcasecmp applied to the menu item's title.

 this is what I used until 2.7.1:

 {{{
 function sort_admin_menu()
 {
         global $submenu;

         #dump($submenu);

         foreach ( $submenu as $key => $menu_items )
         {
                 switch ( $key )
                 {
                 case 'edit.php':
                 case 'upload.php';
                 case 'link-manager.php';
                 case 'edit-pages.php';
                         $stop = 2;
                         break;

                 case 'themes.php':
                         $stop = 2;
                         unset($menu_items[10]); # theme and plugin editors
                         unset($menu_items[15]); # add new theme
                         break;

                 case 'plugins.php':
                         $stop = 2;
                         unset($menu_items[15]); # theme and plugin editors
                         break;

                 case 'index.php':
                 case 'edit-comments.php':
                 case 'users.php':
                 case 'profile.php':
                 case 'tools.php':
                 case 'options-general.php':
                         $stop = 1;
                         break;

                 default:
                         # don't reorder menus added by plugins
                         $stop = sizeof($submenu[$key]);
                         break;
                 }

                 $unsortable = array();
                 $sortable = $menu_items;
                 reset($sortable);

                 while ( $stop != 0 )
                 {
                         $mkey = key($sortable);
                         $unsortable[$mkey] = current($sortable);
                         unset($sortable[$mkey]);

                         $stop--;
                 }

                 uasort($sortable, array('sem_fixes_admin',
 'menu_nat_sort'));

                 $submenu[$key] = array_merge($unsortable, $sortable);

                 if ( count($submenu[$key]) == 1 )
                 {
                         unset($submenu[$key]);
                 }
         }
 } # sort_admin_menu()


 #
 # menu_nat_sort()
 #

 function menu_nat_sort($a, $b)
 {
         return strnatcmp($a[0], $b[0]);
 } # menu_nat_sort()
 }}}

 if there is any interest, I'll change the above as needed cook up a patch.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9876>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list