WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)
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?

share|improve this question
up vote 2 down vote accepted

Maybe it is too late to hook on init. Try set_current_user or some earlier hook. List is here: https://codex.wordpress.org/Plugin_API/Action_Reference

share|improve this answer
Cheers. It looks like set_current_user is early enough in the cycle to accomplish this. – Ek0nomik Feb 1 '13 at 14:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.