WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 8 weeks 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:

Description

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 SergeyBiryukov13 months ago

  • Component changed from Menus to Administration

comment:2 nacin13 months 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 mordauk8 weeks 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.