Created
January 17, 2023 09:03
-
-
Save aslamdoctor/70c65d8aa085d8d812188097f8dfd4e4 to your computer and use it in GitHub Desktop.
Delete Spam Users from WordPress
This file contains hidden or 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
<?php | |
add_action( | |
'init', | |
function() { | |
if ( isset( $_GET['cleanup_spams'] ) ) { | |
global $wpdb; | |
$query = "SELECT * | |
FROM $wpdb->users | |
WHERE user_email LIKE '%.be'"; | |
$users = $wpdb->get_results( $query ); | |
echo 'Total users to delete: ' . count( $users ) . '<hr/><br/>'; | |
foreach ( $users as $user ) { | |
echo 'Deleted : ' . $user->user_email . '<hr/>'; | |
wp_delete_user( $user->ID ); | |
} | |
} | |
} | |
); | |
// How to Run: | |
// Simply open the website by adding ?cleanup_spams in your url | |
// e.g. http://www.example.com/?cleanup_spams | |
// If the script timeout, increase max_execution_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment