Skip to content

Instantly share code, notes, and snippets.

@michelve
Created February 15, 2016 20:22
Show Gist options
  • Save michelve/9133386b48a3b3fe466a to your computer and use it in GitHub Desktop.
Save michelve/9133386b48a3b3fe466a to your computer and use it in GitHub Desktop.
wordpress auto login
/*
Plugin Name: Auto Login
Plugin URI: http://hbt.io/
Version: 1.0.0
Author: Harri Bell-Thomas
Author URI: http://hbt.io/
*/
function autologin() {
// PARAMETER TO CHECK FOR
if ($_GET['autologin'] == 'demo') {
// ACCOUNT USERNAME TO LOGIN TO
$creds['user_login'] = 'demo';
// ACCOUNT PASSWORD TO USE
$creds['user_password'] = 'demo';
$creds['remember'] = true;
$autologin_user = wp_signon( $creds, false );
if ( !is_wp_error($autologin_user) )
header('Location: wp-admin'); // LOCATION TO REDIRECT TO
}
}
// ADD CODE JUST BEFORE HEADERS AND COOKIES ARE SENT
add_action( 'after_setup_theme', 'autologin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment