settings_fields()
Outputs hidden form fields on the settings page (option_page, _wpnonce, ...).
The function is used in conjunction with functions from the Settings API. Its tasks include outputting all necessary fields for correct operation and protection of the form.
Note: the function must be called inside the <form> tag for the options page.
Uses: wp_nonce_field()
No Hooks.
Returns
null. Returns nothing. Outputs hidden input fields to the screen.
Usage
settings_fields( $option_group );
- $option_group(string) (required)
- The name of the settings group. Must match the first $option_group parameter from register_setting( $option_group, ... ).
Examples
#1 settings_fields() displays hidden form fields, so it must be inside the form tag:
<form method="POST" action="options.php"> <?php // page slug on which the form is displayed, // same as the group name ($option_group) in the options API settings_fields( 'my-page' ); // page slug on which the form is displayed do_settings_sections( 'my-page' ); submit_button(); ?> </form>
#2 More examples
For other examples of use, see the examples on the API settings page.
Changelog
| Since 2.7.0 | Introduced. |
settings_fields() settings fields code WP 6.9.1
function settings_fields( $option_group ) {
echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group ) . "' />";
echo '<input type="hidden" name="action" value="update" />';
wp_nonce_field( "$option_group-options" );
}