函数文档

signup_nonce_fields()

💡 云策文档标注

概述

signup_nonce_fields() 函数用于在 WordPress 注册页面添加一个 nonce 字段,以增强表单安全性。该函数生成一个随机 ID 并调用 wp_nonce_field() 来输出隐藏字段。

关键要点

  • 函数 signup_nonce_fields() 在注册页面添加 nonce 字段,防止跨站请求伪造(CSRF)攻击。
  • 它使用 mt_rand() 生成随机 ID,并调用 wp_nonce_field() 输出带有特定 action 和 name 的隐藏字段。
  • 此函数自 WordPress MU 3.0.0 版本引入,属于核心功能的一部分。

代码示例

function signup_nonce_fields() {
    $id = mt_rand();
    echo "";
    wp_nonce_field( 'signup_form_' . $id, '_signup_form', false );
}

📄 原文内容

Adds a nonce field to the signup page.

Source

function signup_nonce_fields() {
	$id = mt_rand();
	echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
	wp_nonce_field( 'signup_form_' . $id, '_signup_form', false );
}

Changelog

Version Description
MU (3.0.0) Introduced.