register_form
云策文档标注
概述
register_form 是一个 WordPress 动作钩子,在用户注册表单的“Email”字段后触发,主要用于自定义注册表单的字段添加或修改。
关键要点
- register_form 钩子在注册表单的“Email”字段后执行,允许开发者添加自定义字段或修改表单内容。
- 自定义注册时,需结合 registration_errors 钩子进行验证,并使用 register_post 钩子保存额外数据。
- 在 WordPress 多站点(MS)环境中,应使用 signup_header 动作来重定向用户,而非 register_form。
- 添加的字段不会自动保存,需要手动设置验证规则和处理保存逻辑。
代码示例
add_action( 'register_form', 'wporg_myplugin_add_registration_fields' );
function wporg_myplugin_add_registration_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 ‘Email’ field in the user registration form.
Source
do_action( 'register_form' );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Skip to note 3 content
Tom Carney
This example demonstrates how to add a new field to the registration 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.
Choose the codes/blocks for translation accurately, otherwise the above function may change other parts of the registration page.