biocuration / isb-website

Tracker for the website of the International Society for Biocuration
http://biocuration.org/
Other
2 stars 0 forks source link

reset password link not displaying in email #52

Closed andrewsu closed 4 years ago

andrewsu commented 5 years ago

A user reported (and I was able to replicate) a bug where the a reset password email is successfully being sent, but the link does not show up in the email. However, when examining the raw email, the link is present. See screenshot:

2019-02-15_10-55-00

As described in this link, some email clients do not like naked URLs embedded in angled brackets, so they are stripped. WPengine support says they cannot reproduce the problem in a fresh installation. Likely it is some conflict with an existing plugin. Nevertheless, the fix described at the link above worked. Specifically, in wp-login.php, I changed

$message .= ‘<‘ . network_site_url(“wp-login.php?action=rp&key=$key&login=” . rawurlencode($user_login), ‘login’) . “>\r\n”;

to

$message .= ‘(‘ . network_site_url(“wp-login.php?action=rp&key=$key&login=” . rawurlencode($user_login), ‘login’) . “)\r\n”;

This is not a great solution because likely this change will be overwritten when core files are updated... So need to find a more permanent fix.

andrewsu commented 5 years ago

note: easiest way to make this change is via sftp, credentials in the wpengine control panel

andrewsu commented 4 years ago

looks like https://wordpress.stackexchange.com/questions/246377/missing-url-in-password-reset-email describes a better way to address this issue that will be more persistent (and not overwritten when core files are updated).

andrewsu commented 4 years ago

I undid the change to wp-login.php described above and confirmed that the reset password link does not appear. Then I added the code below to /wp-content/themes/twentyfourteen-isb/functions.php and confirmed that the password link shows up successfully.

/**
 * Removes angle brackets (characters < and >) arounds URLs in a given string
 *
 * @param string $string    The string to remove potential angle brackets from
 *
 * @return string    $string where any angle brackets surrounding an URL have been removed.
 * 
 * From: https://wordpress.stackexchange.com/questions/246377/missing-url-in-password-reset-email
 * Addresses: https://github.com/biocuration/isb-website/issues/52
 */
function remove_angle_brackets_around_url($string)
{
    return preg_replace('/<(' . preg_quote(network_site_url(), '/') . '[^>]*)>/', '\1', $string);
}

// Apply the remove_angle_brackets_around_url() function on the "retrieve password" message:
add_filter('retrieve_password_message', 'remove_angle_brackets_around_url', 99, 1);

This should be a persistent fix to this reset password problem.