entity-command
entity-command copied to clipboard
wp add user command does not allow a dash in username
- [x] Yes, I reviewed the contribution guidelines.
- [ ] Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
Dashes aren't allowed in usernames, they are when using the wp-admin user creation form.
wp user create user-bob [email protected] --role=administrator
Error: Usernames can only contain lowercase letters (a-z) and numbers.
Describe how other contributors can replicate this bug
wp user create user-bob [email protected] --role=administrator
Describe what you expect as the correct outcome
A username with a dash should be possible.
Let us know what environment you are running this on
OS: Linux 5.0.0-1033-gcp wp-cli/wp-cli#34-Ubuntu SMP Tue Mar 3 04:36:26 UTC 2020 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php7.3
PHP version: 7.3.4-1+ubuntu16.04.1+deb.sury.org+3
php.ini used: /etc/php/7.3/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /www/elementormultisite_511/public
WP-CLI packages dir: /www/elementormultisite_511/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
I believe this is the wrong repo for this issue, go to this repo for this issue.
This is indeed a bug. I just tested, and everything works as expected when creating a user with a dash in the slug via the WP admin backend.
WP-CLI should allow for this as well.
I think this is working as expected.
On multi-sites, the rules for usernames are more restricted compared to single sites. I am able to create a username with hyphens on a single site setup.
However, on a multisite setup, I can see the error on the WP admin backend (see image below).
The details shared by the OP indicate they're on a multi-site environment. (Path /www/elementormultisite_511/public
)

cc: @schlessera
If using a dash or a space be sure to wrap the string in double quotes: wp user create "fname-lname" [email protected]
Like mentioned above https://github.com/wp-cli/entity-command/issues/300#issuecomment-1046235281 this is working as expected.
In multisite -
character is not accepted by core itself.
For single installation, username with -
could be passed wrapped with apostrophe like wp user create "fname-lname"
.