Skip to content

Instantly share code, notes, and snippets.

@jkudish
Created January 13, 2012 21:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jkudish/1608708 to your computer and use it in GitHub Desktop.
Save jkudish/1608708 to your computer and use it in GitHub Desktop.
Always logged in with WordPress
<?php
/**
* keeps a user always logged in
* don't use this on a production site, ever!
*/
add_action('init', 'auto_login');
add_action('admin_init', 'auto_login');
function auto_login() {
if (!is_user_logged_in()) {
$user = get_userdata(1); // 1 being the ID that I want
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment