I'm developing a website where the username is a document number, called CPF (think of it as a national ID), which has the following mask:
000.000.000-00
I'm storing the usernames as plain numbers, but all our forms must have the mask above, which in turn makes it so the _POST['user_login']
always goes with the dash and dots. This is an example of a user's login/username:
$_POST['user_login'] = '123.456.789-00'
$actual_username_ondb = '12345678900'
This wasn't a problem for logging in, as I hook into the wp_authenticate action hook (not the pluggable function!) and I filter the username before continuing (and also check if the number is a valid CPF):
/**
* Hooks before login and filters out the CPF mask if it exists
*/
add_action( 'wp_authenticate' , 'filter_username' );
function filter_username(&$username) {
$cpf = preg_replace('/[^0-9]/is', '', $username);
if (is_valid_cpf($cpf)) {
$username = $cpf;
}
}
However, now I'm dealing with the lost password form, and I couldn't find any way to do the same as above, i.e.: filter $_POST['user_login']
before going on with the password retrieval.
If there's any way to do it, it'd be via the hook lostpassword_post
, because that's the earliest hook in the retrieve_password() function, but unfortunately it only triggers after the data is already parsed, so I don't know how it could be done.