钩子文档

lostpassword_url

💡 云策文档标注

概述

lostpassword_url 是一个 WordPress 过滤器,用于修改 wp_lostpassword_url() 函数返回的丢失密码页面 URL。它允许开发者自定义重定向路径,以指向特定的密码找回页面。

关键要点

  • 过滤器名称:lostpassword_url
  • 参数:$lostpassword_url(丢失密码页面 URL)和 $redirect(登录后重定向路径)
  • 应用场景:通过 wp_lostpassword_url() 函数调用,开发者可以控制用户被引导到的密码找回 URL
  • 引入版本:WordPress 2.8.0

代码示例

add_filter( 'lostpassword_url', 'my_lost_password_page', 10, 2 );
function my_lost_password_page( $lostpassword_url, $redirect ) {
    return home_url( '/lostpassword/?redirect_to=' . $redirect );
}

📄 原文内容

Filters the Lost Password URL.

Parameters

$lostpassword_urlstring
The lost password page URL.
$redirectstring
The path to redirect to on login.

More Information

The filter is applied to the URL returned by the function wp_lostpassword_url() , allowing the developer to have that function direct users to a specific (different) URL for retrieving a lost password.

Source

return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );

Changelog

Version Description
2.8.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    The following example would return a lost password URL https://example.com/lostpassword/ for the wp_lostpassword_url() function:

    add_filter( 'lostpassword_url', 'my_lost_password_page', 10, 2 );
    function my_lost_password_page( $lostpassword_url, $redirect ) {
        return home_url( '/lostpassword/?redirect_to=' . $redirect );
    }