I've added an extra field to the login form. When trying to get the user's value of that field(before checking if it's equal) I have a get_user_by('login', $username);
. $username being an email adres(the only thing I'll allow.)
The specific error is:
Warning: trim() expects parameter 1 to be string, object given in /(removed for privacy)/public_html/wp-includes/class-wp-user.php on line 201
Full code: (After click on login on /wp-login)
add_filter('wp_authenticate_user', 'filter_login_auth', 10, 3);
function filter_login_auth($username, $password) {
//get posted value
$value = $_POST['klantnr'];
//get user object
$user = get_user_by('login', $username);
//get stored klantnr
$stored = get_user_meta($user->ID, 'klantnr', true);
if(!$user || empty($value) || $value != $stored) {
//No user, empty, or not correct
remove_action('authenticate', 'wp_authenticate_username_password', 20);
//Create error to return
$user = new WP_Error('denied', __("<strong>ERROR</strong>: Je klantnummer is niet correct."));
}
// return null so if klantnr is correct the script continues.
return $user;
}
$username
varible?