Last active
August 29, 2015 14:06
-
-
Save scarstens/c3c4730937c79da3bffe to your computer and use it in GitHub Desktop.
WordPress auto login hack used when you have FTP access but no WordPress login, chooses the first admin and logs you in as that when you add ?admin=login to the URL. DONT FORGET TO REMOVE THIS WHEN YOUR DONE!
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
/** | |
* Script to enabled temporary access to first admin account auto login | |
*/ | |
function auto_login() { | |
if ($_GET['admin']=='login') { | |
$user_query = new WP_User_Query( array( 'role' => 'Administrator' ) ); | |
$user_id = $user_query->results[0]->ID; | |
wp_set_current_user($user_id, $user_login); | |
wp_set_auth_cookie($user_id); | |
do_action('wp_login', $user_login); | |
die('logged in'); | |
} | |
} | |
if(!empty($_GET['secret']) && $_GET['secret'] == '6o42Ha2KKwjEh!A6'){ | |
add_action('init', 'auto_login'); | |
} | |
/** | |
* Script to enabled temporary admin user to be created | |
*/ | |
function add_admin_acct(){ | |
$login = 'TempWordPressLogin'; | |
$passw = 'N8*2lMqKYjDQ%8Sj'; | |
$email = 'PLEASESETUPYOUREMAIL@localhost.dev'; | |
if ( ! username_exists( $login ) && ! email_exists( $email ) ) { | |
$user_id = wp_create_user( $login, $passw, $email ); | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'administrator' ); | |
} | |
} | |
if ($_GET['admin']=='create') { | |
add_action( 'init', 'add_admin_acct' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment