Skip to content

Instantly share code, notes, and snippets.

@ooooak
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooooak/8737362671f529c851bb to your computer and use it in GitHub Desktop.
Save ooooak/8737362671f529c851bb to your computer and use it in GitHub Desktop.
[wordpress] login user by user id
<?php
/**
* @param Mix $id will user id
* @param String $user_login
*/
function login_user($id, $user_login) {
wp_set_current_user( $id, $user_login);
wp_set_auth_cookie( $id );
do_action( 'wp_login', $user_login );
}
$user = get_user_by('id', 1);
login_user($user->get('id'), $user->get('user_login'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment