Allow one-click logins on local

I’d love to see Local allowing one-click user login and user switching the way DesktopServer does; it’s nice when I’m pulling down a copy of a site and don’t know the password (there are other ways around that, of course). It’s also nice because then I don’t have to look up a password for sites I’m logging into on my local machine.

This is likely a relatively simple addition (compared with most of the feature requests on here), and could even be an addon for Local.

1 Like

I’ve added this snippet to my mu-plugin:

add_action( 'init', function() {
		if ( is_admin() && !is_user_logged_in() ) {

			if ( $user = get_user_by( 'login', 'YOURUSERNAME' ) ) {
				wp_set_current_user ( $user->ID );
				wp_set_auth_cookie  ( $user->ID, true );
				wp_safe_redirect( esc_url( $_SERVER['REQUEST_URI'] ) );

	} );

It automatically logs you in with “YOURUSERNAME” if the backend is requested. Make sure you only use it on your local environment!

You could probably actually slightly improve this snippet by using the user ID number so that you don’t have to type in the username if it differs per site.

This is exactly the sort of thing I’d like to see baked into Local (so that I couldn’t ever accidentally deploy something like this to prod).

1 Like