Filter uncanny-learndash-groups

retrieve_password_message

Filters the message body of the password reset mail. If the filtered message is empty, the password reset email will not be sent. Filters the password reset email message body before it's sent to the user, allowing customization.

add_filter( 'retrieve_password_message', $callback, 10, 4 );

Description

Filters the content of the password reset email. Developers can modify the message, add custom text, or even prevent the email from being sent by returning an empty string. This hook fires just before the password reset email is sent to the user.


Usage

add_filter( 'retrieve_password_message', 'your_function_name', 10, 4 );

Parameters

$message (mixed)
This parameter contains the HTML or plain text message that will be sent to the user to reset their password.
$key (mixed)
This parameter contains the actual HTML or plain text message that will be sent to the user's email address for password reset purposes.
$user_login (mixed)
This parameter contains the unique security key generated for the password reset process.
$user_data (mixed)
The `$user_login` parameter contains the username of the user for whom the password reset is being initiated.

Return Value

The filtered value.


Examples

/**
 * Modify the password reset email message to include a custom greeting and a link to a helpful article.
 *
 * @param string   $message    The default password reset message.
 * @param string   $key        The password reset key.
 * @param string   $user_login The username of the user requesting the reset.
 * @param WP_User  $user_data  The WP_User object for the user.
 * @return string The modified password reset message.
 */
function my_custom_retrieve_password_message( $message, $key, $user_login, $user_data ) {
    // Define a custom greeting.
    $greeting = sprintf( __( 'Hello %s,', 'my-text-domain' ), $user_data->display_name );

    // Create a link to a helpful article about password security.
    $helpful_link = '<a href="https://example.com/wordpress-password-security-tips/">' . __( 'password security tips', 'my-text-domain' ) . '</a>';

    // Construct the new message.
    $new_message = $greeting . '<br><br>';
    $new_message .= sprintf(
        __( 'You recently requested to reset your password for your account on %s.', 'my-text-domain' ),
        get_bloginfo( 'name' )
    ) . '<br><br>';
    $new_message .= sprintf(
        __( 'To reset your password, visit the following link: %s', 'my-text-domain' ),
        '<a href="' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . '">' . __( 'Reset Password', 'my-text-domain' ) . '</a>'
    ) . '<br><br>';
    $new_message .= sprintf(
        __( 'This link will expire in %s.', 'my-text-domain' ),
        sprintf(
            __( '%s hours', 'my-text-domain' ),
            absint( YEAR_IN_SECONDS / HOUR_IN_SECONDS ) // Default is 24 hours.
        )
    ) . '<br><br>';
    $new_message .= sprintf(
        __( 'If you did not request a password reset, please ignore this email or contact us if you have any concerns. For more information, please read our %s.', 'my-text-domain' ),
        $helpful_link
    ) . '<br><br>';
    $new_message .= __( 'Thanks,', 'my-text-domain' ) . '<br>';
    $new_message .= get_bloginfo( 'name' );

    // Return the modified message.
    return $new_message;
}
add_filter( 'retrieve_password_message', 'my_custom_retrieve_password_message', 10, 4 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/helpers/rest-api-end-points.php:1667

$message .= __( 'To reset your password, visit the following address:', 'uncanny-learndash-groups' ) . "rnrn";
				$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "rn";

				/* translators: Password reset notification email subject. %s: Site title */
				$title = sprintf( __( '[%s] Password Reset', 'uncanny-learndash-groups' ), $site_name );
				$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );

				$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
				$mail    = SharedFunctions::wp_mail( $user_email, wp_specialchars_decode( $title ), $message );
				if ( $message && ! $mail ) {
					$data['message'] = __( 'The email could not be sent. Possible reason: your host may have disabled the mail() function.', 'uncanny-learndash-groups' );
					wp_send_json_error( $data );
				}
			}
		}


Scroll to Top