views:

49

answers:

2

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.

A: 

"Add a login form on your WordPress Theme" (including remember me functionality): http://www.wprecipes.com/add-a-login-form-on-your-wordpress-theme

Also: http://www.problogdesign.com/how-to/how-to-create-a-wordpress-login-form-overlay/

etc...

zaf
i checked that post already. The problem is he used the wp-login.php at form action. The theme i used is using own function for the form post which i posted at above.
morningglory
Then why don't you just use the code from wp-login.php?
zaf
because if i use wp-login.php, if user leave blank the usrename or password, when returning error, they will be carried out away from current login box and wordpress will show validation error at wp-login . That's why
morningglory
I said 'use the code'. I didn't say use all of it. Also, isn't wp-login.php part of your theme as well?
zaf
yes, i tried to find possibility from wp-login.php, but i am not sure which are the codes it used for remember me. I only see html checkbox from there. Seems like there may be other file which is controlling, because i saw remember me functionality at wp-includes/user.php also. If you can, can you take a look for me as well ? Currently I am desperate to get that. Thanks
morningglory
A: 

"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();
}
Marc B