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. All associated posts will be deleted. Proceed? [y/n]

If not, re-run as following to prevent posts removing:

for ex.:

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

Source:
https://wordpress.stackexchange.com/questions/167184/delete-all-subscribers-from-wp-users-and-wp-usermeta-a-few-thousand-at-a-time
https://wp-cli.org/

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *