MySQL Query to Bulk Delete Wordpress Spam Users

My membership site has been flooded with spam. One thing I noticed is a lot of spammers @ hotmail.com emails.

What I want to do is delete all users who are subscribers and have an @hotmail email address.

User data is in two tables wp_usersand wp_usermeta, as far as I understand, I need to delete data in both tables in order to effectively delete users. I was unable to find a query that can delete all user data from mysql through two tables.

I can remove users from the wp_user table with this query

DELETE 
FROM  wp_users 
WHERE  user_email LIKE  "%@hotmail%"

But I also need to delete the data from the table wp_usersmeta, and also make sure that I delete only subscribers ( meta_key = wp_capabilities and meta_value = subscriber).

Any ideas how I can do this? Is there any user data in any other tables that I am missing? Subscribers have no messages associated with them.

I saw some spam plugins, but they are proactive. Right now, I need a way to get rid of these annoying spammers emails.

+1
source share
1 answer

Using DELETE in MySQL.

DELETE
FROM  wp_users 
INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
WHERE  wp_users.user_email LIKE  "%@hotmail%" AND [etc, etc.]

This solution gives you two problems (or maybe more ;-)): 1) you cannot reassign messages and links (if you want), and 2) you need to deal with JSON values ​​in MySQL.

WordPress . get_users wp_delete_user .

<?php $args = array(
    'blog_id'      => $GLOBALS['blog_id'],
    'role'         => 'subscriber',
    'search'       => '*@hotmail.com'
 );

$blogusers = get_users($args);
    foreach ($blogusers as $user) {
        wp_delete_user( $user->ID, $reassign );
    }
?>

: .

+2

All Articles