Just log in some user and no worry

Here is the simple script to set some particular user as currently logged.


function auto_login( $user ) {
	$username   = $user;
	// log in automatically
	if ( !is_user_logged_in() ) {
		$user = get_userdatabylogin( $username );
		$user_id = $user->ID;
		wp_set_current_user( $user_id, $user_login );
		wp_set_auth_cookie( $user_id );
		do_action( 'wp_login', $user_login );

As you may see the process will also set the authentication cookie. Please note we don’t user wp_signon function here and there will be no error messages in case of errors.

tags: & category: -