I am trying to use the custom_action hook to generate and send the password reset link to the user.
My setup so far is:
- created a form with a email field and a hidden field
- added hidden field on the Email content - {{field_id}}
- Used add_action(âbricks/form/custom_actionâ, âform_reset_password_custom_actionâ, 10, 1);
- Inside the form_reset_password_custom_action() function I generate the link with the userâs email
- Add the reset link to the hidden field, as such
$fields = $form->get_fields();
$fields['form-field-hdpbqn'] = $reset_pass_link;
Full code below.
The issue is that the reset link is not showing on the email.
I have tested and can confirm that:
- The hidden field when added a value manually works and can be seen in the email
- The reset link is being generated successfully
- And it is being added as the hidden field value.
function form_reset_password_custom_action($form)
{
$fields = $form->get_fields();
if ($fields['formId'] !== 'ulqmtn') {
return;
}
$user_email = $fields['form-field-04da93'];
$user = get_user_by('email', $user_email);
$reset_key = get_password_reset_key($user);
$user_login = $user->user_login;
$reset_pass_link = '<a href="' . network_site_url("wp-login.php?action=rp&key=$reset_key&login=" . rawurlencode($user_login), 'login') . '">Reset Password</a>';
$fields['form-field-hdpbqn'] = $reset_pass_link;
}
add_action('bricks/form/custom_action', 'form_reset_password_custom_action', 10, 1);
Here are some screenshots of the form setup on the builder
