How to bypass login in WordPress

2015-10-27

This is a small PHP-script that you can save in a PHP-file and move to the root directory of your WordPress site. Navigate to it through your browser and it will automatically authenticate you as the user you choose. It’s a good tool to have laying around if you get locked out of your own site.

And please remember to remove it once you’re done, in case someone else finds out about it.

<?php

require_once('wp-load.php');

auto_login("admin");  // Change this to your username

function auto_login($username) {
    $user = get_userdatabylogin($username);
    $user_id = $user->ID;
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action('wp_login', $user_login);
    wp_redirect(admin_url());
}

?>