Skip to content

Function

Filter the lost password URL.

tml_filter_lostpassword_url( string $url, string $redirect )

Parameters

$url string
The URL.
$redirect string
The redirect.

Return

string The lostpassword URL.

Source

function tml_filter_lostpassword_url( $url, $redirect ) {
    global $pagenow;

    // Bail if currently visiting wp-login.php
    if ( 'wp-login.php' === $pagenow ) {
        return $url;
    }

    // Bail if logout action doesn't exist for some reason
    if ( ! tml_action_exists( 'lostpassword' ) ) {
        return $url;
    }

    // Get the lostpassword URL
    $url = tml_get_action_url( 'lostpassword' );

    // Add the redirect query argument if needed
    if ( ! empty( $redirect ) ) {
        $url = add_query_arg( 'redirect_to', urlencode( $redirect ), $url ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode -- matches wp_lostpassword_url()'s own encoding of the redirect_to arg.
    }

    return $url;
}

Uses

See also

Changelog

VersionDescription
7.0.11 Introduced.