do_settings_fields() WordPress Function

The do_settings_fields() function is used to display fields for a particular settings page. This function should be called by the add_settings_section() function. The do_settings_fields() function accepts two parameters: the $page parameter is used to specify the settings page where the fields will be displayed, and the $section parameter is used to specify the settings section where the fields will be displayed.

do_settings_fields( string $page, string $section ) #

Prints out the settings fields for a particular settings section.


Description

Part of the Settings API. Use this in a settings page to output a specific section. Should normally be called by do_settings_sections() rather than directly.


Top ↑

Parameters

$page

(string)(Required)Slug title of the admin page whose settings fields you want to show.

$section

(string)(Required)Slug title of the settings section whose fields you want to show.


Top ↑

Source

File: wp-admin/includes/template.php

function do_settings_fields( $page, $section ) {
	global $wp_settings_fields;

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

	foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
		$class = '';

		if ( ! empty( $field['args']['class'] ) ) {
			$class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
		}

		echo "<tr{$class}>";

		if ( ! empty( $field['args']['label_for'] ) ) {
			echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
		} else {
			echo '<th scope="row">' . $field['title'] . '</th>';
		}

		echo '<td>';
		call_user_func( $field['callback'], $field['args'] );
		echo '</td>';
		echo '</tr>';
	}
}


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.