Make WordPress Core

Opened 2 years ago

Last modified 19 months ago

#23836 new defect (bug)

add_submenu_page() duplicate menus

Reported by: king_of_the_ring Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Administration Keywords:
Focuses: Cc:


Creating two sub-menus with the same "menu slug" using add_submenu_page() should create only the last sub-menu.
But it creates two sub-menus with the same "menu slug".

Based on documentation "menu slug" should be unique for each sub-menu.

Change History (3)

comment:1 @SergeyBiryukov2 years ago

  • Component changed from Menus to Administration

comment:2 @nacin2 years ago

While it should be unique, I don't think the behavior you're seeing is necessarily a bug. The function is "add", not "update". If you want to replace a menu, remove it then add it.

comment:3 @mordauk19 months ago

  • Severity changed from major to minor

While it really doesn't seem to cause any issues having duplicate pages, it does seem a bit odd to me that duplicate sub menu items are allowed.

function test_add_duplicate_menu_page() {
	add_submenu_page( 'plugins.php', 'Test', 'Test', 'manage_options', 'my-test-page', '__return_null' );
	add_submenu_page( 'plugins.php', 'Test', 'Test', 'manage_options', 'my-test-page', '__return_null' );
add_action( 'admin_menu', 'test_add_duplicate_menu_page' );

That, for example, will register two "Test" submenu items that both point to the same page.

Is it an issue? I don't really think so but it is a bit odd. What if we prevented the second one from being added (or replaced the first) if all arguments are the same?

Note: See TracTickets for help on using tickets.