I’ve previously written a note about how to export WordPress Databases using wp-cli before but today I feel I am also in need of another wp-cli code snippet too as the need for creating a user for an existing website that is fresh installed in my machine happens to me quite often.
Before wp-cli provided this functionality, my solution was to create a user manually directly on the wp-users
table of the database the WordPress with the help from MD5. It’s a suicide!
To create, first make sure you have your wp-cli installed on your local machine. After that, check to see if you can run the wp
command from your local WordPress root directory.
Now, open the terminal and go to the WordPress installation you would like to add a user to it, and run the following command:
wp user create yourusername youremail@example.com --role=administrator --user_pass=yourpassword
yourusername
→ desired usernameyouremail@example.com
→ valid email address--role=administrator
→ assigns admin role--user_pass=yourpassword
→ sets the password (optional; if omitted, WP will generate one)