Last active
January 11, 2016 01:16
-
-
Save rheinardkorf/a42cc50d5d735777cc95 to your computer and use it in GitHub Desktop.
WordPress auto-login
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
<?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