I have a simple auto log in hook that looks like the following:
function auto_login() {
if (!is_user_logged_in()) {
//Removed some code for brevity.
$user = get_userdatabylogin($domainName);
if ($user != null) {
//Set the auth cookie.
wp_set_auth_cookie($user->ID, false, null);
//Set the current user (this will also set WP objects at the global level)
wp_set_current_user($user->ID);
}
}
}
add_action('init', 'auto_login');
This code does work, but, in order to get the admin bar at the top of the page it requires a page refresh. This makes me think that I'm not getting some global objects populated early enough in the Wordpress page life cycle.
Should I be calling this method somewhere else besides init
?