钩子文档

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

$registration_redirectstring
The redirect destination URL.
$errorsint|WP_Error
User id if registration was successful, WP_Error object otherwise.

More Information

  • The registration redirect filter is used to change the location redirected to after a user registers. This could be the location set by the “redirect_to” parameter sent to the registration page.
  • This filter is to redirect the user following registration. To filter the location of the registration page itself, use register_url.

Source

$redirect_to = apply_filters( 'registration_redirect', $registration_redirect, $errors );

Changelog

Version Description
5.9.0 Added the $errors parameter.
3.0.0 Introduced.

User Contributed Notes