WordPress.org

Make WordPress Core

Opened 23 months ago

Last modified 13 months ago

#24104 new defect (bug)

Remove duplicated separators in admin menu

Reported by: rilwis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.7
Component: Plugins Keywords: has-patch
Focuses: administration Cc:

Description

I'm working on WordPress admin menu, and I found that the code to remove duplicated separators in admin menu in wp-admin/includes/menu.php doesn't work correctly.

Assuming we have these items in the $menu:

$menu = array(
	100 => array(
		0 => 'Admin Style',
		2 => 'wp-admin-style.php',
		1 => 'read',
		4 => 'menu-top menu-icon-generic toplevel_page_wp-admin-style menu-top-first menu-top-last',
		6 => 'none',
	),
	110 => array(
		0 => '',
		1 => 'read',
		2 => 'separator1',
		3 => '',
		4 => 'wp-menu-separator',
	),
	130 => array(
		0 => '',
		1 => 'read',
		2 => 'separator2',
		3 => '',
		4 => 'wp-menu-separator',
	),
	140 => array(
		0 => '',
		1 => 'read',
		2 => 'separator-last',
		3 => '',
		4 => 'wp-menu-separator',
	),
	150 => array(
		0 => 'Hide Menu',
		1 => 'manage_options',
		2 => 'hide-admin-menu',
		3 => 'Hide Admin Menu',
		4 => 'menu-top toplevel_page_hide-admin-menu',
		5 => 'toplevel_page_hide-admin-menu',
		6 => 'http://localhost:8080/wp/wp-content/plugins/hide-admin-menu/img/icon.png',
	),
);

WordPress will remove only the 1st duplicated separator (130) and still keeps the 2nd one (140).

Another problem with current code is if separator menu item has classes like 'wp-menu-separator woocommerce' (WooCommerce does this), it won't be recognized as a separator, because the function to check separator uses strcmp.

Attachments (1)

menu.php.patch (615 bytes) - added by rilwis 23 months ago.

Download all attachments as: .zip

Change History (4)

@rilwis23 months ago

comment:1 @SergeyBiryukov23 months ago

  • Component changed from Menus to Administration
  • Version changed from trunk to 2.7

Related: [9989], #23182

comment:2 @jeremyfelt13 months ago

  • Component changed from Administration to Menus
  • Focuses administration added

comment:3 @SergeyBiryukov13 months ago

  • Component changed from Menus to Plugins

Admin menu API now belongs to Plugins, according to the new component structure.

Note: See TracTickets for help on using tickets.