Created
November 6, 2013 19:04
-
-
Save cb99999/7342146 to your computer and use it in GitHub Desktop.
php > auto login for wordpress users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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