If you’d dumped one of your $player
s you’d have seen the issue:
object(WP_User)#126 (7) {
["data"]=>
object(stdClass)#129 (10) {
["ID"]=>
string(1) "9"
["user_login"]=>
string(3) "abc"
["user_pass"]=>
string(34) "$P$BmwzlhY1xP6JTBlbWzLPetkx8lB.Zo/"
["user_nicename"]=>
string(3) "abc"
["user_email"]=>
string(19) "[email protected]"
["user_url"]=>
string(0) ""
["user_registered"]=>
string(19) "2013-10-04 09:22:08"
["user_activation_key"]=>
string(0) ""
["user_status"]=>
string(1) "0"
["display_name"]=>
string(3) "abc"
}
["ID"]=>
int(9)
// removed some unnecessary information
}
The ID is saved redundantly in the first level of that object, but the email address is not. It is in $player->data->user_email
. You are accessing the variable data incorrectly.
get_userdata
gives you exactly the same data that you already have– try it–, so that code is wasteful. Just use the $player
data.