I'm creating a custom password reset page on a site, and am trying to leverage
retrieve_password() to send the reset email. Upon sending the reset email, I'd like to
wp_redirect the user back to the login page with a flash message telling them to check their email. Herein lies the problem:
If you take a look at the link above, you'll notice that Hookr's suggested usage of
retrieve_password() has a check to see if the function exists yet, and if not includes
wp-login.php, where the WordPress (core) defines that function. It would seem that my
wp_loaded action that handles this process doesn't occur in a context with that file loaded, so I do need to include
wp-login.php before I can use
The problem is that
wp-login.php automatically does some client rendering, which causes headers to be sent, preventing me from sending headers in the future.
wp_redirect() relies on the usage of headers to work, and as such is breaking since it's called after
wp-login.php is included.
It would seem I have a few options; namely:
require_once 'wp-login.phpin an output buffer to prevent rendering/headers
- Copy+Paste or rewrite
retrieve_password()outside the context of
wp-login.php, and reference my new version.
your suggestion here?
None of these options seem too appealing to me. Using an output buffer seems like a bad practice, and I'm not entirely certain what all else will be run in the background when I do this. I'd prefer to leverage as much of WordPress' built-in password reset functionality as possible, and so I'm also hesitant to rewrite the
I'm sure this has been done before. Does anyone have a suggestion here? Am I chasing a poor solution trying to rely on
retrieve_password(), rather than just writing my own email logic?