Make WordPress Core

Opened 3 years ago

Closed 8 weeks ago

#22487 closed enhancement (wontfix)

Adding priority to settings sections.

Reported by: alexmansfield Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords: has-patch settings-api 3.6-early
Focuses: administration Cc:


Currently there is no way (at least that I could find) to specify the order of settings sections on a settings page (for example, a theme options page). Use case: a child theme adding a settings section to the parent theme's "Theme Options" page has no way of specifying where on the page the new section should be placed.

I've modified the add_settings_section() function to allow for a priority to be set (much like when adding sections to the theme customizer). I also added uasort($wp_settings_sections[$page], 'compare_priority'); to the do_settings_section() function, where 'compare_priority' is a slightly modified version of the compare function used to set the priority of the theme customizer sections. The patch is based on version 3.4.2, but I'd be happy to make another for the development version if that would help.

This is my first patch submitted, so please let me know if I need to do anything differently. Thanks!

Attachments (1)

section-priority.patch (1.9 KB) - added by alexmansfield 3 years ago.
Adds priority option to settings sections

Download all attachments as: .zip

Change History (25)

3 years ago

Adds priority option to settings sections

#1 @toscho
3 years ago

  • Cc info@… added

#2 @DrewAPicture
3 years ago

  • Cc xoodrew@… added

#4 follow-up: @kovshenin
3 years ago

#20733 is for the Customizer, which already has priorities. This is about the Settings API I guess. It would also be nice if fields could have priorities too.

Also related: #18285 New Settings API & Workflow

#5 in reply to: ↑ 4 @SergeyBiryukov
3 years ago

Replying to kovshenin:

#20733 is for the Customizer, which already has priorities.

It describes a bug which we'd probably want to fix before using a similar approach for Settings API.

#6 @alexmansfield
3 years ago

@kovshenin Correct, this is for the settings API, not the Customizer. I would love to add priority to the individual fields as well, but I figured I'd start with the sections.

@SergeyBiryukov Yes, since I borrowed some of the code from the customizer, it would inherit the same the bug. However, I read the comments for #20733 and it was determined that the bug was relatively minor and was not a roadblock to release, so I don't think it would need to be a roadblock to implementing priorities in the settings API. As soon as the bug is solved for the customizer it could be ported to the settings API as well.

#7 @unknowndomain
3 years ago

  • Keywords settings-3.6 added

#8 @unknowndomain
3 years ago

  • Cc me@… added

#9 @ctsttom
3 years ago

  • Keywords 3.6 needs-refresh added; has-patch removed

@alexmandfield would you be interested in refreshing this code once 3.5.1 is out in the next couple of weeks to get this into 3.6?

#10 @ctsttom
3 years ago

  • Keywords 3.6-early added; 3.6 removed

#11 @SergeyBiryukov
3 years ago

  • Keywords has-patch settings-api added; settings-3.6 removed

#12 @SergeyBiryukov
3 years ago

  • Keywords needs-refresh removed

section-priority.patch still applies cleanly.

#13 follow-up: @alexmansfield
3 years ago

So if I understand the changes added above, I don't need to rebuild the patch. Correct?

#14 in reply to: ↑ 13 @SergeyBiryukov
3 years ago

Replying to alexmansfield:

So if I understand the changes added above, I don't need to rebuild the patch. Correct?

Yes. "@since 3.4.0" can be updated once the ticket is actually slated for a milestone.

#15 @unknowndomain
3 years ago

@alexmandfield I have just tested the patch and found that it doesn't work as expected, if you have two sections with the same or default priority they should be ordered in the order in code, however they seem to get sorted backwards.

Also I think this should be expanded to add priority toadd_settings_fields as this could also be useful to people, especially once the Settings API is implemented in wp-admin.

What do you think?

#16 @alexmansfield
3 years ago

@unknowndomain The code for setting the order comes from the code already used to set the order of Theme Customizer sections. This code has a known bug when priorities are the same (#20733). I figured that once that bug is resolved, I would simply incorporate the solution here as well.

Also, I agree that priorities should be expanded to add_settings_fields as well, I just haven't had the time to submit a patch for that yet. Thanks for the input!

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

#17 @unknowndomain
3 years ago

@alexmansfield I see, that explains a lot, they pointed out as I pondered, looking at the code you did if the way the settings are stored should be changed internally to match the way actions and filters work, i.e. they are stored as a multi-dimensional array $settings[priority][page][section][field].

Seems like a rather big change though considering how much impact it might have.

On a side note, do you think you will have time to add priority to settings field as you know what changes need to be done already?

Last edited 3 years ago by unknowndomain (previous) (diff)

#18 @alexmansfield
3 years ago

I am hoping to submit a patch for settings fields next week, though I can't guarantee that I'll get it done by then. It's definitely on my list of things to do as soon as possible :)

#19 @unknowndomain
3 years ago

Awesome, just means I can focus on the other settings-api stuff.

#20 @alexmansfield
3 years ago

To those of you who mentioned adding priority to settings (rather than just sections), I've posted a patch for prioritizing settings here: #23387

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

#21 @nacin
23 months ago

  • Component changed from General to Plugins

#22 @nacin
22 months ago

  • Component changed from Plugins to Admin APIs
  • Focuses administration added

#23 @nacin
22 months ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

#24 @DrewAPicture
8 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

No further activity or interest in 2 years. Closing as wontfix.

Note: See TracTickets for help on using tickets.