WP-CLI (WordPress Command Line Interface) allows you to manage WordPress users efficiently without accessing the WordPress admin panel.
1. Verify PHP Configuration
Before using WP-CLI, ensure PHP is installed and configured correctly:
Check PHP configuration file
php --ini
Check PHP version
php -v
2. List WordPress Users
To list all users with the administrator role:
wp user list --role=administrator --skip-plugins --allow-root
3. Create a New User
Create a new administrator user:
wp user create testadmin [email protected] --role=administrator --allow-root
testadmin` → Username
[email protected]` → Email
4. Update a User’s Password
Change the password for `testadmin`:
wp user update testadmin --user_pass='Lov33@TI%!#laiesHa' --skip-email --allow-root
5. Delete a User
Delete the user `testadmin`:
wp user delete testadmin --allow-root
Delete a user by ID (`4` in this case):
wp user delete 4 --allow-root
6. Change User Role
Make `[email protected]` an administrator:
wp user update [email protected] --role=administrator --skip-plugins --allow-root
7. Using WP-CLI on a cPanel Server
For cPanel servers, use the full PHP binary path:
/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/bin/wp
/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/bin/wp user list --role=administrator --skip-plugins --allow-root
Modify `ea-php73` according to your PHP version.
Conclusion
WP-CLI makes WordPress user management quick and efficient. These commands help in listing, creating, updating, and deleting users without accessing the WordPress dashboard.