I must be doing something wrong, but the following commented code returns false. Note that WP is returning 'admin' as the 'user_login', but when that user_login is used for the get_user_by()
function it simply returns false. Am I missing something?
$user = get_userdata(1); // (admin ID is 1)
var_dump($user->user_login); // string(5) 'admin'
var_dump(get_user_by('user_login', $user->user_login)); // bool(false)
I am running WordPress 4.8.2
I believe you'll need to use "login" rather by "user_login" in the get_user_by call.
See the posssible accepted values of the function here: https://developer.wordpress.org/reference/functions/get_user_by/
Try this one it's working
$user = get_userdata(1); // admin ID = 1
var_dump($user->user_login); // string(5) 'admin'
var_dump(get_user_by('login', $user->user_login)); // return array with data