Last active
August 28, 2021 01:06
-
-
Save danielpataki/22e5e8973670130c383d to your computer and use it in GitHub Desktop.
Database cleaning
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 FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' ) ); | |
DELETE FROM wp_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' ) ); | |
DELETE FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' ); |
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
SELECT * FROM wp_users WHERE LENGTH(user_email) - LENGTH(REPLACE(user_email, '.', '')) > 4; |
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 FROM wp_usermeta WHERE 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
DELETE FROM wp_users WHERE ID NOT IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' ) |
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
SELECT domain, COUNT(domain) as count FROM wp_users GROUP BY domain ORDER BY count DESC; |
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 FROM wp_users WHERE | |
user_email LIKE '%buy%' OR | |
user_email LIKE '%weight%' OR | |
user_email LIKE '%guide%' OR | |
user_email LIKE '%money%' OR | |
user_email LIKE '%fashion%' OR | |
user_email LIKE '%cheats%' OR | |
user_email LIKE '%finance%' OR | |
user_email LIKE '%marijuana%' OR | |
user_email LIKE '%cialis%' OR | |
user_email LIKE '%viagra%'; |
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
SELECT DISTINCT(taxonomy) FROM wp_term_taxonomy; |
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 FROM wp_users WHERE user_email LIKE "%zippymail.info%" OR user_email LIKE "%mailinator.com%" // etc.; |
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
$users = $wpdb->get_results( "SELECT ID, user_email FROM wp_users" ); | |
foreach( $users as $user ) { | |
$domain = substr( strrchr ( $user->user_email, "@" ), 1 ); | |
$wpdb->update( | |
'wp_users', | |
array( 'domain' => $domain ), | |
array( 'ID', $user->ID ), | |
array( '%s' ), | |
array( '%d' ) | |
); | |
} |
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
SELECT DISTINCT(meta_key) FROM wp_usermeta LIMIT 0, 500; |
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 FROM wp_users WHERE user_email = '' OR user_login = '' OR user_password = ''; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment