If your code, you use the first argument passed to wp_authenticate_user
filter callback. That is a WP_User object, it not a email address and it is not a string.
You may be confusing because of the name of the variable, $username
, I suggest to change the name to $user
, whcih is more appropiate and it is a better representation of the real value of that variable.
add_filter('wp_authenticate_user', 'filter_login_auth', 10, 3);
function filter_login_auth( $user, $password ) {
//get posted value
$value = $_POST['klantnr'];
//get user object
$user = get_user_by('login', $user->user_login);
// .....
}
But you don’t need that because get_user_by()
returns a user object and you already have it:
add_filter('wp_authenticate_user', 'filter_login_auth', 10, 3);
function filter_login_auth( $user, $password ) {
//get posted value
$value = $_POST['klantnr'];
// You don't need this, you already have the user object
// get user object
//$user = get_user_by('login', $user->user_login);
// .....
}
For more information, see wp_authenticate_user
docs.