Make WordPress Core

Opened 4 years ago

Last modified 3 weeks ago

#52035 new defect (bug)

The `add_submenu_page()` position is ignored.

Reported by: howdy_mcgee's profile Howdy_McGee Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: needs-patch
Focuses: administration Cc:



I'm not sure that the add_submenu_page() position argument is being applied properly. See the below example:

add_action( 'admin_menu', function() {
                function() {
                        echo 'Hello Foo';
                function() {
                        echo 'Hello Bar';
} );

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.

Attachments (1)

52035.diff (988 bytes) - added by im_niloy 6 weeks ago.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
4 years ago

  • Component changed from Menus to Administration

Thanks for the report!

Moving to the Administration component, as Menus is specifically for the Menus screen and nav menu functions.

This ticket was mentioned in PR #816 on WordPress/wordpress-develop by mukeshpanchal27.

4 years ago

  • Keywords has-patch added

#3 @mukesh27
4 years ago

Hi there!

Above attached PR #816 fixes the menu position issue.

#4 @leogermani
2 years 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 :)

#5 @leogermani
2 years ago

Also, it just occurred to me that there would be a problem if 2 submenus are registered using the same position.

#6 @leogermani
2 years ago

Introduced in #39776

#7 @oglekler
4 months ago

  • Keywords needs-patch added; has-patch removed

6 weeks ago

This ticket was mentioned in Slack in #core by im_niloy. View the logs.

3 weeks ago

Note: See TracTickets for help on using tickets.