How to remove WordPress spam users using WP-CLI

If you have a huge amount of spam users in your database you need to check this post https://alltime.pp.ua/blog/how-to-remove-wordpress-spam-users-using-mysql-command-line/ as the way below will take ‘forever’ 🙂

Supposed you’ve decided to leave just ‘administrator’

Using command below you found a pattern

wp user list

So, now run to remove them:

wp user delete $(wp user list --role=author --field=ID)
wp user delete $(wp user list --role=customer --field=ID)
wp user delete $(wp user list --role=subscriber --field=ID)

You should be asked and if you are sure just type ‘y

–reassign parameter not passed.… Read the rest