WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 4 months ago

#39776 assigned enhancement

add priority argument to add_submenu_page() function

Reported by: alexvorn2 Owned by: welcher
Milestone: 5.3 Priority: normal
Severity: normal Version: 4.7.2
Component: Menus Keywords: has-patch dev-feedback early
Focuses: administration Cc:

Description

Add option to add new sub-menu pages with specific order - adding priority number, so if we will have a bigger priority the menu will have higher position in sidebar admin menus.

Attachments (3)

39776.diff (13.5 KB) - added by welcher 2 years ago.
Initial Patch
39776.2.diff (13.7 KB) - added by welcher 6 months ago.
Refreshed patch
39776.3.diff (13.7 KB) - added by welcher 4 months ago.
New simplified approach.

Download all attachments as: .zip

Change History (15)

@welcher
2 years ago

Initial Patch

#1 @welcher
2 years ago

  • Keywords has-patch dev-feedback added

Attached is an initial approach based on what is done in add_menu_page. The position numbers are not sequential, but rather multiples of 5. Adding a submenu item with a priority of 5 ( or lower ) will place it at the top of the list, 10 will be the second, 15 the third and so on.

This is due to how the menus are generated and output in includes/menu.php: https://core.trac.wordpress.org/browser/tags/4.7/src/wp-admin/includes/menu.php

The Appearance menu does deviate from this numbering system slightly which may cause some confusion when adding items to it.

I'd love a second opinion on this approach.

#2 @welcher
2 years ago

Related #40927

#3 @alexvorn2
2 years ago

So can we move this to 4.9 Milestone?

#4 @welcher
21 months ago

  • Milestone changed from Awaiting Review to 5.0

I think its too late for 4.9 but lets aim for 5.0

#5 @welcher
21 months ago

The ability to set the position is done with the attached patch.

However, I don't really like how the numbering seems arbitrary. 1 is the top but 5 is the second slot and then 10 is the third unless you are in the Appearance menu in which case 6 is the third.

I think we need a way to abstract that away so it's consistent and numbered in a sane fashion.

#6 @welcher
21 months ago

  • Owner set to welcher
  • Status changed from new to assigned

#7 @peterwilsoncc
9 months ago

  • Milestone changed from 5.0 to 5.1

Switching milestone due to the focus on the new editor (Gutenberg) for WordPress 5.0.

#8 @desrosj
6 months ago

  • Keywords needs-refresh added
  • Milestone changed from 5.1 to 5.2

The most recent patch needs a refresh against trunk. @welcher are you able to refresh?

Punting to 5.2, but if it's ready before Beta on Thursday, this can be reconsidered.

@welcher
6 months ago

Refreshed patch

#9 @welcher
6 months ago

  • Keywords needs-refresh removed

@desrosj I've updated the patch. The numbering system is still a bit arbitrary but we can refine as needed.

Last edited 6 months ago by welcher (previous) (diff)

#10 @desrosj
4 months ago

  • Keywords early added
  • Milestone changed from 5.2 to 5.3

Thanks @welcher! The patch applies cleanly now.

5.2 beta is in just a few days. Since this still needs a proper review and testing, I am going to punt it to 5.3 and add the early tag so it can be well tested.

If a committer is confident in this for 5.2, then feel free to move it back!

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


4 months ago

@welcher
4 months ago

New simplified approach.

#12 @welcher
4 months ago

I've reworked the patch with a new approach that standardizes the insertion point based on the number of items in the array instead of the actual index number.

The only thing I am a little concerned about is that part of this approach uses array_merge which doesn't preserve the array keys. Unit tests still pass but I'd love any other feedback on whether those keys are actually used anywhere that this change will break.

Note: See TracTickets for help on using tickets.