Skip to content
  1. Blog

Favorite WP-CLI Packages: Login Command

Ben Word Ben Word on

Passwordless logins for WordPress

wp-cli-login-command is a package by Evan Mattson that creates passwordless links for your WordPress sites.

I’ve been adding the login command WP-CLI package on every site that I’ve touched since the beginning of last year. If you’re a Trellis user, you can define wp_cli_packages in main.yml to have them installed on your sites:

  - aaemnnosttv/wp-cli-login-command

Make sure to also add the companion WordPress plugin to your Bedrock/Composer based WordPress site:

$ composer require aaemnnosttv/wp-cli-login-server

I also install the package on my host machine for when I’m working on Valet sites:

$ wp package install aaemnnosttv/wp-cli-login-command

After installing the WP-CLI Login Command package and activating the companion WordPress plugin, we can start diving into wp login:

usage: wp login create <user-locator> [--expires=<seconds-from-now>] [--url-only] [--launch]
   or: wp login email <user-locator> [--expires=<seconds-from-now>] [--template=<path-to-template-file>]
   or: wp login install [--activate] [--yes]
   or: wp login invalidate
   or: wp login toggle [<on|off>]

The simplest usage:

$ wp login create admin
Success: Magic login link created!
This link will self-destruct in 15 mins, or as soon as it is used; whichever comes first.

Following the link will bring you directly to the WordPress admin dashboard for the user you defined ✨.

In conjunction with WP-CLI aliases, the login command is even more powerful by allowing you to quickly login to any environment of a WordPress site.

Right now I’m switching between several projects that I consistently login to via wp login. Being able to define the environment means that I never have to leave my host terminal to get into a site:

$ cd ~/Sites/
$ wp @staging login create traderjoes
Success: Magic login link created!
This link will self-destruct in 15 mins, or as soon as it is used; whichever comes first.

Implementation with a Slack bot

A year ago I started heading down the path of integrating BotMan and the WP-CLI login command together in order to get passwordless links via Slack:

WP-CLI login command bot

There’s a lot of potential with this command and all of the ways you could go about implementing it. Evan’s plans for v2 include:

  • Move all core functionality to the server plugin (no interface). This should make things a bit simpler implementation-wise and the CLI will be more of a “client” for using the plugin. This will also allow for programmatic creation of logins via your own plugin 🎉
  • Move magic login data to a custom table to allow for some new features that aren’t possible with the current transient-based persistence.
  • Probably rewrite a bunch of stuff.
  • GitHub Updater?
  • Punch & pie.

Keep in mind that user passwords are still in place with this command and plugin out of the box, but modifying your WordPress installation to be completely passwordless isn’t out of the question.

Magic Password looks promising, but there’s not much going on in this space right now.

About the author

Ben Word

Ben Word has been creating WordPress sites since 2004. He loves dogs, climbing, and yoga, and is passionate about helping people build awesome things on the web.

Subscribe for updates

Join over 8,000 subscribers on our newsletter to get the latest Roots updates and tips on building better WordPress sites

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?