To add an admin user using WP-CLI (WordPress Command Line Interface), follow these steps:

  1. Open your terminal or command prompt.
  2. Navigate to your WordPress installation directory. This is the directory where your WordPress files are located.
  3. Run the command to create a new user:
    Use the wp user create command followed by the username, email, and other necessary details. For example, to create a user with the username adminuser, email admin@example.com, and set their role to administrator, 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 the administrator role to the new user.
    • --user_pass=yourpassword: Sets the password for the new user. Replace yourpassword with a strong password of your choice.
  4. 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, andstrongpassword123` 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.