settings_fields()
Output nonce, action, and option_page fields for a settings page.
Uses: wp_nonce_field()
No Hooks.
Return
null
. Nothing.
Usage
settings_fields( $option_group );
- $option_group(string) (required)
- A settings group name. This should match the group name used in register_setting().
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.1.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" ); }