do_settings_sections() WordPress Function

The do_settings_sections() function is used to display all settings sections added to a particular settings page. This function should be called inside the form tag on the settings page. Each settings section will be displayed in a separate box.

do_settings_sections( string $page ) #

Prints out all settings sections added to a particular settings page


Description

Part of the Settings API. 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()


Top ↑

Parameters

$page

(string)(Required)The slug name of the page whose settings sections you want to output.


Top ↑

More Information

This will output the section titles wrapped in h3 tags and the settings fields wrapped in tables.


Top ↑

Source

File: wp-admin/includes/template.php

function do_settings_sections( $page ) {
	global $wp_settings_sections, $wp_settings_fields;

	if ( ! isset( $wp_settings_sections[ $page ] ) ) {
		return;
	}

	foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
		if ( $section['title'] ) {
			echo "<h2>{$section['title']}</h2>\n";
		}

		if ( $section['callback'] ) {
			call_user_func( $section['callback'], $section );
		}

		if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
			continue;
		}
		echo '<table class="form-table" role="presentation">';
		do_settings_fields( $page, $section['id'] );
		echo '</table>';
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.