Create or delete a WordPress admin user with WP-CLI
WP-CLI is a command line tool that helps you perform different actions on your WordPress site. If you're comfortable with using SSH commands, you'll notice that WP-CLI has simplified commands created for WordPress sites. Here's how you can create a new WordPress admin user or delete an existing one with commands available in WP-CLI.
Warning: You should always back up your site before making changes to the database.
Required: You'll need the following to complete these steps:
- An SSH app. We suggest PuTTY for Windows, or Terminal for macOS.
- Your FTP details. If you don’t have them already written down, you should find your FTP host, username, and password:
- For your FTP host, you can use either your domain name or your IP address.
- You can find your FTP username and password in your hosting account for Linux Hosting with cPanel or Managed WordPress Hosting (steps 1-7).
Note: If you have a VPS or DED Server, you need to install WP-CLI before you can start using it. WP-CLI is not available on our Windows Hosting plans.
Create a new admin user
- Connect to your hosting account with SSH.
- Use the bash command ls to list files and folders, and cd and ../ to move through directories until you're in the directory with your WordPress files.
- Enter the following command to create a new user:
wp user create newusername example@coolexample.com --role=administrator --porcelain
In the command above, you should replace:- newusername with the actual username you want to use the new user.
- example@coolexample.com with the email address associated with that user.
- Once the user number shows up in the SSH app, the new user can set up a new secure password by resetting it from a WordPress login page using the email address entered in step 3.
Delete a user
- Connect to your server or shared hosting account with SSH.
- Use the bash command ls to list files and folders, and cd and ../ to move through directories until you're in the directory with your WordPress files.
- Enter the following command to delete a user:
- To delete a user and all their posts:
wp user delete username
In the command above, you should replace username with the actual username for the user you want to delete. When prompted if you want to delete posts, select y to confirm. - To delete a user and reassign their posts to another user:
wp user delete username --reassign=anotherusername
In the command above, you should replace username with the actual username for the user you want to delete and anotherusername with the username of the user you want to reassign posts to.
- To delete a user and all their posts:
Once you see a success message, the user is deleted.
More info
- Export and import a database with WP-CLI
- Want to know more about WP-CLI? Find developer specific info on their official site.