How to update a user’s role with WP-CLI

September 17, 2024 / How-to Guide

WP-CLI offers an easy way to manage user roles in WordPress directly from the command line.

Here’s how to update a user’s role using WP-CLI.

Prerequisites:

  • SSH access to your server
  • WP-CLI installed

Follow below steps:

  1. Open your terminal and connect to the server:
    ssh username@your-server-ip
  2. Change to the WordPress installation directory:
    cd /path/to/wordpress
  3. To view all users and their roles, use the following command:
    wp user list
  4. Use the following command to update a specific user’s role:
    wp user update <user-id> --role=<new-role>

    Replace <user-id> with the actual user ID and <new-role> with the role you want to assign (e.g., administrator, editor, author, etc.).

    Example:

    wp user update 3 --role=editor
  5. You can check the updated role by running:
    wp user get <user-id> --field=roles

WP-CLI streamlines administrative duties and makes user role management easier by enabling you to update roles rapidly from the command line.

If you manage roles and permissions, make sure your admin email is also up to date.
For more information on that , check out our detailed guide on how to change the admin email with WP-CLI.

Hope you liked our article!

Spread the love