Getting user info at wp_login hook?
-
I am working on a plugin that, when a user successfully logs in to WP, checks that user’s capabilities (using the current_user_can function) and conditionally sets a login cookie for ZenPhoto, which is installed side-by-side with WP.
I am using the wp_login hook, which is the last hook I can use before the user is redirected and the admin_header stuff starts getting written (i.e. by then it’s too late to set a cookie).
But current_user_can wasn’t returning the expected value, so I tried to check on the user by var_dump’ing the value returned by wp_get_current_user. But this function returns basically an empty user object even when the user should be successfully logged in:
object(WP_User)#87 (6) {
["data"]=>
NULL
["id"]=>
int(0)
["caps"]=>
array(0) {
}
["cap_key"]=>
NULL
["roles"]=>
array(0) {
}
["allcaps"]=>
array(0) {
}
}However, if I reload wp-login.php after I log in, the same function returns a full-fledged user with all roles and everything in place.
So, I guess the question is: what can I do from the wp_login hook to get the user info populated, so that I can use current_user_can? (Or, should I be trying to set this cookie at a different/better hook anyway??)
Thanks for any insights. Oh, and I know how easy it would be to hack wp-login.php, but my goal is to keep this hack-free.
- The topic ‘Getting user info at wp_login hook?’ is closed to new replies.