Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created May 23, 2020 23:41
Show Gist options
  • Save yanknudtskov/203e255cfcd382218e46bee4ae4c3c2d to your computer and use it in GitHub Desktop.
Save yanknudtskov/203e255cfcd382218e46bee4ae4c3c2d to your computer and use it in GitHub Desktop.
Delete SPAM users from WordPress/WooCommerce. They usually never have a first name set
# Use with EXTREME CAUTION
DELETE FROM wp_users WHERE ID IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%'
AND user_id NOT IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'billing_first_name' AND meta_value != ''
AND user_id IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' ) ) )
DELETE FROM wp_usermeta WHERE user_id IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%'
AND user_id NOT IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'billing_first_name' AND meta_value != ''
AND user_id IN ( SELECT user_id FROM wp_usermeta
WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' ) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment