Add Users Wordpress
How to add new users in Wordpress
The process of adding a new user and assigning a role to them in WordPress is relatively straightforward and can be accomplished through two primary methods. The first involves accessing the admin dashboard, while the second requires SSH access and the use of the wp cli.
The latter approach is best suited for technically proficient WordPress users who are familiar with executing commands in the terminal. Nonetheless, the wp-cli commands required to create users are simple and straightforward. This article will explore both methods for creating new users and assigning roles. However, we will begin by examining the process of adding new users through the WordPress admin dashboard.
Add New User from Wordpress Admin Dashboard
To add a new user in WordPress, please log in to your WordPress admin dashboard and navigate to the “Users” section. Hover over the “Users” tab and select “Add New” to access a new form where you can input the necessary details for the new user.
Enter the new user’s username, email, first name, last name, and website URL, if applicable. To generate a strong password for the user, click on the “Generate Password” button.
Next, select the appropriate role for the new user from the five available options: subscriber, contributor, author, editor, or administrator. Once you have selected the desired role, click on the “Add New User” button located at the bottom of the form.
The system will then add the new user with the assigned role. Adding a new user in WordPress is a straightforward process that can be completed with ease.
Add New User via WP-CLI
The second approach to adding new WordPress users entails a certain level of technical proficiency, as it requires the ability to execute terminal commands and SSH access to the server. Nevertheless, if one is capable of executing terminal commands and has server access, the process is relatively straightforward.
Initially, install the WP CLI on the server to enable the execution of commands and for WordPress management using the WP CLI. The installation process is also very simple. Once installed, the CLI can be utilized to manage various tasks such as optimizing databases, creating tables, installing themes and plugins, and even managing posts from the terminal.
To install the WP CLI, one must SSH to the server and execute the following command upon connection.:
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
You can check if it works using the following command:
$ php wp-cli.phar –info
Since we want to be able to run commands by typing just wp, we need to run a few commands more:
$ chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp
Subsequently, you can try running wp –info and check the output. If you see an output liek one given below, you have installed WP CLI successfully.
OS: Linux 5.15.0-67-generic #74-Ubuntu SMP Wed Feb 22 14:14:39 UTC 2023 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php8.2
PHP version: 8.2.8
php.ini used: /etc/php/8.2/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
SQL modes: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
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: /var/www/html
WP-CLI packages dir:
WP-CLI cache dir: /root/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.8.1
To test the WP CLI, you can try obtaining a list of existing users. Fort, change to the root directory or the directory where wordpress is installed.
$ cd /var/www/html
Now run the following command to check the existing users.
$ wp user list
The above command will output a list of existing users like the following:
root@wordpress-ubuntu:/var/www/html# wp user list
+----+-------------+-----------------+-----------------------+---------------------+---------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+-------------+-----------------+-----------------------+---------------------+---------------+
| 1 | Bob09 | Bobby | [email protected] | 2023-07-02 13:49:05 | administrator |
| 2 | Karla | Karla Adams | [email protected] | 2023-07-02 14:00:35 | subscriber |
+----+-------------+-----------------+-----------------------+---------------------+---------------+
Don’t run wp cli commands as the root user or if you want to run them as the root user, add the –allow-root flag at the end of the command.
Now, let’s get back to adding our new user. Run the following command in the root directory of your website.
$ wp user create mike [email protected] –role=author
Additionally you can use the nickname flag to give the user a nickname as in the below command.
$ wp user create mike [email protected] –role=author –nickname=mikey
A break up of the above command:
wp user create : creates a new user
Mike : the user name of the new user
[email protected]: new user’s email
--role=author: the role to be assigned to the new user.
You will receive an output like the following:
Success: Created user 33.
Password: XJ9D^XuyQH1Z#gG17%v1BZkp
Copy the password for the new user and try logging in as the new user. You have created a new user using the WP CLI and assigned the role author to him.
Deleting a user via wp cli
Just like you created a new user, you can also delete users from wordpress through the help of the wp cli. It can be done with a simple command. In case, the user is a author, you can assign his posts to the admin or another author on your blog.
To plainly delete a user, who is a subscriber or an author with no posts just copy the user number and run the command wp user delete like below:
$ wp user delete 33
Make sure the user does not have any associated posts. However, the system will warn you if you have not passed the reassign parameter. You will get an output like
--reassign parameter not passed. All associated posts will be deleted. Proceed? [y/n]
If the user has no associated posts, you can safely answer y.
This will delete the user number 33. Now, if you want to delete an existing author and want to assign his posts to another user, the same command can be used with the reassign flag. Suppose, you need to delete user 33 and assign his posts to user 76.
$ wp user delete 33 -–reassign=76
This will delete the user and assign the existing posts to the user you have specified.
Get User Details Using WP-CLI
The WP cli makes user management for you easier in wordpress. Suppose you want to generate the details of a specific user, you just need to run the command wp user get followed by the user number like:
$ wp user get 33
It will output the details of the user including user login, email, registered date, display name and the role.
Suggested Reading