Skip to content

Instantly share code, notes, and snippets.

@rheinardkorf
Last active January 11, 2016 01:16
Show Gist options
  • Save rheinardkorf/a42cc50d5d735777cc95 to your computer and use it in GitHub Desktop.
Save rheinardkorf/a42cc50d5d735777cc95 to your computer and use it in GitHub Desktop.
WordPress auto-login
<?php
/*
* Auto-login script to save having to manually login when developing a WP site.
*
* Place in wp-content/mu-plugins and remember to add to .gitignore for safety
*
* Add the DEV_GET_PARAMETER to the url to activate the script and login for you
* e.g. http://localhost:8080/?dev
*/
define('DEV_HOST', 'localhost');
define('DEV_USER', 'admin');
define('DEV_GET_PARAMETER', 'dev');
add_action('plugins_loaded', 'developer_admin_login');
function developer_admin_login() {
if ($_SERVER['SERVER_NAME'] === DEV_HOST && isset($_GET[DEV_GET_PARAMETER])) {
$admin = get_user_by('login', DEV_USER);
if ($admin && !is_user_logged_in()) {
wp_set_auth_cookie($admin->ID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment