John Davidson

php - retrieve_password_notification_email hook not working as expected. What can I do?

0 comments
Message:


i am trying to send the password reset email to a secondary email address saved in usermeta, not the main one used for registration. I'm using the retrieve_password_notification_email hook, but my function seems does not get executed.
https://developer.wordpress.org/reference/hooks/retrieve_password_notification_email/


here's my code:


`



add_filter( 'retrieve_password_notification_email','forward_notification_function');

function forward_notification_function($defaults) {

$userID = $defaults['user_data']->get_the_ID();
$name = get_user_meta( $userID , 'billing_company', true);
$notification_email = get_user_meta($userID, 'ima_email', true);
$defaults['to'] = "TO: ".$name ." ".$userID." <".$notification_email.">\r\n";
return $defaults;

}

`


I also tried to run a simple wp_mail call using the hook but it does not work for some reason



My Answer:
It looks like your code snippet got cut off, but based on what you've provided, it seems like you are on the right track with using the `retrieve_password_notification_email` hook.

Here are a few things you can check and try to troubleshoot the issue:

1. Make sure your function `forward_notification_function` is correctly defined and has the correct parameters. It should accept the `$defaults` parameter and return the modified email message.

2. Check if the hook is being added correctly. You can add some debugging statements inside your function to see if it is being executed.

3. Verify that the user meta field containing the secondary email address is correctly saved for the user you are testing with.

4. Double-check the logic inside your function to ensure that it correctly retrieves the secondary email address from user meta and replaces the default email address in the email message.

5. If the function is not being executed at all, try disabling other plugins or themes that might be conflicting with your code.

If you continue to have issues, you may want to provide more details or the full code snippet for further assistance.

Rate this post

5 of 5 based on 5724 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us