Opened 2 years ago
Last modified 16 months ago
#52035 new defect (bug)
The `add_submenu_page()` position is ignored.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
Hello,
I'm not sure that the add_submenu_page()
position argument is being applied properly. See the below example:
<?php add_action( 'admin_menu', function() { add_submenu_page( 'edit.php', 'Foo', 'Foo', 'list_users', 'foo', function() { echo 'Hello Foo'; }, 200, ); add_submenu_page( 'edit.php', 'Bar', 'Bar', 'list_users', 'bar', function() { echo 'Hello Bar'; }, 100, ); } );
I would expect "Bar" to appear before "Foo" since it has a lower position number. What ends up happening is whichever add_submenu_page()
was called first, gets position priority.
Change History (6)
This ticket was mentioned in PR #816 on WordPress/wordpress-develop by mukeshpanchal27.
2 years ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/52035
#4
@
16 months ago
Hi @mukesh27 ,
I just stumbled upon this bug and had a look at your patch.
It doesn't solve the problem if there are multiple submenus being registered because apparently array keys get reset and the last menu registered will always end up in the last position.
I suggest start by writing some tests so we can cover many different situations. I'm happy to help testing and giving feedback to move this ticket forward.
And in the meantime I'm going to look for a workaround to my problem :)
Thanks for the report!
Moving to the Administration component, as Menus is specifically for the Menus screen and nav menu functions.