Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Login to remember the login for next session, just like "Remember Me" option in standard login form. #139

Open
inf3cti0n95 opened this issue Dec 16, 2022 · 4 comments
Assignees
Milestone

Comments

@inf3cti0n95
Copy link

I want the plugin to remember the login, just like "Remember Me" option in standard login form.

@username0136
Copy link

+1

@aviral-mittal
Copy link

We are considering adding this feature in next release - however, not final yet.

Thanks for pointing this out.

@rothschild86
Copy link

+1
pretty useless for my users without this...

perhaps could borrow some tactics from this plugin? https://wordpress.org/plugins/wp-persistent-login/

@rothschild86
Copy link

rothschild86 commented May 18, 2024

Here's tested working code on persisting the login - as seen in https://wordpress.org/plugins/wp-persistent-login/ wp-persistent-login.php:348

essentially, it finds the relevant session, updates it, and then creates a new cookie

add_action( 'wp_login', function($user_login, $user){

//calls into persistent login plugin https://wordpress.org/plugins/wp-persistent-login/

if(!class_exists('WP_Persistent_Login_Manage_Sessions')){return;}

$user_id = $user->ID;

update_user_meta( $user_id, 'persistent_login_remember_me', 'true');

// get the users latest session from the database
$sessions = get_user_meta( $user_id, 'session_tokens', true );
if( is_array($sessions) ) {

	// fetch the login time column from the array
	$login_times = array_column($sessions, 'login');

	// sort the sessions by login times (newest first)
	array_multisort( $login_times, SORT_DESC, $sessions );

	// get the key (verifier) of the first session
	$session_verifier = array_key_first($sessions);

	//remove the session from the database
	$wp_login_manage_sessions = new WP_Persistent_Login_Manage_Sessions( $user_id );
	$wp_login_manage_sessions->persistent_login_update_session( $session_verifier, null );

	// set a new cookie with remember me checked
	wp_set_auth_cookie( $user_id, true );
}

}, 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants