functions - what is the meaning of settings_fields()

admin2025-04-16  0

Please guys , I tried a lot ro find out what's the main purpose of this function , but i didn't find what i want , i looked in the codex but seriously the description is not clear , i tried to see examples but finnally i saw an example i didn't understand nothing from it .

<?php
echo '<form method="post" action="options.php">';
settings_fields( 'my-plugin-settings-group' );
?>

Please guys , I tried a lot ro find out what's the main purpose of this function , but i didn't find what i want , i looked in the codex but seriously the description is not clear , i tried to see examples but finnally i saw an example i didn't understand nothing from it .

<?php
echo '<form method="post" action="options.php">';
settings_fields( 'my-plugin-settings-group' );
?>
Share Improve this question asked Dec 20, 2017 at 0:06 Simo PatrekSimo Patrek 1121 gold badge4 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Via the Developer Reference (not the Codex)

Output nonce, action, and option_page fields for a settings page.

Here's the source code for it

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");
}  

so, it gives the form processor some info to work with for the current options page, and verification with nonce on submit.

UPDATE

It's role is made more clear in the Settings API docs:

To display the hidden fields and handle security of your options form, the Settings API provides the settings_fields() function. settings_fields( $option_group );

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744809321a268188.html

最新回复(0)