WordPress Help

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:
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

  1. Connect to your hosting account with SSH.
  2. 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.
  3. 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.
  4. 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

  1. Connect to your server or shared hosting account with SSH.
  2. 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.
  3. 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.

Once you see a success message, the user is deleted.

More info