From time to time when you're developing plugins/themes you may need to delete some test user accounts. Here is a way to do it.

You can either create an MU Plugin (by creating a file in mu-plugins/some-code.php) or adding it in functions.php in your current (child) theme.

Then go to the admin area. I was receiving errors (function doesn't exist) when I wasn't in the admin area.

You have to be careful with this code.

[php]
add_action('admin_init', 'abc_quick_del', 10);

// !!!
function abc_quick_del() {
$user = get_user_by( 'login', 'some_username');

if (!empty($user->ID)) {
echo "Deleting user ID: " . $user->ID . "<br/>\n";
wp_delete_user( $user->ID );
} else {
echo "Account not found.";
}
}
[/php]

 

 

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer