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:
- Open your terminal and connect to the server:
ssh username@your-server-ip
- Change to the WordPress installation directory:
cd /path/to/wordpress
- To view all users and their roles, use the following command:
wp user list
- 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
- 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.