WPI-CLI is a set of tools and commands that allow you to easily maintain your website built on WordPress right from the command line. The user command allows you to maintain the user database for your website. With this command you can create, view, edit and delete users.
Follow the instructions below to manage WordPress users using the user command.
Adding a user
Using the wp user command you can create a user to add to your WordPress website. We recommend that you follow the steps below to add a user (with administrator privileges) from the command line:
- Log in to the server via SSH with the cPanel user who owns the website you want to work on.
- Use the cd command to access the root folder of your website eg:
cd public_html/my_website
Replace public_html/my_website with the real path to the root folder of your website.
Execute the following command:
wp user create $username $emailaddress –role=$role
Replace ($username and $emailaddress) the values given as an example with your custom values and ($roles) the role you want the user to be configured with. At the end of the command run, a password will be returned, as in the output example below:
[email protected] [~/public_html]# wp user create exampl3 [email protected] –role=administrator
Success: Created user 2.
Password: srWCdc3c*(&b
See the table below to determine the capabilities of each role. It will help you choose what role to assign as a user in the above command.
| Role | Description |
|---|---|
| Super Admin | Can access all administration features (including site network administration). |
| Admnistrator | Can access all administration features (within a single site). |
| Editor | Can publish and manage posts (including posts by other users). |
| Author | Can publish and manage their own posts. |
| Contributor | Can write and manage their own posts (but cannot publish). |
| Subscriber | Can only manage their profile. |
Listing users
The wp user command can also be used to list current users in the database. Follow the steps below to list WordPress users with WP-CLI.
- Log in to the server via SSH with the cPanel user who owns the website you want to work on.
- Use the cd command to access the root folder of your website eg:
cd public_html/my_website
Replace public_html/my_website with the real path to the root folder of your website.
Execute the following command:
wp user list
The output of this command will display the complete details of all users.
[email protected] [~/public_html]# wp user list +----+----------+------------+--------------------+---------------------+-------+ | ID |user_login|display_name| user_email | user_registered | roles | +----+----------+------------+--------------------+---------------------+-------+ | 1 | admin | admin | [email protected] | 2017-12-16 00:57:44 | admin | | 2 | exampl3 | exampl3 | [email protected] | 2017-12-18 20:15:53 | admin | +----+----------+------------+--------------------+---------------------+-------+
Editing users
The wp user command can also be used to modify details stored for a user. Here are the steps required to change a user's email address using WP-CLI:
- Log in to the server via SSH with the cPanel user who owns the website you want to work on.
- Use the cd command to access the root folder of your website eg:
cd public_html/my_website
Replace public_html/my_website with the real path to the root folder of your website.
Execute the following command:
wp user update $user —$field=$value
Replace ($username and $emailaddress) the values given as an example with your custom values and ($roles) the role you want the user to be modified with. At the end of the command run, a password will be returned, as in the output example below:
[email protected] [~/public_html]# wp user update exampl3 [email protected]
Success: Updated user 2.
Deleting users
You can delete a user using the wp user command. To delete a WordPress user using WP-CLI, follow the instructions below:
- Log in to the server via SSH with the cPanel user who owns the website you want to work on.
- Use the cd command to access the root folder of your website eg:
cd public_html/my_website
Replace public_html/my_website with the real path to the root folder of your website.
Execute the following command:
wp user delete $user –reassign=$username
Replace ($user and $username) the values given as an example with your custom values. At the end of the command run you will be able to see a successful deletion message, as in the output example:
[email protected] [~/public_html]# wp user delete exampl3 --reassign=admin Success: Removed user 2 from http://example.com.
For assistance in applying the above instructions on HostX servers please contact us. HostX offers the fastest WordPress hosting and can help you solve your problems.
