scarstens
9/3/2014 - 8:39 PM

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

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!

/**
  * 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' );
}