Created
February 22, 2019 00:38
-
-
Save taeo/82e81801c4f18524272d4a73ade911fa to your computer and use it in GitHub Desktop.
WooCommerce - delete users with customer role and no orders (likely spam accounts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Delete usermeta that nas no related user in users */ | |
DELETE FROM wp_usermeta WHERE wp_usermeta.user_id NOT IN (SELECT ID FROM wp_users); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 1. MAKE A BACKUP FIRST!!!! | |
* 2. DO A PREFLIGHT - USE SELECT * (not DELETE wp_users.*) | |
*/ | |
DELETE wp_users.* FROM wp_users | |
INNER JOIN wp_usermeta | |
ON wp_users.ID = wp_usermeta.user_id | |
WHERE wp_usermeta.meta_key = 'wp_capabilities' | |
AND wp_usermeta.meta_value = 'a:1:{s:8:"customer";b:1;}' | |
AND wp_users.ID not in ( | |
SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user' | |
) AND wp_users.ID not in ( | |
select distinct(post_author) from wp_posts | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment