Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#9876 closed enhancement (wontfix)

sort items in the admin menu

Reported by: Denis-de-Bernardy Owned by: ryan
Milestone: Priority: normal
Severity: minor Version: 2.8
Component: Menus Keywords: has-patch tested commit early
Focuses: Cc:


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;
	foreach ( $submenu as $key => $menu_items )
		switch ( $key )
		case 'edit.php':
		case 'upload.php';
		case 'link-manager.php';
		case 'edit-pages.php';
			$stop = 2;

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

		case 'plugins.php':
			$stop = 2;
			unset($menu_items[15]); # theme and plugin editors
		case 'index.php':
		case 'edit-comments.php':
		case 'users.php':
		case 'profile.php':
		case 'tools.php':
		case 'options-general.php':
			$stop = 1;
			# don't reorder menus added by plugins
			$stop = sizeof($submenu[$key]);
		$unsortable = array();
		$sortable = $menu_items;

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


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

		$submenu[$key] = array_merge($unsortable, $sortable);
		if ( count($submenu[$key]) == 1 )
} # 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)

9876.diff (807 bytes) - added by Denis-de-Bernardy 11 years ago.
9876.2.diff (1.0 KB) - added by Denis-de-Bernardy 11 years ago.
9876.3.diff (1.0 KB) - added by Denis-de-Bernardy 11 years ago.
fix a bug in the previous patch

Download all attachments as: .zip

Change History (15)

#1 @Denis-de-Bernardy
11 years ago

  • Keywords has-patch tested commit added

Attached patch will do the following:

  • Leave WP submenu items as they currently are
  • Append all submenu items added by plugins, natcase-sorted by menu name

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.

#2 @ryan
11 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 @Denis-de-Bernardy
11 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 @ryan
11 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.

#5 @ryan
11 years ago

  • Type changed from defect (bug) to enhancement

#6 @ryan
11 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.

#7 @Denis-de-Bernardy
11 years ago

  • Keywords needs-patch added; has-patch tested commit removed

#8 @Denis-de-Bernardy
11 years ago

  • Keywords has-patch tested commit early added; needs-patch removed

new patch makes sure only WP menu items are done.

#9 @Denis-de-Bernardy
11 years ago

still applies clean, in case there's any interest.

11 years ago

fix a bug in the previous patch

#10 @Denis-de-Bernardy
11 years ago

new patch fixes a bug on index.php when akismet is enabled. It's now checking for !empty() instead of isset().

#11 follow-up: @westi
11 years ago

  • Milestone changed from 2.9 to Future Release

I'm not sure that this is necessary.

Moving to Future for now.

#12 in reply to: ↑ 11 @Denis-de-Bernardy
11 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Replying to westi:

I'm not sure that this is necessary.

you obviously aren't the only one...

Note: See TracTickets for help on using tickets.