Skip to content

Instantly share code, notes, and snippets.

@arioch1984
Last active August 29, 2015 14:01
Show Gist options
  • Save arioch1984/46d657c65d9bdb591eb7 to your computer and use it in GitHub Desktop.
Save arioch1984/46d657c65d9bdb591eb7 to your computer and use it in GitHub Desktop.
Log in a WordPress user programmatically
/*
* Taken from http://www.wprecipes.com/log-in-a-wordpress-user-programmatically
*/
<?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 );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment