Favorite WP-CLI Packages: Login Command


Originally published at: https://roots.io/favorite-wp-cli-packages-login-command/

This is the first post in a series on WP-CLI Packages. Most work days for me involve working on WordPress sites, which in-turn means that I’m regularly interacting with WP installs via WP-CLI. :desktop_computer: wp is the 4th most used command in my history, and wp login is one of my most frequently used commands.…


This is great! I’d be interested to know where BotMan is sitting in your example? Is there some sort of middleware or server in between Slack and where the site lives to handle the login logic / run the wp-cli login command?


In that example it’s sitting within a Laravel intranet/dashboard app that has cloned repos for all of our active projects. This is how I was testing it:

require 'vendor/autoload.php';

use Mpociot\BotMan\BotManFactory;
use React\EventLoop\Factory;

$loop = Factory::create();
$botman = BotManFactory::createForRTM([
    'slack_token' => env('SLACK_TOKEN')
], $loop);

$botman->hears('~login', function($bot) {
    $bot->reply("Use the following format:\n • ~login example.com\n • ~login example.com:staging\n");

$botman->hears('~login {login}', function($bot, $domain) {
    if (strpos($domain, ':staging') !== false) {
        $domain = preg_match("/.*\|(.*)>$/", $domain, $matches);
        $domain = $matches[1];
        $domain = str_replace(':staging', '', $domain);
        $environment = 'staging';
    } else {
        $domain = preg_match("/.*\|(.*)>$/", $domain, $matches);
        $domain = $matches[1];
        $environment = 'production';

    if (file_exists('./storage/repos/'.$domain.'/site/composer.json')) {
        $output = shell_exec('cd storage/repos/'.$domain.'/site && wp @'.$environment.' login create adminusername --url-only');
        $bot->reply("🔒 *Launch ".$environment." wp-admin* \n • ".$output);
    } else {
        $bot->reply("⚠️ Site not found. Type `~login` for help.");



Amazing! Thanks for the snippet! :heart_eyes:


Evan does some awesome stuff.

Another one of my favorites is: wp valet.

Simply valet park your development/project directory (e.g. cd ~/Development/web && valet park) and from there on out, enjoy 1 liner Bedrock installs.

wp valet new example --project=bedrock

and example.test (or whatever tld you have configured on Valet) will be ready to roll, including .env and your database.


I didn’t know until I inquired about setting a default project here, but apparently ~/.wp-cli/config.yml is a thing.

To set the project to bedrock by default when using wp valet new, you can add the following to config.yml (create it if it doesn’t exist):

valet new:
  project: bedrock