I am trying to customize the notification email sent to user that contains the link to set password.
Currently, I have set up a custom user registration and login forms at the urls site.com/register
and site.com/login
respectively.
After the registration, wordpress is sending email with following link that asks to set a password.
site.com/wp-login.php?action=rp&key=XYieERXh3QinbU4VquB2&login=user%40gmail.com
I want it replace this url to
site.com/login?action=rp&key=XYieERXh3QinbU4VquB2&login=user%40gmail.com
I have tried the following code in functions.php
add_filter( 'wp_new_user_notification_email', 'my_wp_new_user_notification_email', 10, 3 );
function my_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
$message .= __('Hello To set your password, visit the following address:') . "\r\n\r\n";
$message .= '<' . network_site_url("login/?key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";
$wp_new_user_notification_email['message'] = $message
return $wp_new_user_notification_email;
}
I think I am missing $key
information since the email received has the link like this:
site.com/login?action=rp&key=&login=user%40test.com
How to fix this?