Support » Plugins » Hacks » Custom Log In, request for reauth on wp-admin

Viewing 5 replies - 1 through 5 (of 5 total)
  • Apparently the wp_set_auth_cookie() function is all that’s required. I placed this into my log in script, and it’s now seamless between log in and admin dashboard.

    wp_set_auth_cookie($user_data->ID);

    Hi,

    We are having the same problem you had. Unfortunately, from your answer I still don’t know how to fix it. Where exactly did you place the line wp_set_auth_cookie($user_data->ID);?

    Robin,

    I’m storing get_user_by() data in the $user_data variable, and after the wp_signon() is verified is when I call wp_set_auth_cookie($user_data->ID);. The ID is part of the get_user_by() array.

    Hope this helps, if so let me know.

    Charles

    You sir, are a gentlemen and a scholar. Thanks! =) Just for kicks, here is a working example after receiving the post from the login form:

    if ($_POST) {
    
        $errors = array();
    
        $username = $wpdb->escape($_REQUEST['username']);
        $password = $wpdb->escape($_REQUEST['password']);
        $remember = $wpdb->escape($_REQUEST['rememberme']);
        $remember = ($remember) ? "true" : "false";
    
        $login_data = array();
        $login_data['user_login'] = $username;
        $login_data['user_password'] = $password;
        $login_data['remember'] = $remember;
        $user_verify = wp_signon($login_data, true);
    
        if (is_wp_error($user_verify)) {
            $errors[] = 'Invalid username or password. Please try again!';
        } else {
            wp_set_auth_cookie($user_verify->ID);
    
            if(isset($_POST['redirect_to'])){
                $go_to = $_POST['redirect_to'];
            } else {
                $go_to = home_url();
            }
    
            wp_redirect($go_to);
            exit;
        }
    
    }

    thanks getrouty 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Log In, request for reauth on wp-admin’ is closed to new replies.