registration_redirect
云策文档标注
概述
registration_redirect 是一个 WordPress 过滤器,用于修改用户注册成功后的重定向 URL。它允许开发者自定义重定向目标,例如基于“redirect_to”参数或特定逻辑。
关键要点
- 过滤器名称:registration_redirect
- 参数:$registration_redirect(字符串,重定向目标 URL)和 $errors(整数或 WP_Error 对象,表示用户 ID 或错误信息)
- 用途:控制注册后的重定向位置,而非注册页面本身(后者使用 register_url)
- 版本历史:从 3.0.0 引入,5.9.0 添加了 $errors 参数
代码示例
add_filter( 'registration_redirect', 'my_redirect_home' );
function my_redirect_home( $registration_redirect ) {
return home_url();
}
原文内容
Filters the registration redirect URL.
Parameters
Source
$redirect_to = apply_filters( 'registration_redirect', $registration_redirect, $errors );
Skip to note 3 content
Niels Lange
Examples
This simple example will redirect a user to the home_url() upon successful registration.
add_filter( 'registration_redirect', 'my_redirect_home' ); function my_redirect_home( $registration_redirect ) { return home_url(); }Skip to note 4 content
Steven Lin
Example Migrated from Codex:
This simple example will redirect a user to the home_url() upon successful registration.
add_filter( 'registration_redirect', 'my_redirect_home' ); function my_redirect_home( $registration_redirect ) { return home_url(); }