Last active
April 2, 2020 10:09
-
-
Save New0/b8685d9f1230d6cd6fefce64e1cabf86 to your computer and use it in GitHub Desktop.
Two examples to add a reset password link in Caldera Forms, first uses main mailer, second sends an independant email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* Sends and independant email with a reset password link | |
* | |
*/ | |
add_action( 'caldera_forms_do_mailer', function( $mail, $data, $form ) { | |
if( 'CF5e85b15e45b2a' == $form[ 'ID' ] ) { // Use you own Form ID instead of CF5e85b15e45b2a | |
$user_email = $data['fld_6009157']; // Use the ID of the email field that defines the user instead of fld_6009157 | |
$user = get_user_by( 'email', $user_email ); | |
if(!$user){ | |
return; | |
} | |
$username = $user->user_login; | |
$key = get_password_reset_key( $user ); | |
$reset_link = wp_login_url() . '?action=rp&key=' . $key . '&login=' . $username; | |
$message = '<h2>' . __('Proceed to reset password : ', 'my_slug') . '</h2><br />' . | |
__('Reset your password link : ', 'my_slug') . | |
'<a href="'. esc_url( $reset_link ) . '" title="' . __('Reset your password link : ', 'my_slug') .'" >' . | |
esc_url( $reset_link ) . '</a>'; | |
wp_mail( $user_email, $mail['subject'], stripslashes( $message ), "Content-Type: text/html; charset=UTF-8" ); | |
} | |
}, 10, 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* Adds a reset password link to Caldera Forms main mailer | |
* Make sure to use main mailer to send to the same email field used to define the user | |
* | |
*/ | |
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) { | |
if( 'CF5e85b15e45b2a' == $form[ 'ID' ] ) { // Use you own Form ID instead of CF5e85b15e45b2a | |
$user_email = $data['fld_6009157']; // Use the ID of the email field that defines the user instead of fld_6009157 | |
$user = get_user_by( 'email', $user_email ); | |
$username = $user->user_login; | |
$key = get_password_reset_key( $user ); | |
$reset_link = wp_login_url() . '?action=rp&key=' . $key . '&login=' . $username; | |
$mail['message'] .= __('Reset your password link : ', 'my_slug') . esc_url( $reset_link ); // Use your own slug instead of my_slug | |
} | |
return $mail; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment