Opened 16 years ago
Closed 15 years ago
#9876 closed enhancement (wontfix)
sort items in the admin menu
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 2.8 |
Component: | Menus | Keywords: | has-patch tested commit early |
Focuses: | Cc: |
Description
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.
Attachments (3)
Change History (15)
#2
@
16 years ago
Plugins that add their own top-levels currently can control the order in which the submenus appear beneath that top-level. This seems like it would override that case.
#3
@
16 years ago
I happen to maintain a few such plugins. :-)
Contrary to WP menu items, add_menu_page and add_sub_menu page all have a page title argument. As a result, $_data[3] is always set. The only case where it would not be set if the globals are modified directly.
#4
@
16 years ago
I tested with Nextgen Gallery and its submenu items are reordered. An About page that was at the end of the list is now at the top of the list. Since its at the top of the list, it becomes the default page for that top-level rather than the intended Overview page.
#6
@
16 years ago
- Component changed from UI to Menus
- Milestone changed from 2.8 to 2.9
- Owner set to ryan
Postponing to 2.9, where we will be doing some other menu enhancements.
#8
@
16 years ago
- Keywords has-patch tested commit early added; needs-patch removed
new patch makes sure only WP menu items are done.
#10
@
16 years ago
new patch fixes a bug on index.php when akismet is enabled. It's now checking for !empty() instead of isset().
Attached patch will do the following:
The key benefit is when you've a zillion plugins that add stuff to settings. As things are, they end up in a mostly random order. With the patch, it's nice and neat.