do_settings_sections()
Outputs to the screen all option blocks related to the specified settings page in the admin panel.
Use this in a settings page callback function to output all the sections and fields that were added to that $page with add_settings_section() and add_settings_field().
Note: the function will output section headers in an H3 tag and form fields in a table.
The function works in conjunction with other functions of the Settings API.
No Hooks.
Returns
null. Outputs to the screen the HTML code of the blocks with form fields.
Usage
do_settings_sections( $page );
- $page(string) (required)
- Identifier of the admin panel page on which to output the option blocks. Must match the $page parameter from add_settings_section( $id, $title, $callback, $page ).
Examples
#1 Displaying settings sections on the settings page
Suppose we registered new options, added a block and fields to this block. Now, we need to display these fields on the settings page of the plugin in the admin panel, then use this function:
<div class="wrap"> <?php screen_icon(); ?> <h2>Primer plugin settings</h2> <form action="options.php" method="POST"> <?php settings_fields( 'option_id' ); ?> <?php do_settings_sections( 'primer_page' ); ?> <?php submit_button(); ?> </form> </div>
See the Settings API for a full example of how to use it.
Notes
- Global. Array.
$wp_settings_sectionsStorage array of all settings sections added to admin pages. - Global. Array.
$wp_settings_fieldsStorage array of settings fields and info about their pages/sections.
Changelog
| Since 2.7.0 | Introduced. |