entity-command icon indicating copy to clipboard operation
entity-command copied to clipboard

wp add user command does not allow a dash in username

Open patrick-wc opened this issue 4 years ago • 4 comments

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

patrick-wc avatar May 15 '20 15:05 patrick-wc

I believe this is the wrong repo for this issue, go to this repo for this issue.

anirudhdggl avatar Jul 18 '20 18:07 anirudhdggl

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.

schlessera avatar Jul 22 '20 15:07 schlessera

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)

Screen Shot 2022-02-20 at 5 48 27 PM

See this further reference.

cc: @schlessera

Sidsector9 avatar Feb 20 '22 13:02 Sidsector9

If using a dash or a space be sure to wrap the string in double quotes: wp user create "fname-lname" [email protected]

mediaformat avatar Jan 31 '23 22:01 mediaformat

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".

ernilambar avatar Apr 16 '24 08:04 ernilambar