最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - what is the meaning of settings_fields()

programmeradmin4浏览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 );

发布评论

评论列表(0)

  1. 暂无评论