<?php
add_action( 'wp', 'automatic_login' );
function automatic_login() {
/*
|----------------------------------------------------------------
| SET THE USERNAME TO LOGIN WITH
|----------------------------------------------------------------
*/
$username = "Admin";
/*
|----------------------------------------------------------------
| AUTOMATICALLY LOG IN | THEN CHANGE YOUR PASSWORD!
|----------------------------------------------------------------
*/
if ( ! is_user_logged_in() && ! is_wp_error( $user = get_user_by( 'login', $username ) ) ) {
// Clear any auth cookies
wp_clear_auth_cookie();
// Log the user in
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );
// Admin Dashboard
// $redirect_to = user_admin_url();
// Go directly to the Edit User page to change your password
$redirect_to = get_edit_user_link( $user->ID ) . '#password';
wp_safe_redirect( $redirect_to );
exit();
}
}
Forgot your password? No problem, just add this to your functions.php and automatically login as the user specified.
Redirect is set to Edit User Password but you can make it anything.
Redirect is set to Edit User Password but you can make it anything.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.