Remove users with WP CLI by ROLE

WP CLI

To remove users with a specific role using WP-CLI, you can use the wp user delete command with the --role parameter.

Here’s an example command to remove all users with the “contributor” role:

 wp user list --role=subscriber --field=ID --allow-root | xargs wp user delete --reassign=7 --quiet --allow-root

This command first lists all users with the “contributor” role and retrieves only their user IDs using the --field=ID parameter. The output is then piped to the xargs command, which passes each user ID as an argument to the wp user delete command, deleting all users with the “contributor” role.

Note: Before running this command, it’s a good idea to backup your database or at least create a backup of the users you’re deleting in case you need to restore them later.

Sample Blog Post One

Leave a Comment