Opened 12 years ago
Closed 9 years 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: |
Description
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)
Change History (25)
#6
@
12 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.
#9
@
12 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?
#13
follow-up:
↓ 14
@
12 years ago
So if I understand the changes added above, I don't need to rebuild the patch. Correct?
#14
in reply to:
↑ 13
@
12 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
@
12 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
@
12 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!
#17
@
12 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?
#18
@
12 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 :)
Adds priority option to settings sections