Skip to content

Instantly share code, notes, and snippets.

@aslamdoctor
Created January 17, 2023 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslamdoctor/70c65d8aa085d8d812188097f8dfd4e4 to your computer and use it in GitHub Desktop.
Save aslamdoctor/70c65d8aa085d8d812188097f8dfd4e4 to your computer and use it in GitHub Desktop.
Delete Spam Users from WordPress
<?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