Skip to content

Instantly share code, notes, and snippets.

@cb99999
Created November 6, 2013 19:04
Show Gist options
  • Save cb99999/7342146 to your computer and use it in GitHub Desktop.
Save cb99999/7342146 to your computer and use it in GitHub Desktop.
php > auto login for wordpress users
// put in functions.php
function auto_login( $user ) {
$username = $user;
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 );
}
}
// Then, to log in a user, do the following:
auto_login( 'admin' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment