How to add WordPress password reset link in HTML email?
P粉136356287
2023-09-02 13:52:43
<p>I'm trying to replace the WP core password reset email with an Html email. Overall it works great, the emails are well formatted and sent correctly. However, implementing a dynamic reset of the link doesn't work (as does the username, but that's not even the most important thing) </p>
<p>I used the following code in my template's functions.php: </p>
<pre class="brush:php;toolbar:false;">add_filter( 'wp_mail_content_type','prefix_set_content_type' );
function prefix_set_content_type() {
return "text/html";
}
add_filter( 'retrieve_password_message', 'replace_retrieve_password_message', 10, 2 );
function replace_retrieve_password_message( $message, $key, $user_login, $user_data ) {
$message = '<html...>A lot of html content (basically formatted emails)</html>'</pre>
<p>Doing so will result in a fatal error because the function expects 4 parameters but only receives 2 (said in the bug report email). When I omit $user_data and $key, the error disappears, but I still don't know how to implement dynamic linking...</p>
<p>When I try to include this link in Html, it only sends half of the link (probably due to the '""'): </p>
<pre class="brush:php;toolbar:false;">' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), ' login' ) . '</pre>
<p>Does anyone have any ideas on how to resolve this issue? Thanks. </p>
Put 4 at the end of the line instead of 2.
You must tell add_filter() and add_action() how many arguments the hook function requires.