login_form
云策文档标注
概述
login_form 是一个 WordPress 动作钩子,在登录表单的“密码”字段后触发,用于自定义内置登录表单。通常与 login_head 钩子结合使用以实现验证功能。
关键要点
- login_form 钩子在登录表单的密码字段后执行,允许开发者添加自定义字段或内容。
- 此钩子自 WordPress 2.1.0 版本引入,源调用为 do_action( 'login_form' )。
- 使用 add_action( 'login_form', 'callback_function' ) 来挂载自定义函数,但需手动处理额外字段的验证和保存。
代码示例
add_action( 'login_form', 'myplugin_add_login_fields' );
function myplugin_add_login_fields() {
$user_extra = ( isset( $_POST['user_extra'] ) ) ? $_POST['user_extra'] : '';
?>
<p>
<label for="user_extra">Extra Field<br />
<input type="text" name="user_extra" id="user_extra" class="input" value="<?php echo esc_attr( $user_extra ); ?>" size="25" />
</label>
</p>
<?php
}注意事项
- 添加的自定义字段不会自动保存,需要开发者设置验证规则并手动处理数据保存。
- 在自定义登录表单时,应确保代码准确,避免意外影响登录页面的其他部分。
原文内容
Fires following the ‘Password’ field in the login form.
Source
do_action( 'login_form' );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Skip to note 4 content
Steven Lin
Example migrated from Codex:
This example demonstrates how to add a new field to the login form. Keep in mind that this won’t be saved automatically. You will still need to set up validation rules and manually handle saving of the additional form fields.
Skip to note 6 content
Steven Lin
Example migrated from Codex: