public static function credentialsForUserWithRole($userRole) { $credentials = \Wordfence\ExKit\Config::get("user.{$userRole}", null, false); if ($credentials === null) { \Wordfence\ExKit\Cli::write("Please enter the username and password for a user with the \"{$userRole}\" role."); $username = \Wordfence\ExKit\Cli::prompt("Username", ''); $password = \Wordfence\ExKit\Cli::prompt("Password", ''); $credentials = [self::USER_CREDENTIALS_USERNAME_KEY => $username, self::USER_CREDENTIALS_PASSWORD_KEY => $password]; \Wordfence\ExKit\Config::set("user.{$userRole}", $credentials); } return $credentials; }
#!/usr/bin/env php <?php require __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; use Wordfence\ExKit\WPAuthentication; use Wordfence\ExKit\Cli; //Prompt for something $value = Cli::prompt("Enter a value", 'some default'); Cli::write('Value: ' . $value); //Prompt for the baseURL early if needed Endpoint::baseURL(); //Log in as a subscriber $session = new \Requests_Session(); WPAuthentication::logInAsUserRole($session, WPAuthentication::USER_ROLE_SUBSCRIBER); Cli::write('[+] Logged in', 'green', null);