How To: Change User Role with WP CLI

Home » How To: Change User Role with WP CLI

This is one of those hacks that allows you to bypass hacking the database directly for what is just a simple thing to do. Change the user role of a WordPress user.

If you find yourself, for whatever reason, not being able to change a WordPress user’s role via the Dashboard, here’s your best alternative. Via WP CLI.

Time needed: 1 minute

If you find yourself, for whatever reason, not being able to change a WordPress user’s role via the Dashboard, here’s your best alternative. Via WP CLI.

  1. Connect to your site

    Find your favorite Terminal app and connect via SSH to your WordPress site.

  2. Navigate to the root folder of your WordPress site

    9 out of 10 times you can only use WP CLI commands when you’ve navigated to the root of your WordPress installation. An easy way to check where you are is to use the ls command. That will show you what files are in the directory where you are.

  3. Update the user role

    Copy and paste the following command to your terminal
    wp user set-role username administrator
    Make sure to change the username to the username you want to change it and hit enter.

  4. Check and double check again

    If all went well you will see no errors after hitting enter. Double check in the WordPress User overview if your change was what you intended.

    Alternatively, you can use the following command to check the usernames + user roles via the terminal you’re already finding yourself in:
    wp user list

That’s it. All done. Want to learn more about what you can do with WP CLI? Check out my courses.

First name
This field is for validation purposes and should be left unchanged.

Automatically sent to your inbox, just like 🪄