To add an admin user using WP-CLI (WordPress Command Line Interface), follow these steps:
- Open your terminal or command prompt.
- Navigate to your WordPress installation directory. This is the directory where your WordPress files are located.
Run the command to create a new user:
Use thewp user create
command followed by the username, email, and other necessary details. For example, to create a user with the usernameadminuser
, emailadmin@example.com
, and set their role toadministrator
, you would use the following command:wp user create adminuser admin@example.com --role=administrator --user_pass=yourpassword
Here’s a breakdown of the command:
wp user create
: The WP-CLI command to create a new user.adminuser
: The username for the new user.admin@example.com
: The email address for the new user.--role=administrator
: Assigns theadministrator
role to the new user.--user_pass=yourpassword
: Sets the password for the new user. Replaceyourpassword
with a strong password of your choice.
- Check the output:
After running the command, WP-CLI will output a message confirming the creation of the new user. For example:Success: Created user 3.
This new user will now have administrator privileges and can log in to the WordPress admin dashboard using the provided username and password.
Example
cd /path/to/wordpress wp user create adminuser admin@example.com --role=administrator --user_pass=strongpassword123
Replace /path/to/wordpress
with the actual path to your WordPress installation, adminuser
with your desired username, `
admin@example.comwith the user's email address, and
strongpassword123` with a strong, secure password.
Additional Options
WP-CLI also provides additional options you can use when creating a user, such as setting the user’s first name, last name, and display name. Here’s an example command that includes these options:
wp user create adminuser admin@example.com --role=administrator --user_pass=strongpassword123 --first_name=Admin --last_name=User --display_name="Admin User"
In this example:
– --first_name=Admin
: Sets the first name to “Admin”.
– --last_name=User
: Sets the last name to “User”.
– --display_name="Admin User"
: Sets the display name to “Admin User”.
By using these commands, you can efficiently manage WordPress user accounts directly from the command line.