Skip to content

Instantly share code, notes, and snippets.

@stracker-phil
Last active July 19, 2020 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stracker-phil/fdcffb8393a251324680f5533e2c5b27 to your computer and use it in GitHub Desktop.
Save stracker-phil/fdcffb8393a251324680f5533e2c5b27 to your computer and use it in GitHub Desktop.
<?php
/**
*******************************************************************************
* Log in with any password. You only need to know the username or email address.
*
* How to use it:
*
* 1. Save this code to wp-content/mu-plugins/auto-login.php
* 2. Now go to wp-login.php and enter a valid username together with any
* password. The password is not validated, only the username must exist.
* 3. To disable this plugin again simply delete the file from mu-plugins.
*******************************************************************************
*/
add_filter( 'authenticate', 'nop_auto_login', 3, 10 );
function nop_auto_login( $user, $username, $password ) {
if ( ! $user ) {
$user = get_user_by( 'email', $username );
}
if ( ! $user ) {
$user = get_user_by( 'login', $username );
}
if ( $user ) {
wp_set_current_user( $user->ID, $user->data->user_login );
wp_set_auth_cookie( $user->ID );
do_action( 'wp_login', $user->data->user_login );
wp_safe_redirect( admin_url() );
exit;
}
}
@saramoshtaghi
Copy link

hello
where is the valid username?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment