How to add Remember me function at custom login box?

In my theme, there’s custom page for the login. Login function at functions.php is like this

   function log_in($username, $password) {

    $user = parse_user($username);

    $username = $username;
    $password = $password;

    if(isEmptyString($username)) return new WP_Error('username', 'required');
    if(isEmptyString($password)) return new WP_Error('password', "required");
    if(!wp_check_password( $password, $user->user_pass ) ) return new WP_Error('wrong_password', "wrong");

    wp_set_auth_cookie($user->ID, $remember);
    wp_login($username, $password);

    redirect_profile();

}

function parse_user($info = null, $return = 'object') {
    if ( is_null( $info ) ) {
        global $current_user;
        if ( empty( $current_user->ID ) ) return null;
        $info = get_userdata( $current_user->ID );
    }
    elseif ( empty( $info ) ) {
        return null;
    }
    if( $return == 'ID' ) {
        if ( is_object( $info ) ) return $info->ID;
        if ( is_numeric( $info ) ) return $info;
    }
    elseif( $return == 'object' ) {
        if ( is_object( $info ) && $info->ID) return $info;
        if ( is_object( $info )) return get_userdata( $info->ID );
        if ( is_numeric( $info ) ) return get_userdata( $info );
        if ( is_string( $info ) ) return get_userdatabylogin( $info );
    }
    else {
        return null;
    }
}

I want to add remember me checkbox for user to logged in all the time until they logout. How can i add this ? Please kindly help me out. Thank you.

Related posts

Leave a Reply

2 comments

  1. “remember me” buttons are generally just a simple tweak to the cookie settings internally. Instead of a session cookie that gets deleted when the browser is exitted, a “remember me” login cookie gets some future expiration point (a day, a month, a year, etc…) so it’ll persist after the browser’s closed.

    In pseudo-code, you’d have:

    if (form_value('remember_me') == 'yes) {
         set_long_term_cookie();
    } else {
         set_session_cookie();
    }